elexis-wiki-interface 0.4
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.
- data/.gitignore +18 -0
- data/.travis.yml +24 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +94 -0
- data/LICENSE +674 -0
- data/README.textile +104 -0
- data/Rakefile +6 -0
- data/bin/wiki_pull +6 -0
- data/bin/wiki_pull_daily +25 -0
- data/bin/wiki_push +5 -0
- data/elexis-wiki-interface.gemspec +28 -0
- data/lib/elexis/wiki/interface.rb +8 -0
- data/lib/elexis/wiki/interface/version.rb +7 -0
- data/lib/elexis/wiki/interface/workspace.rb +298 -0
- data/spec/data/doc/doc_de/.project +42 -0
- data/spec/data/pull/ch.elexis.agenda/.project +36 -0
- data/spec/data/pull/ch.elexis.agenda/META-INF/MANIFEST.MF +33 -0
- data/spec/data/pull/ch.elexis.agenda/plugin.properties +8 -0
- data/spec/data/pull/ch.elexis.agenda/plugin.xml +209 -0
- data/spec/data/pull/ch.elexis.agenda/plugin_de.properties +8 -0
- data/spec/data/pull/ch.elexis.agenda/plugin_en.properties +8 -0
- data/spec/data/pull/ch.elexis.agenda/plugin_fr.properties +7 -0
- data/spec/data/pull/ch.elexis.core.application.feature/.project +23 -0
- data/spec/data/pull/ch.elexis.core.application.feature/build.properties +1 -0
- data/spec/data/pull/ch.elexis.core.application.feature/feature.xml +699 -0
- data/spec/data/pull/ch.elexis.core.application.feature/pom.xml +12 -0
- data/spec/data/pull/ch.elexis.icpc/.project +28 -0
- data/spec/data/pull/ch.elexis.icpc/META-INF/MANIFEST.MF +26 -0
- data/spec/data/pull/ch.elexis.icpc/plugin.xml +74 -0
- data/spec/data/pull/ch.elexis.notes/.project +34 -0
- data/spec/data/pull/ch.elexis.notes/META-INF/MANIFEST.MF +17 -0
- data/spec/data/pull/ch.elexis.notes/plugin.properties +1 -0
- data/spec/data/pull/ch.elexis.notes/plugin.xml +36 -0
- data/spec/data/pull/ch.elexis.notes/plugin_de.properties +3 -0
- data/spec/data/pull/ch.elexis.notes/plugin_en.properties +3 -0
- data/spec/data/pull/ch.elexis.notes/plugin_fr.properties +3 -0
- data/spec/data/pull/doc_de/.project +42 -0
- data/spec/data/pull/doc_de/Doc_de_abrechnungssystem1.png +0 -0
- data/spec/data/pull/doc_de/doc_de.mediawiki +1842 -0
- data/spec/data/push/ch.elexis.icpc/.project +28 -0
- data/spec/data/push/ch.elexis.icpc/META-INF/MANIFEST.MF +26 -0
- data/spec/data/push/ch.elexis.icpc/doc/favicon_green.png +0 -0
- data/spec/data/push/ch.elexis.icpc/doc/test.mediawiki +3 -0
- data/spec/data/push/ch.elexis.icpc/plugin.xml +74 -0
- data/spec/pull_spec.rb +99 -0
- data/spec/push_spec.rb +29 -0
- data/spec/spec_helper.rb +18 -0
- metadata +258 -0
data/README.textile
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
h1. Elexis::Wiki::Interface
|
2
|
+
|
3
|
+
A Ruby Gem to allow pulling and pushing between Elexis source code repositories and the mediawiki installation
|
4
|
+
|
5
|
+
Use it at your own risk, as it is just a small utility gem to help for some release engineering for the Elexis-RCP. See http://elexis.info.
|
6
|
+
|
7
|
+
But I have an open ear for suggestions for improvements, especially if they come with a patch including specs.
|
8
|
+
|
9
|
+
License: GPLv3 or later
|
10
|
+
|
11
|
+
Copyright: 2014 (c) by Niklaus Giger <niklaus.giger@member.fsf.org>
|
12
|
+
|
13
|
+
h2. Installation
|
14
|
+
|
15
|
+
Ensure that you use Ruby 1.9.2 or higher (mediawiki-gateway does not support Ruby 1.8.7).
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
bc. $ gem 'elexis-wiki-interface'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
bc. $ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
bc. $ gem install elexis-wiki-interface
|
28
|
+
|
29
|
+
h2. Usage
|
30
|
+
|
31
|
+
h3. using some built-in helpers (mainly for the jenkins-CI)
|
32
|
+
|
33
|
+
Each of the helper script below should work if you have a ruby installation >= 1.9.2 and executed @gem install bundler && bundle install@ in directory where
|
34
|
+
|
35
|
+
bc. wiki_pull
|
36
|
+
wiki_pull_daily
|
37
|
+
wiki_push
|
38
|
+
|
39
|
+
h3. in a ruby script
|
40
|
+
|
41
|
+
bc. require 'elexis/wiki/interface/workspace'
|
42
|
+
require 'pp'
|
43
|
+
workspace = Elexis::Wiki::Interface::Workspace.new('.')
|
44
|
+
workspace.pull # get actual mediawiki content and place it under doc inside the plugin
|
45
|
+
workspace.info.show
|
46
|
+
pp workspace.views_missing_documentation # returns an array of plugin-ids
|
47
|
+
pp workspace.perspectives_missing_documentation # returns an array of plugin-ids
|
48
|
+
pp workspace.plugins_missing_documentation # returns an array of plugis
|
49
|
+
workspace.push # push doc/*.mediwiki files to the wiki
|
50
|
+
|
51
|
+
Or you can inspire you from the spec/*_spec.rb files to see tested examples.
|
52
|
+
|
53
|
+
h3. Username/password to access your wiki
|
54
|
+
|
55
|
+
The username and password is fetched from a config.yml, which may be either
|
56
|
+
* /etc/elexis-wiki-interface/config.yml
|
57
|
+
* <current workdir>/config.yml
|
58
|
+
|
59
|
+
Here is an example:
|
60
|
+
|
61
|
+
bc. ---
|
62
|
+
wiki: http://wiki.elexis.info/api.php
|
63
|
+
password: topsecrect
|
64
|
+
user: elexis
|
65
|
+
|
66
|
+
This user must have the privilege to access the wiki via the API interface.
|
67
|
+
|
68
|
+
h3. Conventions
|
69
|
+
|
70
|
+
* You must create a directory config with a file hosts.yml containing the mediawiki-gateway configuration (host, username, password)
|
71
|
+
|
72
|
+
* The push/pull methods use the convention
|
73
|
+
** in page names all '.' are removed
|
74
|
+
** a plugin plugin.name has a page plugin.name
|
75
|
+
** a view view.name with a localized name localized_name has a page <plugin.name>Views<localized_name>
|
76
|
+
** a perspective perspective.name with a localized name localized_name has a page P_<localized_name>
|
77
|
+
** png files should start with their plugin/feature-name followed by '_' by a unique name
|
78
|
+
** png files resides inside the 'doc' sub-directory of each plugin/feature
|
79
|
+
|
80
|
+
h3. Limitations/TODO
|
81
|
+
|
82
|
+
* Upload all perspectives/view images from a jubula run
|
83
|
+
** View-images were in doc_de/images/views/Artikelauswahl.png (localized_name) -> http://wiki.elexis.info/Datei:Ch.elexis:Artikelauswahl.png
|
84
|
+
** https://srv.elexis.info/jenkins/view/3.0/job/Elexis-3.0-Jubula/118/artifact/test-results/screenshots/Other/https://srv.elexis.info/jenkins/view/3.0/job/Elexis-3.0-Jubula/118/artifact/test-results/screenshots/Other/Fixmedikation.png
|
85
|
+
** Bug ch.elexis -> ch.elexis.core splitted. now you find it here
|
86
|
+
*** ch.elexis.core.application/plugin_de.properties:elexis.articleSelectorView=Artikelauswahl
|
87
|
+
*** ch.elexis.core.ui.laboratory/plugin_de.properties:elexis.articleSelectorView = Artikelauswahl
|
88
|
+
*** ch.elexis.core.ui/plugin_de.properties:elexis.articleSelectorView = Artikelauswahl
|
89
|
+
*** ch.elexis.core.application/plugin.xml: name="%elexis.articleSelectorView">
|
90
|
+
** Missing line [[Datei:Ch.elexis:Artikelauswahl.png]] in http://wiki.elexis.info/ChElexisViewsArtikelArtikelselektor
|
91
|
+
* Perspektives: were not uploaded to doc_de
|
92
|
+
* No images are pulled/pushed at the moment.
|
93
|
+
* Check whether a link to the view exists on the wiki.elexis.info/Hauptseite
|
94
|
+
* No support for features at the moment
|
95
|
+
* No multilingual support at the moment
|
96
|
+
|
97
|
+
|
98
|
+
h2. Contributing
|
99
|
+
|
100
|
+
# Fork it ( http://github.com/ngiger/elexis-wiki-interface/fork )
|
101
|
+
# Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
# Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
# Push to the branch (`git push origin my-new-feature`)
|
104
|
+
# Create new Pull Request
|
data/Rakefile
ADDED
data/bin/wiki_pull
ADDED
data/bin/wiki_pull_daily
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
|
3
|
+
require 'elexis/wiki/interface/workspace'
|
4
|
+
|
5
|
+
workspace = Elexis::Wiki::Interface::Workspace.new(Dir.pwd)
|
6
|
+
workspace.pull
|
7
|
+
workspace.show_missing(true)
|
8
|
+
files = Dir.glob('doc_??') +
|
9
|
+
Dir.glob('*/doc/*.mediawiki') +
|
10
|
+
Dir.glob('*/doc/*.png')
|
11
|
+
Dir.glob('*/doc/*.jpg')
|
12
|
+
Dir.glob('*/doc/*.gif')
|
13
|
+
files.each{
|
14
|
+
|file|
|
15
|
+
if /:/.match(File.basename(file))
|
16
|
+
puts "You may not add a file containg ':' or it will break git for Windows. Remove/rename #{file}"
|
17
|
+
exit 2
|
18
|
+
end
|
19
|
+
}
|
20
|
+
system("git add -f #{files.join(' ')}")
|
21
|
+
system("git status")
|
22
|
+
system("git commit --all -m '#{File.basename(__FILE__)}: Added mediawiki content from #{workspace.wiki}'")
|
23
|
+
system("git status")
|
24
|
+
system("git log -1")
|
25
|
+
# system("git push")
|
data/bin/wiki_push
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'elexis/wiki/interface/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "elexis-wiki-interface"
|
8
|
+
spec.version = Elexis::Wiki::Interface::VERSION
|
9
|
+
spec.authors = ["Niklaus Giger"]
|
10
|
+
spec.email = ["niklaus.giger@member.fsf.org"]
|
11
|
+
spec.summary = "Interface between elexis source and wiki"
|
12
|
+
spec.description = "Support for pulling/pushing wiki content from source repository to elexis.wiki"
|
13
|
+
spec.homepage = "http://wiki.elexis.info"
|
14
|
+
spec.license = "GPLv3"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.add_dependency 'rubyzip', '< 1.0.0'
|
21
|
+
spec.add_dependency 'unicode'
|
22
|
+
spec.add_dependency 'mediawiki-gateway'
|
23
|
+
spec.add_dependency 'eclipse-plugin', '>= 0.1'
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'eclipse/plugin'
|
4
|
+
require 'media_wiki' # TODO: port it to require 'mediawiki_api'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'open-uri'
|
7
|
+
require 'time'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
module Elexis
|
11
|
+
module Wiki
|
12
|
+
module Interface
|
13
|
+
class Workspace
|
14
|
+
attr_reader :info, :mw, :wiki, :views_missing_documentation, :perspectives_missing_documentation, :plugins_missing_documentation, :features_missing_documentation,
|
15
|
+
:doc_project, :features, :info
|
16
|
+
def initialize(dir, wiki = 'http://wiki.elexis.info/api.php')
|
17
|
+
@wiki = wiki
|
18
|
+
@mw = MediaWiki::Gateway.new(@wiki)
|
19
|
+
@info = Eclipse::Workspace.new(dir)
|
20
|
+
@doc_projects = Dir.glob(File.join(dir, "doc_??", ".project"))
|
21
|
+
@info.parse_sub_dirs
|
22
|
+
@info.show if $VERBOSE
|
23
|
+
@views_missing_documentation =[]
|
24
|
+
@perspectives_missing_documentation =[]
|
25
|
+
@plugins_missing_documentation =[]
|
26
|
+
@features_missing_documentation =[]
|
27
|
+
end
|
28
|
+
def show_missing(details = false)
|
29
|
+
if views_missing_documentation.size and
|
30
|
+
plugins_missing_documentation.size == 0 and
|
31
|
+
features_missing_documentation.size == 0 and
|
32
|
+
perspectives_missing_documentation.size == 0
|
33
|
+
puts "Eclipse-Workspace #{@info.workspace_dir} seems to have documented all views, features, plugins and perspectives"
|
34
|
+
else
|
35
|
+
puts "Eclipse-Workspace #{@info.workspace_dir} needs documenting "
|
36
|
+
if views_missing_documentation.size > 0
|
37
|
+
puts " #{views_missing_documentation.size} views"
|
38
|
+
puts " #{views_missing_documentation.inspect}" if details
|
39
|
+
end
|
40
|
+
if plugins_missing_documentation.size > 0
|
41
|
+
puts " #{plugins_missing_documentation.size} plugins"
|
42
|
+
puts " #{plugins_missing_documentation.inspect}" if details
|
43
|
+
end
|
44
|
+
if features_missing_documentation.size > 0
|
45
|
+
puts " #{features_missing_documentation.size} features"
|
46
|
+
puts " #{features_missing_documentation.inspect}" if details
|
47
|
+
end
|
48
|
+
if perspectives_missing_documentation.size > 0
|
49
|
+
puts " #{perspectives_missing_documentation.size} perspectives"
|
50
|
+
puts " #{perspectives_missing_documentation.inspect}" if details
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def push
|
55
|
+
check_config_file
|
56
|
+
raise "must define wiki with user and password in #{@config_yml}" unless @user and @password and @wiki
|
57
|
+
@mw.login(@user, @password)
|
58
|
+
@doc_projects.each{
|
59
|
+
|prj|
|
60
|
+
dir = File.dirname(prj)
|
61
|
+
}
|
62
|
+
@info.plugins.each{
|
63
|
+
|id,plugin|
|
64
|
+
to_push = Dir.glob("#{plugin.jar_or_src}/doc/*.mediawiki")
|
65
|
+
to_push.each{
|
66
|
+
|file|
|
67
|
+
# verify that locally committed file is newer than the page in the wiki
|
68
|
+
# verify that the content after the push matches the local content
|
69
|
+
my_new_content = File.new(file).read
|
70
|
+
to_verify = my_new_content.gsub(/\n+/,"\n").chomp
|
71
|
+
pagename = File.basename(file, '.mediawiki').capitalize
|
72
|
+
last_wiki_modification = get_page_modification_time(pagename)
|
73
|
+
last_git_modification = get_git_modification(file)
|
74
|
+
unless last_wiki_modification
|
75
|
+
puts "first upload #{File.basename(file)} last_git_modification is #{last_git_modification}" if $VERBOSE
|
76
|
+
@mw.create(pagename, my_new_content,{:overwrite => true, :summary => "pushed by #{File.basename(__FILE__)}" })
|
77
|
+
else
|
78
|
+
got = @mw.get(pagename).gsub(/\n+/,"\n")
|
79
|
+
if got == to_verify
|
80
|
+
puts "No changes to push for #{file}"
|
81
|
+
next
|
82
|
+
end
|
83
|
+
@mw.edit(pagename, to_verify,{:overwrite => true, :summary => "pushed by #{File.basename(__FILE__)}" })
|
84
|
+
puts "Uploaded #{file} to #{pagename}" if $VERBOSE
|
85
|
+
end
|
86
|
+
}
|
87
|
+
if to_push.size > 0 # then upload also all *.png files
|
88
|
+
images_to_push = Dir.glob("#{plugin.jar_or_src}/doc/*.png")
|
89
|
+
images_to_push.each{
|
90
|
+
|image|
|
91
|
+
if /:/.match(File.basename(image))
|
92
|
+
puts "You may not add a file containg ':' or it will break git for Windows. Remove/rename #{image}"
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
|
96
|
+
git_mod = get_git_modification(image)
|
97
|
+
wiki_mod = get_image_modification_name(image)
|
98
|
+
|
99
|
+
if wiki_mod == nil
|
100
|
+
puts "first upload #{File.basename(image)} as last_git_modification is #{git_mod}" if $VERBOSE
|
101
|
+
else
|
102
|
+
to_verify = File.new(image, 'rb').read
|
103
|
+
got = @mw.get(File.basename(image))
|
104
|
+
if got == to_verify
|
105
|
+
puts "nothing to upload for #{image}" if $VERBOSE
|
106
|
+
next
|
107
|
+
end
|
108
|
+
end
|
109
|
+
begin
|
110
|
+
res = @mw.upload(image, 'filename' => File.basename(image))
|
111
|
+
puts "res für #{image} exists? #{File.exists?(image)} ist #{res.to_s}"
|
112
|
+
puts "If you received API error: code 'verification-error', info 'This file did not pass file verification'"
|
113
|
+
puts "this means that the file type and content do not match, e.g. you have a *png file but in reality it is a JPEG file."
|
114
|
+
puts "In this case convert file.png file.png fixes this problem"
|
115
|
+
rescue MediaWiki::APIError => e
|
116
|
+
puts "rescue für #{image} #{e}" # if $VERBOSE
|
117
|
+
end
|
118
|
+
}
|
119
|
+
end
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_git_modification(file)
|
124
|
+
return nil unless File.exists?(file)
|
125
|
+
git_time = `git log -1 --pretty=format:%ai #{file}`
|
126
|
+
return nil unless git_time.length > 8
|
127
|
+
Time.parse(git_time.chomp).utc
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_page_modification_time(pagename)
|
131
|
+
json_url = "#{@wiki}?action=query&format=json&prop=revisions&titles=#{pagename}&rvprop=timestamp"
|
132
|
+
json = RestClient.get(json_url)
|
133
|
+
wiki_json_timestamp_to_time(json, pagename)
|
134
|
+
end
|
135
|
+
|
136
|
+
def pull
|
137
|
+
@doc_projects.each{
|
138
|
+
|prj|
|
139
|
+
dir = File.dirname(prj)
|
140
|
+
get_content_from_wiki(dir, File.basename(dir))
|
141
|
+
}
|
142
|
+
@info.plugins.each{
|
143
|
+
|id, info|
|
144
|
+
puts "Pulling for plugin #{id}" if $VERBOSE
|
145
|
+
pull_docs_views(info)
|
146
|
+
pull_docs_plugins(info)
|
147
|
+
pull_docs_perspectives(info)
|
148
|
+
}
|
149
|
+
@info.features.each{
|
150
|
+
|id, info|
|
151
|
+
puts "Pulling for feature #{id}" if $VERBOSE
|
152
|
+
pull_docs_features(info)
|
153
|
+
}
|
154
|
+
saved = Dir.pwd
|
155
|
+
end
|
156
|
+
|
157
|
+
def perspectiveToPageName(perspective)
|
158
|
+
# http://wiki.elexis.info/P_Abrechnungen
|
159
|
+
name = 'P_'+ perspective.id.gsub(' ', '')
|
160
|
+
puts "perspectiveToPageName for #{perspective.inspect} is '#{name}'" if $VERBOSE
|
161
|
+
name
|
162
|
+
end
|
163
|
+
def viewToPageName(plugin_id, view)
|
164
|
+
# für ch.elexis.agenda.views.TagesView (= view.id)
|
165
|
+
# http://wiki.elexis.info/ChElexisAgendaViewsTagesview
|
166
|
+
# wurde unter http://wiki.elexis.info/Hauptseite ein Link Agenda (= view.name) angelegt.
|
167
|
+
# evtl. sollten wir testen, ob dieser Link vorhanden ist
|
168
|
+
# http://wiki.elexis.info/ChElexisIcpcViewsEpisodesview
|
169
|
+
comps = view.id.split('.')
|
170
|
+
pageName = comps[0..-2].collect{|x| x.capitalize}.join + 'Views'+view.id.split('.').last.capitalize
|
171
|
+
puts "viewToPageName for #{plugin_id}/#{view.id} is #{pageName}" if $VERBOSE
|
172
|
+
pageName
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
def wiki_json_timestamp_to_time(json, page_or_img)
|
177
|
+
return nil unless json
|
178
|
+
begin
|
179
|
+
m = json.match(/timestamp['"]:['"]([^'"]+)/)
|
180
|
+
return Time.parse(m[1]) if m
|
181
|
+
end
|
182
|
+
nil
|
183
|
+
end
|
184
|
+
|
185
|
+
def check_config_file
|
186
|
+
possibleCfgs = ['/etc/elexis-wiki-interface/config.yml', File.join(Dir.pwd, 'config.yml'), ]
|
187
|
+
possibleCfgs.each{ |cfg| @config_yml = cfg; break if File.exists?(cfg) }
|
188
|
+
raise "need a config file #{possibleCfgs.join(' or ')} for wiki with user/password" unless File.exists?(@config_yml)
|
189
|
+
yaml = YAML.load_file(@config_yml)
|
190
|
+
@user = yaml['user']
|
191
|
+
@password = yaml['password']
|
192
|
+
@wiki = yaml['wiki']
|
193
|
+
puts "MediWiki #{@wiki} user #{@user} with password #{@password}" if $VERBOSE
|
194
|
+
end
|
195
|
+
|
196
|
+
def shorten_wiki_image(image)
|
197
|
+
return File.basename(image) unless File.basename(image).index(':')
|
198
|
+
File.basename(image).split(':')[1..-1].join(':').gsub(':', '_')
|
199
|
+
end
|
200
|
+
|
201
|
+
# http://wiki.elexis.info/api.php?action=query&format=json&list=allimages&ailimit=5&aiprop=timestamp&aiprefix=Ch.elexis.notes:config.png&*
|
202
|
+
def get_image_modification_name(image)
|
203
|
+
json_url = "#{@wiki}?action=query&format=json&list=allimages&ailimit=5&aiprop=timestamp&aiprefix=#{shorten_wiki_image(image)}"
|
204
|
+
json = RestClient.get(json_url)
|
205
|
+
wiki_json_timestamp_to_time(json, image)
|
206
|
+
end
|
207
|
+
|
208
|
+
# helper function, as mediawiki-gateway does not handle this situation correctly
|
209
|
+
def download_image_file(image, downloaded_image)
|
210
|
+
short_image = shorten_wiki_image(image)
|
211
|
+
unless File.exist? downloaded_image
|
212
|
+
json_url = "#{@wiki}?action=query&format=json&list=allimages&ailimit=5&aiprop=url&aiprefix=#{short_image}"
|
213
|
+
json = RestClient.get(json_url)
|
214
|
+
unless json
|
215
|
+
puts "JSON: Could not fetch for image #{image} using #{json_url}"
|
216
|
+
return
|
217
|
+
end
|
218
|
+
begin
|
219
|
+
answer = JSON.parse(json)
|
220
|
+
image_url = nil
|
221
|
+
image_url = answer['query'].first[1].first['url'] if answer['query'] and answer['query'].size >= 1 and answer['query'].first[1].size > 0
|
222
|
+
if image_url
|
223
|
+
File.open(downloaded_image, 'w') do |file|
|
224
|
+
file.write(open(image_url).read)
|
225
|
+
end
|
226
|
+
else
|
227
|
+
puts "skipping image #{image}"
|
228
|
+
end
|
229
|
+
rescue => e
|
230
|
+
puts "JSON: Could not fetch for image #{image} using #{json_url}"
|
231
|
+
puts " was '#{json}'"
|
232
|
+
puts " error was #{e.inspect}"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
puts "Downloaded image #{downloaded_image} #{File.size(downloaded_image)} bytes" if $VERBOSE
|
236
|
+
end
|
237
|
+
|
238
|
+
def get_content_from_wiki(out_dir, pageName)
|
239
|
+
puts "get_content_from_wiki page #{pageName} -> #{out_dir}" if $VERBOSE
|
240
|
+
out_name = File.join(out_dir, pageName + '.mediawiki')
|
241
|
+
FileUtils.makedirs(out_dir) unless File.directory?(out_dir)
|
242
|
+
begin
|
243
|
+
content = @mw.get(pageName)
|
244
|
+
rescue MediaWiki::Gateway::Exception => e
|
245
|
+
puts "Unable to get #{pageName} for #{out_dir} from #{File.dirname(@mw.wiki_url)}"
|
246
|
+
return nil
|
247
|
+
end
|
248
|
+
if content
|
249
|
+
ausgabe = File.open(out_name, 'w+') { |f| f.write content.gsub(/(Image:[\w\.]+):(\w+.png)/, '\1_\2') }
|
250
|
+
@mw.images(pageName).each{
|
251
|
+
|image|
|
252
|
+
image = image.gsub(/[^\w\.:]/, '_')
|
253
|
+
downloaded_image = File.join(out_dir, shorten_wiki_image(image))
|
254
|
+
download_image_file(image, downloaded_image.sub(':', ''))
|
255
|
+
break if defined?(RSpec) # speed up rspec
|
256
|
+
}
|
257
|
+
else
|
258
|
+
puts "Could not fetch #{pageName} from #{@mw}" if $VERBOSE
|
259
|
+
end
|
260
|
+
content
|
261
|
+
end
|
262
|
+
def pull_docs_views(plugin)
|
263
|
+
id = plugin.symbolicName
|
264
|
+
plugin.views.each{
|
265
|
+
|id, view|
|
266
|
+
pageName = viewToPageName(plugin.symbolicName, view)
|
267
|
+
content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
|
268
|
+
@views_missing_documentation << pageName unless content
|
269
|
+
}
|
270
|
+
end
|
271
|
+
def pull_docs_perspectives(plugin)
|
272
|
+
id = plugin.symbolicName
|
273
|
+
plugin.perspectives.each{
|
274
|
+
|id, perspective|
|
275
|
+
pageName = perspectiveToPageName(perspective)
|
276
|
+
content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
|
277
|
+
@perspectives_missing_documentation << pageName unless content
|
278
|
+
}
|
279
|
+
end
|
280
|
+
def pull_docs_plugins(plugin)
|
281
|
+
id = plugin.symbolicName
|
282
|
+
pageName = id.capitalize
|
283
|
+
content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
|
284
|
+
@perspectives_missing_documentation << pageName unless content
|
285
|
+
end
|
286
|
+
def pull_docs_features(feature)
|
287
|
+
id = feature.symbolicName
|
288
|
+
pageName = id.capitalize
|
289
|
+
content = get_content_from_wiki(File.join(@info.workspace_dir, id, 'doc'), pageName)
|
290
|
+
unless content
|
291
|
+
content = get_content_from_wiki(File.join(@info.workspace_dir, id, 'doc'), pageName.sub(/feature$/, 'feature.feature.group'))
|
292
|
+
puts "pull_docs_features failed #{id} #{pageName}" unless content
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|