sappho-data-publisher 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'sappho-data-publisher'
6
+
7
+ Sappho::Data::Publisher::CommandLine.new.run
@@ -0,0 +1,27 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'sappho-data-publisher/modules'
7
+ require 'yaml'
8
+
9
+ module Sappho
10
+ module Data
11
+ module Publisher
12
+
13
+ class Configuration
14
+
15
+ attr_reader :data
16
+
17
+ def initialize
18
+ filename = File.expand_path(ARGV[0] || 'config.yml')
19
+ @data = YAML.load_file filename
20
+ Modules.instance.get(:logger).warn "configuration loaded from #{filename}"
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,78 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'sappho-data-publisher/modules'
7
+ require 'xmlrpc/client'
8
+
9
+ module Sappho
10
+ module Data
11
+ module Publisher
12
+
13
+ class Confluence
14
+
15
+ def initialize
16
+ @config = Modules.instance.get :configuration
17
+ @logger = Modules.instance.get :logger
18
+ url = @config.data['confluence.url']
19
+ @wiki = XMLRPC::Client.new2("#{url}/rpc/xmlrpc").proxy('confluence1')
20
+ @token = @wiki.login @config.data['confluence.username'], @config.data['confluence.password']
21
+ @logger.info "Confluence #{url} is online"
22
+ end
23
+
24
+ def getGlobalConfiguration
25
+ pageName = @config.data['confluence.global.config.page.name']
26
+ return getPage @config.data['confluence.config.space.key'], pageName if pageName
27
+ ''
28
+ end
29
+
30
+ def getConfiguration
31
+ getPage @config.data['confluence.config.space.key'], @config.data['confluence.config.page.name']
32
+ end
33
+
34
+ def getTemplate pageData, parameters
35
+ getPage parameters['templatespace'], parameters['templatepage']
36
+ end
37
+
38
+ def getScript rawPage
39
+ rawPage.scan(/\{noformat.*?\}(.*?)\{noformat\}/m).each { |pageData| yield pageData[0] }
40
+ end
41
+
42
+ def publish content, pageData, parameters
43
+ setPage parameters['space'], parameters['parent'], pageData['pagename'], content
44
+ end
45
+
46
+ def shutdown
47
+ @wiki.logout @token
48
+ @logger.info 'disconnected from Confluence'
49
+ end
50
+
51
+ private
52
+
53
+ def getPage spaceKey, pageName
54
+ @logger.info "reading wiki page #{spaceKey}:#{pageName}"
55
+ @wiki.getPage(@token, spaceKey, pageName)['content']
56
+ end
57
+
58
+ def setPage spaceKey, parentPageName, pageName, content
59
+ begin
60
+ page = @wiki.getPage(@token, spaceKey, pageName)
61
+ page['content'] = content
62
+ @logger.info "rewriting existing wiki page #{spaceKey}:#{pageName}"
63
+ rescue
64
+ page = {
65
+ 'space' => spaceKey,
66
+ 'parentId' => @wiki.getPage(@token, spaceKey, parentPageName)['id'],
67
+ 'title' => pageName,
68
+ 'content' => content }
69
+ @logger.info "creating new wiki page #{spaceKey}:#{pageName} as child of #{parentPageName}"
70
+ end
71
+ @wiki.storePage @token, page
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,54 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'rubygems'
7
+ gem 'liquid'
8
+ require 'liquid'
9
+ require 'sappho-data-publisher/modules'
10
+
11
+ module Sappho
12
+ module Data
13
+ module Publisher
14
+
15
+ class CustomLiquid
16
+
17
+ def CustomLiquid.setup
18
+ Liquid::Template.register_filter(Fullname)
19
+ Liquid::Template.register_tag('squash', Squash)
20
+ end
21
+
22
+ module Fullname
23
+
24
+ def fullname username
25
+ begin
26
+ Modules.instance.get('AddressBook').getUserFullName(username)
27
+ rescue
28
+ '** John Doe **'
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ class Squash < Liquid::Block
35
+
36
+ def initialize tag_name, markup, tokens
37
+ super
38
+ @message = (markup ? markup.to_s : '')
39
+ @message = @message.length > 0 ? @message : 'This information has not been supplied.'
40
+ end
41
+
42
+ def render context
43
+ wiki = []
44
+ super.each { |line| wiki << line unless line.strip == ''}
45
+ wiki.size > 0 ? wiki.join : @message
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,63 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'sappho-data-publisher/modules'
7
+ require 'soap/wsdlDriver'
8
+
9
+ module Sappho
10
+ module Data
11
+ module Publisher
12
+
13
+ class Jira
14
+
15
+ def initialize
16
+ config = Modules.instance.get :configuration
17
+ @logger = Modules.instance.get :logger
18
+ url = config.data['jira.url']
19
+ @jira = SOAP::WSDLDriverFactory.new("#{url}/rpc/soap/jirasoapservice-v2?wsdl").create_rpc_driver
20
+ @token = @jira.login config.data['jira.username'], config.data['jira.password']
21
+ @allCustomFields = @jira.getCustomFields @token
22
+ @logger.info "Jira #{url} is online"
23
+ @users = {}
24
+ end
25
+
26
+ def gatherData pageData, parameters
27
+ id = parameters['id']
28
+ @logger.info "reading Jira issue #{id}"
29
+ issue = @jira.getIssue @token, id
30
+ pageData['summary'] = summary = issue['summary']
31
+ pageData['pagename'] = summary unless pageData['pagename']
32
+ pageData['description'] = issue['description']
33
+ pageData['customFields'] = customFields = {}
34
+ @allCustomFields.each { |customField|
35
+ customFields[customField['id']] = {
36
+ 'name' => customField['name'],
37
+ 'values' => nil
38
+ }
39
+ }
40
+ issue['customFieldValues'].each { |customFieldValue|
41
+ customFields[customFieldValue['customfieldId']]['values'] = customFieldValue['values']
42
+ }
43
+ end
44
+
45
+ def getUserFullName username
46
+ user = @users[username]
47
+ unless user
48
+ @logger.info "reading Jira user details for #{username}"
49
+ @users[username] = user = @jira.getUser(@token, username)
50
+ end
51
+ user['fullname']
52
+ end
53
+
54
+ def shutdown
55
+ @jira.logout @token
56
+ @logger.info 'disconnected from Jira'
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,45 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'singleton'
7
+
8
+ module Sappho
9
+ module Data
10
+ module Publisher
11
+
12
+ class Modules
13
+
14
+ include Singleton
15
+
16
+ def initialize
17
+ @modules = {}
18
+ end
19
+
20
+ def set name, mod
21
+ @modules[name] = mod
22
+ end
23
+
24
+ def get name
25
+ @modules[name]
26
+ end
27
+
28
+ def shutdown
29
+ each { |mod| mod.shutdown }
30
+ end
31
+
32
+ def each
33
+ @modules.each do |name, mod|
34
+ begin
35
+ yield mod
36
+ rescue
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'rubygems'
7
+ gem 'liquid'
8
+ require 'liquid'
9
+ require 'yaml'
10
+ require 'sappho-data-publisher/modules'
11
+
12
+ module Sappho
13
+ module Data
14
+ module Publisher
15
+
16
+ class Publisher
17
+
18
+ def publish
19
+ modules = Modules.instance
20
+ logger = modules.get :logger
21
+ configurator = modules.get modules.get(:configuration).data['config.module']
22
+ globalScript = ''
23
+ configurator.getScript(configurator.getGlobalConfiguration) { |configChunk| globalScript += configChunk }
24
+ configurator.getScript configurator.getConfiguration do |configChunk|
25
+ allData = YAML.load(globalScript + configChunk)
26
+ pageData = allData['page']
27
+ if pageData
28
+ logger.info "---- publishing #{pageData['id']} ----"
29
+ pageData['sources'].each do |source|
30
+ id = source['source']
31
+ logger.info "collecting #{id} source data"
32
+ modules.get(id).gatherData pageData, source['parameters']
33
+ end
34
+ pageData['publications'].each do |publication|
35
+ id = publication['destination']
36
+ logger.info "publishing data to #{id}"
37
+ dest = modules.get(id)
38
+ params = publication['parameters']
39
+ template = ''
40
+ dest.getScript(dest.getTemplate pageData, params) { |templateChunk| template += templateChunk }
41
+ dest.publish Liquid::Template.parse(template).render('data' => pageData), pageData, params
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ module Sappho
7
+ module Data
8
+ module Publisher
9
+ VERSION = "0.1.0"
10
+ HOMEPAGE = "https://github.com/sappho/sappho-data-publisher/wiki"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ # See https://github.com/sappho/sappho-data-publisher/wiki for project documentation.
2
+ # This software is licensed under the GNU Affero General Public License, version 3.
3
+ # See http://www.gnu.org/licenses/agpl.html for full details of the license terms.
4
+ # Copyright 2012 Andrew Heald.
5
+
6
+ require 'logger'
7
+ require 'sappho-data-publisher/modules'
8
+ require 'sappho-data-publisher/publisher'
9
+ require 'sappho-data-publisher/configuration'
10
+ require 'sappho-data-publisher/confluence'
11
+ require 'sappho-data-publisher/jira'
12
+ require 'sappho-data-publisher/custom_liquid'
13
+ require 'sappho-data-publisher/version'
14
+
15
+ module Sappho
16
+ module Data
17
+ module Publisher
18
+
19
+ class CommandLine
20
+
21
+ def run
22
+ logger = Logger.new STDOUT
23
+ logger.level = Logger::INFO
24
+ logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
25
+ logger.info "sappho-data-publisher version #{VERSION} - #{HOMEPAGE}"
26
+ modules = Modules.instance
27
+ modules.set :logger, logger
28
+ modules.set :configuration, Configuration.new
29
+ modules.set 'Jira', (jira = Jira.new)
30
+ modules.set 'AddressBook', jira
31
+ modules.set 'Confluence', Confluence.new
32
+ CustomLiquid.setup
33
+ Publisher.new.publish
34
+ modules.shutdown
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sappho-data-publisher
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Heald
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 2
33
+ - 2
34
+ version: 0.9.2.2
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: liquid
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 0
50
+ version: 2.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: See the project home page for more information
54
+ email:
55
+ - andrew@heald.co.uk
56
+ executables:
57
+ - sappho-data-publisher
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - bin/sappho-data-publisher
64
+ - lib/sappho-data-publisher.rb
65
+ - lib/sappho-data-publisher/configuration.rb
66
+ - lib/sappho-data-publisher/confluence.rb
67
+ - lib/sappho-data-publisher/custom_liquid.rb
68
+ - lib/sappho-data-publisher/jira.rb
69
+ - lib/sappho-data-publisher/modules.rb
70
+ - lib/sappho-data-publisher/publisher.rb
71
+ - lib/sappho-data-publisher/version.rb
72
+ homepage: https://github.com/sappho/sappho-data-publisher/wiki
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: sappho-data-publisher
101
+ rubygems_version: 1.8.17
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Publishes aggregated data to formatted pages on a wiki
105
+ test_files: []
106
+