elexis-wiki-interface 0.5.1 → 0.5.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/history.textile +10 -0
- data/lib/elexis/wiki/images.rb +49 -28
- data/lib/elexis/wiki/interface.rb +1 -0
- data/lib/elexis/wiki/version.rb +1 -1
- data/spec/data/images/ch.elexis.icpc/doc/test2.mediawiki +2 -1
- data/spec/images_spec.rb +79 -18
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39023cc608821f4d521e4ecbc6bbced22b04bed5
|
4
|
+
data.tar.gz: 53d24e645de05ca3ebbb95d7ead6095de2ec9501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dca8f432c28684fff8170c702b2efbbbea0a4bdec271b36eeeaf42116569f203c72715eb212cebce13c8738495bd97d2d998f84ca8be12ffdc0924bbc940280
|
7
|
+
data.tar.gz: 42a2159ea7d141b3b4e72c6bceb4a6c552a415f21ad2a7b3d24bced1c35c5423212ff40182ec11c5072e1275c86edb26ddc2033ed10537503c0087691ed4ffd2
|
data/Gemfile.lock
CHANGED
data/history.textile
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
h3. Version 0.5.2 (2015-10-29)
|
2
|
+
|
3
|
+
* Correctly rename picture with ':' and '/'.
|
4
|
+
* Convert CamelCase to underscore
|
5
|
+
|
6
|
+
h3. Version 0.5.1 (2015-10-24)
|
7
|
+
|
8
|
+
* Ensure that files that start with the short project name are followed by a '-'
|
9
|
+
* Accept picture containing '-' in their base_name
|
10
|
+
|
1
11
|
h3. Version 0.5.1 (2015-10-23)
|
2
12
|
|
3
13
|
* Cleanup doc
|
data/lib/elexis/wiki/images.rb
CHANGED
@@ -10,9 +10,19 @@ require 'time'
|
|
10
10
|
require 'yaml'
|
11
11
|
require 'csv'
|
12
12
|
|
13
|
+
class String
|
14
|
+
# Convert CamelCase to underscore
|
15
|
+
def underscore
|
16
|
+
self.gsub(/::/, '/').
|
17
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
18
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
19
|
+
downcase
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
module Elexis
|
14
24
|
module Wiki
|
15
|
-
ImagePattern = /(\[File:|Datei:|\[Image:)([ \w
|
25
|
+
ImagePattern = /(\[File:|Datei:|\[Image:)(?:[^\/:]*\/)?([ \w\.:\/-]*)([^\]\|]*)/
|
16
26
|
|
17
27
|
#
|
18
28
|
# This helper class collect information about all images used in
|
@@ -109,13 +119,13 @@ module Elexis
|
|
109
119
|
sha256 = Digest::SHA256.hexdigest(IO.read(path))
|
110
120
|
same_sha256 = @pictures.find_all{|x| x[:sha256] == sha256}
|
111
121
|
same_name = @pictures.find_all{|x| x[:name] == picture[:name]}
|
112
|
-
nrSha256 = same_name.collect{|c| get_small_name(c[:sha256])}.uniq
|
122
|
+
nrSha256 = same_name.collect{|c| Images.get_small_name(c[:sha256])}.uniq
|
113
123
|
if same_sha256.size == 1 and nrSha256.size == 1
|
114
124
|
puts "new_best_name 3 @short_and_sha_okay #{sha256} for #{path}" if debug
|
115
125
|
picture[:rule] = 'short_and_sha_okay nr_single_sha'
|
116
126
|
@short_and_sha_okay << path
|
117
127
|
@nr_single_sha << same_sha256
|
118
|
-
picture[:best_name] = get_small_name(path)
|
128
|
+
picture[:best_name] = Images.get_small_name(path)
|
119
129
|
return
|
120
130
|
else
|
121
131
|
msg = " nrSha #{sha256.size} #{sha256}"
|
@@ -129,16 +139,16 @@ module Elexis
|
|
129
139
|
if found.size == 1 and nrSha256.size == 1
|
130
140
|
puts "new_best_name 4 case_sensitives #{found}" if debug
|
131
141
|
picture[:rule] = 'case_sensitives'
|
132
|
-
picture[:best_name] = get_small_name(path)
|
142
|
+
picture[:best_name] = Images.get_small_name(path)
|
133
143
|
return
|
134
144
|
end
|
135
145
|
multiple = same_sha256.collect{|c| c[:name]}.uniq
|
136
|
-
to_reduce = same_sha256.collect{|c| get_small_name(c[:name])}.uniq
|
146
|
+
to_reduce = same_sha256.collect{|c| Images.get_small_name(c[:name])}.uniq
|
137
147
|
if nrSha256.size == 1
|
138
148
|
@to_short_names[path] = to_reduce
|
139
149
|
puts "new_best_name 5 to_short_names #{multiple} => #{to_reduce} nrSha #{sha256.size} #{sha256}" if debug
|
140
150
|
picture[:rule] = 'to_short_names'
|
141
|
-
picture[:best_name] = get_small_name(path)
|
151
|
+
picture[:best_name] = Images.get_small_name(path)
|
142
152
|
return
|
143
153
|
end
|
144
154
|
puts "new_best_name 6 multiple #{multiple} to_reduce #{to_reduce} #{get_name_with_project(picture[:path])}" if debug
|
@@ -171,16 +181,22 @@ module Elexis
|
|
171
181
|
initialize_database
|
172
182
|
end
|
173
183
|
|
174
|
-
def
|
184
|
+
def Images.get_project_abbreviation(path)
|
175
185
|
dir = File.dirname(path)
|
186
|
+
dir.sub!(/\/images$/, '')
|
176
187
|
found = dir.sub(/(\.feature|[._]test.*|)\/doc/i, '').sub(/\.v\d$/, '')
|
177
|
-
|
188
|
+
found.split('.')[-1]
|
189
|
+
end
|
190
|
+
|
191
|
+
def get_name_with_project(path)
|
192
|
+
prefix =Images.get_project_abbreviation(path)
|
193
|
+
result = (prefix + '-' + File.basename(path)).downcase.gsub(':', '-')
|
178
194
|
result
|
179
195
|
end
|
180
196
|
|
181
|
-
def get_small_name(path)
|
197
|
+
def Images.get_small_name(path)
|
182
198
|
ext = File.extname(path)
|
183
|
-
to_consider = File.basename(path, ext).gsub(':','-')
|
199
|
+
to_consider = File.basename(path, ext).gsub(':','-').underscore
|
184
200
|
if to_consider.index('.')
|
185
201
|
part = to_consider.split('.')[-1].downcase
|
186
202
|
if part.split('_').size > 1
|
@@ -191,6 +207,10 @@ module Elexis
|
|
191
207
|
else
|
192
208
|
result = to_consider
|
193
209
|
end
|
210
|
+
short = Images.get_project_abbreviation(path)
|
211
|
+
regexp = /^(#{short})([^-])/i
|
212
|
+
m = regexp.match(result)
|
213
|
+
result = result.sub(regexp, '\1-\2') if m and short
|
194
214
|
(result + ext).downcase
|
195
215
|
end
|
196
216
|
|
@@ -229,26 +249,12 @@ module Elexis
|
|
229
249
|
end
|
230
250
|
end
|
231
251
|
|
232
|
-
def
|
233
|
-
files = Dir.glob(file_correct_case + '*', File::FNM_CASEFOLD)
|
234
|
-
return if files.size == 1
|
235
|
-
files.each{
|
236
|
-
|file|
|
237
|
-
next if File.basename(file).eql?(File.basename(file_correct_case))
|
238
|
-
if @add_changes_to_git
|
239
|
-
run_git_cmd("git rm -f #{file}")
|
240
|
-
else
|
241
|
-
FileUtils.rm_f(file)
|
242
|
-
end
|
243
|
-
}
|
244
|
-
end
|
245
|
-
|
246
|
-
def run_git_cmd(git_cmd)
|
252
|
+
def run_git_cmd(git_cmd, may_fail=false)
|
247
253
|
return unless @add_changes_to_git
|
248
254
|
res = system(git_cmd)
|
249
255
|
unless res
|
250
256
|
raise "Running #{git_cmd} failed"
|
251
|
-
end
|
257
|
+
end unless may_fail
|
252
258
|
@actions << git_cmd
|
253
259
|
end
|
254
260
|
|
@@ -266,7 +272,7 @@ module Elexis
|
|
266
272
|
Dir.glob("*#{extension}").each do
|
267
273
|
|wiki_file|
|
268
274
|
old_image_name = picture[:name]
|
269
|
-
new_image_name = picture[:best_name]
|
275
|
+
new_image_name = picture[:best_name].downcase
|
270
276
|
if old_image_name.index('-')
|
271
277
|
puts "Skipping mv #{old_image_name} #{new_image_name}"
|
272
278
|
next
|
@@ -286,9 +292,20 @@ module Elexis
|
|
286
292
|
}
|
287
293
|
end
|
288
294
|
}
|
295
|
+
|
296
|
+
# change_image_name_in_mediawiki
|
289
297
|
Dir.chdir(@rootDir)
|
290
298
|
# Add all pictures which were downloaded and still have the same name
|
291
|
-
@pictures.each { |picture|
|
299
|
+
@pictures.each { |picture|
|
300
|
+
next unless picture[:best_name]
|
301
|
+
dir = File.dirname(picture[:path])
|
302
|
+
dir ||= '.'
|
303
|
+
new_path = File.join(dir, picture[:best_name])
|
304
|
+
next unless File.exists?(picture[:path])
|
305
|
+
FileUtils.cp(picture[:path], new_path, :verbose => true) unless File.exists?(new_path)
|
306
|
+
run_git_cmd("git add -f #{new_path}")
|
307
|
+
run_git_cmd("git rm -f --ignore-unmatch #{picture[:path]}", true) if picture[:path] != new_path
|
308
|
+
}
|
292
309
|
@actions.uniq!
|
293
310
|
puts @actions.join("\n")
|
294
311
|
ensure
|
@@ -299,6 +316,8 @@ module Elexis
|
|
299
316
|
# We assume that the referenced new_image_name is living in the same directory
|
300
317
|
# as the mediawiki_file
|
301
318
|
def change_image_name_in_mediawiki(mediawiki_file, old_image_name, new_image_name)
|
319
|
+
savedDir = Dir.pwd
|
320
|
+
Dir.chdir(File.dirname(mediawiki_file))
|
302
321
|
if new_image_name.downcase != File.basename(new_image_name).downcase
|
303
322
|
raise "new_image_name #{new_image_name} may not contain a directory path"
|
304
323
|
end
|
@@ -325,6 +344,7 @@ module Elexis
|
|
325
344
|
if files = Dir.glob(simpleName, File::FNM_CASEFOLD) and files.size >= 1
|
326
345
|
# if files = (Dir.glob(simpleName, File::FNM_CASEFOLD) +Dir.glob(old_image_name, File::FNM_CASEFOLD)) and files.size >= 1
|
327
346
|
new_line = line.sub(m[2], new_image_name)
|
347
|
+
new_line = new_line.sub(m[3], '') if m[3]
|
328
348
|
puts "change_image_name_in_mediawiki #{__LINE__} #{line} aus #{m[2]} mit #{new_image_name}" if $VERBOSE
|
329
349
|
newLines << new_line
|
330
350
|
else
|
@@ -336,6 +356,7 @@ module Elexis
|
|
336
356
|
}
|
337
357
|
File.open(mediawiki_file, "w") {|f| f.write newLines.join.gsub(/\[\[Datei:|\[\[Image:/i, '[[File:')}
|
338
358
|
run_git_cmd("git add #{mediawiki_file}")
|
359
|
+
ensure Dir.chdir(savedDir)
|
339
360
|
end
|
340
361
|
end
|
341
362
|
end
|
@@ -157,6 +157,7 @@ module Elexis
|
|
157
157
|
end
|
158
158
|
rescue => e
|
159
159
|
puts "JSON: Could not fetch for image #{image} for #{pageName} using #{json_url}"
|
160
|
+
FileUtils.rm_f(image) if File.exists?(image) and File.size(image) == 0
|
160
161
|
puts " was '#{json}'"
|
161
162
|
puts " error was #{e.inspect}"
|
162
163
|
end
|
data/lib/elexis/wiki/version.rb
CHANGED
@@ -11,7 +11,8 @@ tag_four [[Datei:ch.elexis.icpc:icpc4.png|image]]<br />
|
|
11
11
|
tag_png [[Datei:Ch.elexis.icpc:icpc5.png|image]]<br />
|
12
12
|
tag_jpg [[Datei:Ch.elexis.icpc:icpc6.png|image]]<br />
|
13
13
|
tag_gif [[Datei:Ch.elexis.icpc:icpc7.png|image]]<br />
|
14
|
-
tag_utf [[File:
|
14
|
+
tag_utf [[File:kabel.png<U+200E>]]
|
15
|
+
tag_frame_none [[File:Ch.elexis.icpc:icpc5.png|frame|none]] <br>
|
15
16
|
|
16
17
|
|
17
18
|
|
data/spec/images_spec.rb
CHANGED
@@ -4,7 +4,8 @@ require 'spec_helper'
|
|
4
4
|
require "elexis/wiki/images"
|
5
5
|
|
6
6
|
describe 'Images' do
|
7
|
-
NR_PICTURES =
|
7
|
+
NR_PICTURES = 23
|
8
|
+
NR_ELEMS_IN_IMAGE_PATTERN = 4
|
8
9
|
|
9
10
|
before :all do
|
10
11
|
@subdir = 'images'
|
@@ -40,6 +41,37 @@ describe 'Images' do
|
|
40
41
|
expect(content.index('favicon_green.png')).not_to eq 0
|
41
42
|
end
|
42
43
|
|
44
|
+
it "should match picture names with a /" do
|
45
|
+
res = Elexis::Wiki::ImagePattern.match('[[File:At.medevit.elexis.dbcheck/dbcleaningui.png|frame|none]]')
|
46
|
+
expect(res.size).to eq NR_ELEMS_IN_IMAGE_PATTERN
|
47
|
+
expect(res[2]).to eq 'dbcleaningui.png'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should match picture doc_de/settings_agenda-druck1.png" do
|
51
|
+
res = Elexis::Wiki::ImagePattern.match('[[File:doc_de/settings_agenda-druck1.png|image]]<br />')
|
52
|
+
expect(res.size).to eq NR_ELEMS_IN_IMAGE_PATTERN
|
53
|
+
expect(res[2]).to eq 'settings_agenda-druck1.png'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should match picture File:dbcleaningui.png" do
|
57
|
+
res = Elexis::Wiki::ImagePattern.match('[[File:dbcleaningui.png|frame|none]]')
|
58
|
+
expect(res.size).to eq NR_ELEMS_IN_IMAGE_PATTERN
|
59
|
+
expect(res[2]).to eq 'dbcleaningui.png'
|
60
|
+
end
|
61
|
+
|
62
|
+
examples = { 'doc_de/settings_agenda-druck1.png' => 'settings_agenda-druck1.png',
|
63
|
+
'doc_de/settingsAgendaDruck1.png' => 'settings_agenda_druck1.png',
|
64
|
+
'CurabillWarning1.png' => 'curabill_warning1.png',
|
65
|
+
'ch.elexis.icpc/Icpc1.png' => 'icpc-1.png',
|
66
|
+
}
|
67
|
+
examples.each{
|
68
|
+
|picture_name, expected_result|
|
69
|
+
it "should return correct get_small_name for #{picture_name}" do
|
70
|
+
res = Elexis::Wiki::Images.get_small_name picture_name
|
71
|
+
expect(res).to eq expected_result
|
72
|
+
end
|
73
|
+
}
|
74
|
+
|
43
75
|
it "pictures.csv should contain some png" do
|
44
76
|
content = IO.read(@images.csv)
|
45
77
|
expect(content.index('icpc6.png')).not_to eq 0
|
@@ -79,6 +111,8 @@ describe 'Images' do
|
|
79
111
|
end
|
80
112
|
|
81
113
|
rename_tests = {
|
114
|
+
# 'Ch.elexis.icpc:Icpc2.png' => [ 'icpc2.png', 'tag_two [[File:icpc-2.png|image]]'],
|
115
|
+
'Ch.elexis.icpc:icpc5.png' => [ 'icpc5.png', 'tag_frame_none [[File:icpc5.png|frame|none]]'],
|
82
116
|
'Ch.elexis.icpc:icpc5.png' => [ 'icpc5.png', 'tag_png [[File:icpc5.png|image]]'],
|
83
117
|
'Ch.elexis.icpc:icpc6.png' => [ 'elexis_logo.jpg', 'tag_jpg [[File:elexis_logo.jpg|image]]'],
|
84
118
|
'Ch.elexis.icpc:icpc7.png' => [ 'disposan.gif', 'tag_gif [[File:disposan.gif|image]]'],
|
@@ -91,6 +125,17 @@ describe 'Images' do
|
|
91
125
|
end
|
92
126
|
}
|
93
127
|
|
128
|
+
it "should remove UTF-8 chars like <U+200E> after picture names" do
|
129
|
+
wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.icpc', 'doc', 'test2.mediawiki')
|
130
|
+
expect(File.exist?(wiki_file)).to eq true
|
131
|
+
old_picture_name = 'kabel.png'
|
132
|
+
new_picture_name = Elexis::Wiki::Images.get_small_name(old_picture_name)
|
133
|
+
expect(IO.read(wiki_file)).to include old_picture_name
|
134
|
+
@images.change_image_name_in_mediawiki(wiki_file, old_picture_name, new_picture_name)
|
135
|
+
content = IO.read(wiki_file)
|
136
|
+
expect(content).to include 'kabel.png]'
|
137
|
+
end
|
138
|
+
|
94
139
|
it "should refuse to change the image name in a mediawiki file when we find no corresponding image file" do
|
95
140
|
wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.icpc', 'doc', 'test2.mediawiki')
|
96
141
|
expect(File.exist?(wiki_file)).to eq true
|
@@ -99,6 +144,17 @@ describe 'Images' do
|
|
99
144
|
expect { @images.change_image_name_in_mediawiki(wiki_file, old_picture_name, 'icpc_should_not_exist.png')}.to raise_error(RuntimeError, /Could not find image/)
|
100
145
|
end
|
101
146
|
|
147
|
+
checks = {
|
148
|
+
'at.medevit.elexis.swissmedic/fixmedikationaufruf.png' => 'swissmedic',
|
149
|
+
'at.medevit.elexis.swissmedic/doc/fixmedikationaufruf.png' => 'swissmedic',
|
150
|
+
'at.medevit.elexis.swissmedic/doc/images/fixmedikationaufruf.png' => 'swissmedic',
|
151
|
+
}
|
152
|
+
checks.each{
|
153
|
+
|path, expected|
|
154
|
+
it "should return correct project name #{expected} for #{path}" do
|
155
|
+
expect(Elexis::Wiki::Images.get_project_abbreviation(path)).to eq expected
|
156
|
+
end
|
157
|
+
}
|
102
158
|
describe "determine_cleanup" do
|
103
159
|
before(:all) do
|
104
160
|
@images.determine_cleanup
|
@@ -164,9 +220,28 @@ describe 'ImagesCleanup' do
|
|
164
220
|
@images.execute_cleanup(true)
|
165
221
|
end
|
166
222
|
|
167
|
-
it "should add
|
168
|
-
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/
|
169
|
-
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/
|
223
|
+
it "should add icpc-8.png and icpc-1.png" do
|
224
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc-1.png")).not_to eq nil
|
225
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc1.png")).to eq nil
|
226
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/Icpc1.png")).to eq nil
|
227
|
+
expect(@images.actions.index("git add Icpc8.png && git mv Icpc8.png icpc-8.png")).not_to eq nil
|
228
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc8.png")).to eq nil
|
229
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/Icpc8.png")).to eq nil
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should not contain an picture with uppercase letter' do
|
233
|
+
regexp = /git add -f images\/(?:[.\w]+\/)+(?:[a-z0-9]*)([A-Z])/
|
234
|
+
@images.actions.each{
|
235
|
+
|img|
|
236
|
+
if m = regexp.match(img)
|
237
|
+
puts "Found uppercase in #{img}"
|
238
|
+
expect(m).to eq nil
|
239
|
+
end
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should add a "-" if the image name starts with the abbrev' do
|
244
|
+
expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc-1.png")).not_to eq nil
|
170
245
|
end
|
171
246
|
end
|
172
247
|
|
@@ -217,20 +292,6 @@ describe 'ImagesCleanup' do
|
|
217
292
|
files = Dir.glob(search)
|
218
293
|
expect(files.size).to eq 0
|
219
294
|
end
|
220
|
-
it "should remove_files_with_case_sensitive_changes" do
|
221
|
-
lowercase = "#{@images.rootDir}/test_lower_case.png"
|
222
|
-
up_case = "#{@images.rootDir}/TEST_LOWER_CASE.png"
|
223
|
-
capitalized = "#{@images.rootDir}/Test_lower_case.png"
|
224
|
-
[ lowercase, up_case, capitalized].each {
|
225
|
-
|file|
|
226
|
-
system("touch #{file}")
|
227
|
-
expect(File.exist?(file))
|
228
|
-
}
|
229
|
-
@images.remove_files_with_case_sensitive_changes(lowercase)
|
230
|
-
expect(File.exist?(lowercase))
|
231
|
-
expect(File.exist?(up_case)).to eq false
|
232
|
-
expect(File.exist?(capitalized)).to eq false
|
233
|
-
end
|
234
295
|
end
|
235
296
|
end
|
236
297
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elexis-wiki-interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niklaus Giger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -371,4 +371,3 @@ test_files:
|
|
371
371
|
- spec/interface_spec.rb
|
372
372
|
- spec/pull_spec.rb
|
373
373
|
- spec/spec_helper.rb
|
374
|
-
has_rdoc:
|