elexis-wiki-interface 0.4.8 → 0.5.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +25 -1
- data/README.textile +2 -3
- data/bin/wiki_pull +6 -3
- data/bin/wiki_pull_and_commit +38 -0
- data/bin/wiki_push +2 -2
- data/elexis-wiki-interface.gemspec +4 -3
- data/history.textile +14 -0
- data/lib/elexis/wiki/images.rb +338 -0
- data/lib/elexis/wiki/interface.rb +152 -2
- data/lib/elexis/wiki/version.rb +5 -0
- data/lib/elexis/wiki/workspace.rb +286 -0
- data/spec/data/images/ch.elexis.agenda/.project +36 -0
- data/spec/data/images/ch.elexis.agenda/META-INF/MANIFEST.MF +33 -0
- data/spec/data/images/ch.elexis.agenda/doc/fixmedikationaufruf.png +0 -0
- data/spec/data/images/ch.elexis.agenda/plugin.properties +8 -0
- data/spec/data/images/ch.elexis.agenda/plugin.xml +209 -0
- data/spec/data/images/ch.elexis.agenda/plugin_de.properties +8 -0
- data/spec/data/images/ch.elexis.agenda/plugin_en.properties +8 -0
- data/spec/data/images/ch.elexis.agenda/plugin_fr.properties +7 -0
- data/spec/data/images/ch.elexis.core.application.feature/.project +23 -0
- data/spec/data/images/ch.elexis.core.application.feature/build.properties +1 -0
- data/spec/data/images/ch.elexis.core.application.feature/feature.xml +699 -0
- data/spec/data/images/ch.elexis.core.application.feature/pom.xml +12 -0
- data/spec/data/images/ch.elexis.icpc/.project +28 -0
- data/spec/data/images/ch.elexis.icpc/META-INF/MANIFEST.MF +26 -0
- data/spec/data/images/ch.elexis.icpc/doc/Com.hilotec.elexis.opendocument_anleitung_opendocument_1.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/FixmedikationAufruf.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/Icpc8.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/ch.elexis.icpc_icpc1.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/disposan.gif +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/elexis_logo.jpg +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/favicon_green.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc0.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc1.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc2.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc3.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc4.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc5.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc6.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc7.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/icpc9.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/kabel.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/medevit_inbox1.png +0 -0
- data/spec/data/images/ch.elexis.icpc/doc/test.mediawiki +15 -0
- data/spec/data/images/ch.elexis.icpc/doc/test2.mediawiki +19 -0
- data/spec/data/images/ch.elexis.icpc/plugin.xml +74 -0
- data/spec/data/images/ch.elexis.notes/.project +34 -0
- data/spec/data/images/ch.elexis.notes/META-INF/MANIFEST.MF +17 -0
- data/spec/data/images/ch.elexis.notes/doc/At.medevit.medelexis.text.msword:WordBriefe.png +0 -0
- data/spec/data/images/ch.elexis.notes/doc/Ch.medelexis.openoffice:TextverarbeitungSettings.png +0 -0
- data/spec/data/images/ch.elexis.notes/doc/Icpc1.png +0 -0
- data/spec/data/images/ch.elexis.notes/doc/kabel.png +0 -0
- data/spec/data/images/ch.elexis.notes/doc/medidirect:use2.png +0 -0
- data/spec/data/images/ch.elexis.notes/doc/test.mediawiki +13 -0
- data/spec/data/images/ch.elexis.notes/plugin.properties +1 -0
- data/spec/data/images/ch.elexis.notes/plugin.xml +36 -0
- data/spec/data/images/ch.elexis.notes/plugin_de.properties +3 -0
- data/spec/data/images/ch.elexis.notes/plugin_en.properties +3 -0
- data/spec/data/images/ch.elexis.notes/plugin_fr.properties +3 -0
- data/spec/data/images/doc_de/.project +42 -0
- data/spec/data/images/elexis_api_test.png +0 -0
- data/spec/data/push/elexis_api_test.png +0 -0
- data/spec/images_spec.rb +236 -0
- data/spec/interface_spec.rb +118 -0
- data/spec/pull_spec.rb +16 -5
- metadata +128 -13
- data/History.txt +0 -41
- data/bin/wiki_pull_daily +0 -28
- data/lib/elexis/wiki/interface/version.rb +0 -7
- data/lib/elexis/wiki/interface/workspace.rb +0 -404
- data/spec/push_spec.rb +0 -31
- data/spec/update_images_spec.rb +0 -95
- data/spec/user_spec.rb +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ce49a15cb845a0cdfc0877279106c0c3f07ac9a
|
|
4
|
+
data.tar.gz: f18d578327aa1ddf483de7036b12747fd37067fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b97ac0b5d7affd17837da3ed44058c56b1bcc459b6fbb6351b3ea0509af483bdc722c45588bcb0edab24d0ac8995cd9b030b1c0d3c6f01cdb7467144c92d1261
|
|
7
|
+
data.tar.gz: bbea945c3ac300dd6adfa5e0f798486b3da44ed90b902ba65fc28c09ef9a6d39cde5f99825aff686cb815c5dc77606a7976cea55c8972d9495cf2b572378a418
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
elexis-wiki-interface (0.
|
|
4
|
+
elexis-wiki-interface (0.5.0)
|
|
5
5
|
eclipse-plugin (>= 0.1)
|
|
6
6
|
mediawiki-gateway
|
|
7
|
+
mediawiki_api
|
|
7
8
|
rubyzip (< 1.0.0)
|
|
8
9
|
unicode
|
|
9
10
|
|
|
10
11
|
GEM
|
|
11
12
|
remote: https://rubygems.org/
|
|
12
13
|
specs:
|
|
14
|
+
byebug (5.0.0)
|
|
15
|
+
columnize (= 0.9.0)
|
|
16
|
+
coderay (1.1.0)
|
|
17
|
+
columnize (0.9.0)
|
|
13
18
|
diff-lcs (1.2.5)
|
|
14
19
|
docile (1.1.5)
|
|
15
20
|
domain_name (0.5.24)
|
|
@@ -17,16 +22,33 @@ GEM
|
|
|
17
22
|
eclipse-plugin (0.3)
|
|
18
23
|
nokogiri
|
|
19
24
|
rubyzip (< 1.0.0)
|
|
25
|
+
faraday (0.9.1)
|
|
26
|
+
multipart-post (>= 1.2, < 3)
|
|
27
|
+
faraday-cookie_jar (0.0.6)
|
|
28
|
+
faraday (>= 0.7.4)
|
|
29
|
+
http-cookie (~> 1.0.0)
|
|
20
30
|
http-cookie (1.0.2)
|
|
21
31
|
domain_name (~> 0.5)
|
|
22
32
|
json (1.8.3)
|
|
23
33
|
mediawiki-gateway (1.0.0)
|
|
24
34
|
rest-client (~> 1.7)
|
|
35
|
+
mediawiki_api (0.5.0)
|
|
36
|
+
faraday (~> 0.9, >= 0.9.0)
|
|
37
|
+
faraday-cookie_jar (~> 0.0, >= 0.0.6)
|
|
38
|
+
method_source (0.8.2)
|
|
25
39
|
mime-types (2.6.1)
|
|
26
40
|
mini_portile (0.6.2)
|
|
41
|
+
multipart-post (2.0.0)
|
|
27
42
|
netrc (0.10.3)
|
|
28
43
|
nokogiri (1.6.6.2)
|
|
29
44
|
mini_portile (~> 0.6.0)
|
|
45
|
+
pry (0.10.1)
|
|
46
|
+
coderay (~> 1.1.0)
|
|
47
|
+
method_source (~> 0.8.1)
|
|
48
|
+
slop (~> 3.4)
|
|
49
|
+
pry-byebug (3.2.0)
|
|
50
|
+
byebug (~> 5.0)
|
|
51
|
+
pry (~> 0.10)
|
|
30
52
|
rake (10.4.2)
|
|
31
53
|
rest-client (1.8.0)
|
|
32
54
|
http-cookie (>= 1.0.2, < 2.0)
|
|
@@ -51,6 +73,7 @@ GEM
|
|
|
51
73
|
json (~> 1.8)
|
|
52
74
|
simplecov-html (~> 0.10.0)
|
|
53
75
|
simplecov-html (0.10.0)
|
|
76
|
+
slop (3.6.0)
|
|
54
77
|
unf (0.1.4)
|
|
55
78
|
unf_ext
|
|
56
79
|
unf_ext (0.0.7.1)
|
|
@@ -63,6 +86,7 @@ DEPENDENCIES
|
|
|
63
86
|
bundler (~> 1.10)
|
|
64
87
|
eclipse-plugin
|
|
65
88
|
elexis-wiki-interface!
|
|
89
|
+
pry-byebug
|
|
66
90
|
rake (~> 10.0)
|
|
67
91
|
rspec
|
|
68
92
|
simplecov
|
data/README.textile
CHANGED
|
@@ -12,7 +12,7 @@ Copyright: 2014 (c) by Niklaus Giger <niklaus.giger@member.fsf.org>
|
|
|
12
12
|
|
|
13
13
|
h2. Installation
|
|
14
14
|
|
|
15
|
-
Ensure that you use Ruby 1.9.2 or higher
|
|
15
|
+
Ensure that you use Ruby 1.9.2 or higher. Mediawiki 1.19 does not work. Mediawiki 1.25.2 works. Don't know how the versions between score.
|
|
16
16
|
|
|
17
17
|
Add this line to your application's Gemfile:
|
|
18
18
|
|
|
@@ -79,9 +79,8 @@ Also we don't use the tag Datei, as this one is not supported by the Mylin Wikit
|
|
|
79
79
|
** a perspective perspective.name with a localized name localized_name has a page P_<localized_name>
|
|
80
80
|
** an image file must be lowercase (files which differ only by the case will be deleted)
|
|
81
81
|
** use syntax @[[File:@, not [[Datei: or @[[Image:@
|
|
82
|
-
** png files should start with their
|
|
82
|
+
** png files should start with a name derived from their symbolic name, eg, molemax followed by '-' by a name or a globally unique name
|
|
83
83
|
** png files resides inside the 'doc' sub-directory of each plugin/feature
|
|
84
|
-
** inside the doc directoy we create a logical link of the plugin|feature name to the directory. This allows us to edit and preview the mediawiki files using the Mylin Wikitext extension of Eclipse.
|
|
85
84
|
|
|
86
85
|
h3. Limitations/TODO
|
|
87
86
|
|
data/bin/wiki_pull
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/bin/env ruby
|
|
2
|
-
require 'elexis/wiki/
|
|
3
|
-
|
|
4
|
-
workspace = Elexis::Wiki::Interface::Workspace.new(Dir.pwd)
|
|
2
|
+
require 'elexis/wiki/workspace'
|
|
3
|
+
workspace = Elexis::Wiki::Workspace.new(Dir.pwd)
|
|
5
4
|
workspace.pull
|
|
5
|
+
|
|
6
|
+
images = Elexis::Wiki::Images.new(Dir.pwd)
|
|
7
|
+
images.determine_cleanup
|
|
8
|
+
images.execute_cleanup
|
|
6
9
|
workspace.show_missing(true)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'elexis/wiki/workspace'
|
|
4
|
+
|
|
5
|
+
workspace = Elexis::Wiki::Workspace.new(Dir.pwd)
|
|
6
|
+
workspace.pull
|
|
7
|
+
|
|
8
|
+
images = Elexis::Wiki::Images.new(Dir.pwd)
|
|
9
|
+
images.determine_cleanup
|
|
10
|
+
images.execute_cleanup(true) # adds changes via git add
|
|
11
|
+
|
|
12
|
+
files = Dir.glob('doc_??') +
|
|
13
|
+
Dir.glob('*/doc/*.mediawiki', File::FNM_CASEFOLD) +
|
|
14
|
+
Dir.glob('*/doc/*.png', File::FNM_CASEFOLD)
|
|
15
|
+
Dir.glob('*/doc/*.jpg', File::FNM_CASEFOLD)
|
|
16
|
+
Dir.glob('*/doc/*.gif', File::FNM_CASEFOLD)
|
|
17
|
+
(Dir.glob("doc_??/*") + Dir.glob('*/doc/*')).each{|f| files << f if File.symlink?(f) }
|
|
18
|
+
files.each{
|
|
19
|
+
|file|
|
|
20
|
+
if /:/.match(File.basename(file))
|
|
21
|
+
puts "You may not add a file containg ':' or it will break git for Windows. Remove/rename #{file}"
|
|
22
|
+
exit 2
|
|
23
|
+
end
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (error_files = Dir.glob('**/*:*')) and error_files.size > 0
|
|
27
|
+
puts "You may not add a file containg ':' or it will break git for Windows. Remove/rename #{error_files}"
|
|
28
|
+
exit 3
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if true
|
|
32
|
+
system("git status")
|
|
33
|
+
system("git commit --all -m '#{File.basename(__FILE__)}: #{Date.today.to_s} from #{workspace.if.wiki_url.sub(/api.php/i, '')}'")
|
|
34
|
+
system("git status")
|
|
35
|
+
system("git log -1")
|
|
36
|
+
# system("git push")
|
|
37
|
+
end
|
|
38
|
+
workspace.show_missing(true)
|
data/bin/wiki_push
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'elexis/wiki/
|
|
4
|
+
require 'elexis/wiki/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "elexis-wiki-interface"
|
|
8
|
-
spec.version = Elexis::Wiki::
|
|
8
|
+
spec.version = Elexis::Wiki::VERSION
|
|
9
9
|
spec.authors = ["Niklaus Giger"]
|
|
10
10
|
spec.email = ["niklaus.giger@member.fsf.org"]
|
|
11
11
|
spec.summary = "Interface between elexis source and wiki"
|
|
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
spec.add_dependency 'rubyzip', '< 1.0.0'
|
|
21
21
|
spec.add_dependency 'unicode'
|
|
22
|
-
spec.add_dependency 'mediawiki-gateway'
|
|
22
|
+
spec.add_dependency 'mediawiki-gateway' # needed to get pages and infos about pages
|
|
23
|
+
spec.add_dependency 'mediawiki_api' # needed to push images
|
|
23
24
|
spec.add_dependency 'eclipse-plugin', '>= 0.1'
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/history.textile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
h3. Version 0.5.0 (2015-09-18)
|
|
2
|
+
|
|
3
|
+
* Major cleanup, much more spec tests
|
|
4
|
+
* Refactored accessing the Wiki into the new class Interface
|
|
5
|
+
* Using direct json, mediawiki-gateway and mediawiki_api as I found no good gem, which does allow all stuff
|
|
6
|
+
* Requires newer mediawiki (actuall 1.25.2, 1.19 does not work. Unknown how it behaves between)
|
|
7
|
+
* Recognize duplicates in pictures
|
|
8
|
+
* Forces renaming of old convention with '/' or ':' in picture names
|
|
9
|
+
* Added pictures.csv|yml to store information about the seen picture (duplicates, etc)
|
|
10
|
+
|
|
11
|
+
h3. Version 0.4.8 (2015-08-15)
|
|
12
|
+
|
|
13
|
+
* Fails miserably uploading to Mediawiki 1.19
|
|
14
|
+
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
#encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'eclipse/plugin'
|
|
4
|
+
require 'media_wiki'
|
|
5
|
+
require 'mediawiki_api'
|
|
6
|
+
require 'elexis/wiki/images'
|
|
7
|
+
require 'fileutils'
|
|
8
|
+
require 'open-uri'
|
|
9
|
+
require 'time'
|
|
10
|
+
require 'yaml'
|
|
11
|
+
require 'csv'
|
|
12
|
+
|
|
13
|
+
module Elexis
|
|
14
|
+
module Wiki
|
|
15
|
+
ImagePattern = /(\[File:|Datei:|\[Image:)([ \w\.\:\/]*)/i
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# This helper class collect information about all images used in
|
|
19
|
+
# subdirectories doc ending with mediawiki and stores the results
|
|
20
|
+
# in a pictures.yml and a pictures.csv file
|
|
21
|
+
#
|
|
22
|
+
# Several helper allow showing unused pictures, identifying
|
|
23
|
+
# files with same name, but different content and pictures use
|
|
24
|
+
# in several sub-directories
|
|
25
|
+
#
|
|
26
|
+
class Images
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
def write_yml_and_csv
|
|
30
|
+
File.open(@yml, 'w+') {|f| f.puts @pictures.to_yaml}
|
|
31
|
+
column_header = ["sha256","name","project","path"]
|
|
32
|
+
CSV.open(csv, 'w+',
|
|
33
|
+
:write_headers=> true,
|
|
34
|
+
:headers => column_header
|
|
35
|
+
) do |csv|
|
|
36
|
+
csv << ["# Generated by: #{File.basename(__FILE__)} at #{Time.now.utc}"]
|
|
37
|
+
@pictures.each{ |pict| csv << pict.values.to_a }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
def initialize_database
|
|
41
|
+
savedDir = Dir.pwd
|
|
42
|
+
Dir.chdir(@rootDir)
|
|
43
|
+
@docs = Dir.glob('**/doc').reject{|x| x.match(/(^vendor|\/vendor)\//) } # doc_fr is mostly a duplicate of doc_de
|
|
44
|
+
@docs.each{
|
|
45
|
+
|doc_dir|
|
|
46
|
+
pngs = Dir.glob("#{doc_dir}/**/*.{png,jpg}")
|
|
47
|
+
puts "#{doc_dir} has #{pngs.size} png" if $VERBOSE
|
|
48
|
+
next if pngs.size == 0
|
|
49
|
+
pngs.each {
|
|
50
|
+
|png|
|
|
51
|
+
sha256 = Digest::SHA256.hexdigest(IO.read(png))
|
|
52
|
+
pict = { :sha256 => sha256,
|
|
53
|
+
:name => File.basename(png),
|
|
54
|
+
:project => File.basename(File.dirname(File.dirname(png))),
|
|
55
|
+
:path => png}
|
|
56
|
+
@pictures << pict
|
|
57
|
+
}
|
|
58
|
+
# break if pngs.size > 1
|
|
59
|
+
}
|
|
60
|
+
@sha_2_png = {}
|
|
61
|
+
@pictures.each {
|
|
62
|
+
|picture|
|
|
63
|
+
if @sha_2_png[picture[:sha256]]
|
|
64
|
+
@sha_2_png[picture[:sha256]] << picture
|
|
65
|
+
else
|
|
66
|
+
@sha_2_png[picture[:sha256]] = [picture]
|
|
67
|
+
end
|
|
68
|
+
}
|
|
69
|
+
@duplicates = @sha_2_png.find_all{|sha, list| list.size > 1}
|
|
70
|
+
write_yml_and_csv
|
|
71
|
+
ensure
|
|
72
|
+
Dir.chdir(savedDir)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def verify_best_name(picture)
|
|
76
|
+
if picture[:best_name]
|
|
77
|
+
wrong_best_name = @pictures.find_all{|x| x[:best_name] == picture[:best_name] and x[:sha256] != picture[:sha256]}
|
|
78
|
+
if wrong_best_name.size > 0
|
|
79
|
+
puts " #{wrong_best_name.size} entries #{wrong_best_name}" #if $VERBOSE
|
|
80
|
+
@wrong_best_name << [picture[:path], wrong_best_name.collect{|x| x[:path]} ]
|
|
81
|
+
new_name = get_name_with_project(picture[:path])
|
|
82
|
+
if picture[:best_name] != new_name
|
|
83
|
+
puts "new_best_name 2 is #{new_name} for #{picture[:path]}" #if $VERBOSE
|
|
84
|
+
picture[:rule] += " name get_name_with_project"
|
|
85
|
+
picture[:best_name] = new_name
|
|
86
|
+
else
|
|
87
|
+
@@uniq_id ||= 0
|
|
88
|
+
new_name = '27'
|
|
89
|
+
begin
|
|
90
|
+
@@uniq_id += 1
|
|
91
|
+
new_name = File.dirname(picture[:path]) + "/#{@@uniq_id}_" + picture[:name]
|
|
92
|
+
end until File.exist?(new_name).eql?(false)
|
|
93
|
+
puts "new_best_name 3 is #{new_name} for #{picture[:path]}" # if $VERBOSE
|
|
94
|
+
picture[:rule] += " third #{new_name}"
|
|
95
|
+
picture[:best_name] = File.basename(new_name)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def set_best_name(picture)
|
|
102
|
+
debug = $VERBOSE
|
|
103
|
+
path = picture[:path]
|
|
104
|
+
sha256 = Digest::SHA256.hexdigest(IO.read(path))
|
|
105
|
+
same_sha256 = @pictures.find_all{|x| x[:sha256] == sha256}
|
|
106
|
+
same_name = @pictures.find_all{|x| x[:name] == picture[:name]}
|
|
107
|
+
nrSha256 = same_name.collect{|c| get_small_name(c[:sha256])}.uniq
|
|
108
|
+
if same_sha256.size == 1 and nrSha256.size == 1
|
|
109
|
+
puts "new_best_name 3 @short_and_sha_okay #{sha256} for #{path}" if debug
|
|
110
|
+
picture[:rule] = 'short_and_sha_okay nr_single_sha'
|
|
111
|
+
@short_and_sha_okay << path
|
|
112
|
+
@nr_single_sha << same_sha256
|
|
113
|
+
picture[:best_name] = get_small_name(path)
|
|
114
|
+
return
|
|
115
|
+
else
|
|
116
|
+
msg = " nrSha #{sha256.size} #{sha256}"
|
|
117
|
+
if same_sha256.collect{|c| c[:name]}.uniq.size == 1 and nrSha256.size == 1
|
|
118
|
+
puts "@short_and_sha_okay #{path} sha256 #{sha256} for #{same_sha256.size} files" if debug
|
|
119
|
+
picture[:rule] = 'short_and_sha_okay'
|
|
120
|
+
@short_and_sha_okay << path
|
|
121
|
+
return
|
|
122
|
+
end
|
|
123
|
+
found = same_sha256.collect{|c| c[:name].downcase}.uniq
|
|
124
|
+
if found.size == 1 and nrSha256.size == 1
|
|
125
|
+
puts "new_best_name 4 case_sensitives #{found}" if debug
|
|
126
|
+
picture[:rule] = 'case_sensitives'
|
|
127
|
+
picture[:best_name] = get_small_name(path)
|
|
128
|
+
return
|
|
129
|
+
end
|
|
130
|
+
multiple = same_sha256.collect{|c| c[:name]}.uniq
|
|
131
|
+
to_reduce = same_sha256.collect{|c| get_small_name(c[:name])}.uniq
|
|
132
|
+
if nrSha256.size == 1
|
|
133
|
+
@to_short_names[path] = to_reduce
|
|
134
|
+
puts "new_best_name 5 to_short_names #{multiple} => #{to_reduce} nrSha #{sha256.size} #{sha256}" if debug
|
|
135
|
+
picture[:rule] = 'to_short_names'
|
|
136
|
+
picture[:best_name] = get_small_name(path)
|
|
137
|
+
return
|
|
138
|
+
end
|
|
139
|
+
puts "new_best_name 6 multiple #{multiple} to_reduce #{to_reduce} #{get_name_with_project(picture[:path])}" if debug
|
|
140
|
+
@multiple_names[path] = same_sha256
|
|
141
|
+
picture[:best_name] = get_name_with_project(picture[:path])
|
|
142
|
+
picture[:rule] = 'multiple_names'
|
|
143
|
+
return
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
public
|
|
147
|
+
attr_reader :rootDir, :docDir, :extension, :yml, :csv, :pictures, :sha_2_png,
|
|
148
|
+
:multiple_names, :to_short_names, :nr_single_sha,
|
|
149
|
+
:short_and_sha_okay, :wrong_best_name, :new_best_name,
|
|
150
|
+
:duplicates, :dup_non_identical, :actions
|
|
151
|
+
|
|
152
|
+
def initialize(rootDir = Dir.pwd, docDir = 'doc', extension = '.mediawiki')
|
|
153
|
+
@rootDir = rootDir
|
|
154
|
+
@docDir = docDir
|
|
155
|
+
@extension = extension
|
|
156
|
+
@add_changes_to_git = false
|
|
157
|
+
@pictures = []
|
|
158
|
+
@multiple_names = {}
|
|
159
|
+
@to_short_names = {}
|
|
160
|
+
@nr_single_sha = []
|
|
161
|
+
@short_and_sha_okay = []
|
|
162
|
+
@wrong_best_name = []
|
|
163
|
+
@new_best_name = {}
|
|
164
|
+
@yml = File.expand_path(File.join(@rootDir, 'pictures.yml'))
|
|
165
|
+
@csv = File.expand_path(File.join(@rootDir, 'pictures.csv'))
|
|
166
|
+
initialize_database
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def get_name_with_project(path)
|
|
170
|
+
dir = File.dirname(path)
|
|
171
|
+
found = dir.sub(/(\.feature|[._]test.*|)\/doc/i, '').sub(/\.v\d$/, '')
|
|
172
|
+
result = (found.split('.')[-1] + '-' + File.basename(path)).downcase.gsub(':', '-')
|
|
173
|
+
result
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def get_small_name(path)
|
|
177
|
+
ext = File.extname(path)
|
|
178
|
+
to_consider = File.basename(path, ext).gsub(':','-')
|
|
179
|
+
if to_consider.index('.')
|
|
180
|
+
part = to_consider.split('.')[-1].downcase
|
|
181
|
+
if part.split('_').size > 1
|
|
182
|
+
result = part.split('_')[1..-1].join('_')
|
|
183
|
+
else
|
|
184
|
+
result = part
|
|
185
|
+
end
|
|
186
|
+
else
|
|
187
|
+
result = to_consider
|
|
188
|
+
end
|
|
189
|
+
(result + ext).downcase
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def determine_cleanup
|
|
193
|
+
savedDir = Dir.pwd
|
|
194
|
+
Dir.chdir(@rootDir)
|
|
195
|
+
@pictures.each{ |picture| set_best_name(picture) }
|
|
196
|
+
@pictures.each{ |picture| verify_best_name(picture) }
|
|
197
|
+
@wrong_best_name = []
|
|
198
|
+
@pictures.each{ |picture| verify_best_name(picture) }
|
|
199
|
+
@dup_non_identical = @pictures.collect{ |p| p[:path] if p[:rule] =~ /multiple/}.compact
|
|
200
|
+
@pictures.find{ |outer| @pictures.find_all{ |inner| inner[:name].eql?(outer[:name]) and not inner[:sha256].eql?(outer[:sha256])}.size > 1 }
|
|
201
|
+
@new_best_name = @pictures.find_all{ |picture| picture[:best_name] and not picture[:best_name].downcase.eql?(picture[:name].downcase) }
|
|
202
|
+
write_yml_and_csv
|
|
203
|
+
ensure
|
|
204
|
+
Dir.chdir(savedDir)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def remove_obsolete_symlinks
|
|
208
|
+
@docs.each do
|
|
209
|
+
|docDir|
|
|
210
|
+
Dir.chdir(File.join(@rootDir, docDir))
|
|
211
|
+
project = File.basename(File.dirname(docDir))
|
|
212
|
+
tries = [project, project.capitalize, project.sub('.feature', ''), project.sub('.feature', '').capitalize]
|
|
213
|
+
files = []
|
|
214
|
+
tries.each{|try| files << try if File.symlink?(try) }
|
|
215
|
+
files.compact.each do
|
|
216
|
+
|symlink|
|
|
217
|
+
if symlink and File.symlink?(symlink)
|
|
218
|
+
cmd = "rm #{symlink}"
|
|
219
|
+
@actions << cmd
|
|
220
|
+
FileUtils.rm_f(symlink, :verbose => true)
|
|
221
|
+
run_git_cmd("git rm -f --ignore-unmatch #{symlink}") if @add_changes_to_git
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def remove_files_with_case_sensitive_changes(file_correct_case)
|
|
228
|
+
files = Dir.glob(file_correct_case + '*', File::FNM_CASEFOLD)
|
|
229
|
+
return if files.size == 1
|
|
230
|
+
files.each{
|
|
231
|
+
|file|
|
|
232
|
+
next if File.basename(file).eql?(File.basename(file_correct_case))
|
|
233
|
+
if @add_changes_to_git
|
|
234
|
+
run_git_cmd("git rm -f #{file}")
|
|
235
|
+
else
|
|
236
|
+
FileUtils.rm_f(file)
|
|
237
|
+
end
|
|
238
|
+
}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def run_git_cmd(git_cmd)
|
|
242
|
+
return unless @add_changes_to_git
|
|
243
|
+
res = system(git_cmd)
|
|
244
|
+
unless res
|
|
245
|
+
binding.pry
|
|
246
|
+
raise "Running #{git_cmd} failed"
|
|
247
|
+
end
|
|
248
|
+
@actions << git_cmd
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def execute_cleanup(add_changes_to_git=false)
|
|
252
|
+
@add_changes_to_git = add_changes_to_git
|
|
253
|
+
@actions ||= []
|
|
254
|
+
savedDir = Dir.pwd
|
|
255
|
+
remove_obsolete_symlinks
|
|
256
|
+
Dir.chdir(@rootDir)
|
|
257
|
+
cmds = []
|
|
258
|
+
@new_best_name.each{
|
|
259
|
+
|picture|
|
|
260
|
+
dir_name = File.dirname(picture[:path])
|
|
261
|
+
Dir.chdir(File.join(@rootDir, dir_name))
|
|
262
|
+
Dir.glob("*#{extension}").each do
|
|
263
|
+
|wiki_file|
|
|
264
|
+
old_image_name = picture[:name]
|
|
265
|
+
new_image_name = picture[:best_name]
|
|
266
|
+
if old_image_name.index('-')
|
|
267
|
+
puts "Skipping mv #{old_image_name} #{new_image_name}"
|
|
268
|
+
next
|
|
269
|
+
end
|
|
270
|
+
cmd = "change_image_name_in_mediawiki #{wiki_file} #{picture[:name]} #{picture[:best_name]}"
|
|
271
|
+
# cmd = 'change_image_name_in_mediawiki test.mediawiki ch.elexis.icpc_icpc1.png icpc1.png'
|
|
272
|
+
change_image_name_in_mediawiki wiki_file, old_image_name, new_image_name
|
|
273
|
+
@actions << cmd
|
|
274
|
+
oldFiles = Dir.glob(old_image_name, File::FNM_CASEFOLD)
|
|
275
|
+
oldFiles.each{ |old_file|
|
|
276
|
+
if @add_changes_to_git
|
|
277
|
+
run_git_cmd("git rm -f --ignore-unmatch #{old_file}") if File.exist?(old_file)
|
|
278
|
+
else
|
|
279
|
+
FileUtils.rm_f(old_file, :verbose => true)
|
|
280
|
+
@actions << "rm -f #{old_file}"
|
|
281
|
+
end
|
|
282
|
+
}
|
|
283
|
+
end
|
|
284
|
+
}
|
|
285
|
+
Dir.chdir(@rootDir)
|
|
286
|
+
# Add all pictures which were downloaded and still have the same name
|
|
287
|
+
@pictures.each { |picture| run_git_cmd("git add -f #{picture[:path]}") if File.exist?(picture[:path]) }
|
|
288
|
+
@actions.uniq!
|
|
289
|
+
puts @actions.join("\n")
|
|
290
|
+
ensure
|
|
291
|
+
Dir.chdir(savedDir)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Helper for scripts
|
|
295
|
+
# We assume that the referenced new_image_name is living in the same directory
|
|
296
|
+
# as the mediawiki_file
|
|
297
|
+
def change_image_name_in_mediawiki(mediawiki_file, old_image_name, new_image_name)
|
|
298
|
+
if new_image_name.downcase != File.basename(new_image_name).downcase
|
|
299
|
+
raise "new_image_name #{new_image_name} may not contain a directory path"
|
|
300
|
+
end
|
|
301
|
+
if @add_changes_to_git
|
|
302
|
+
run_git_cmd("git add #{old_image_name} && git mv #{old_image_name} #{new_image_name}")
|
|
303
|
+
elsif @actions
|
|
304
|
+
@actions << "mv #{old_image_name} #{new_image_name}"
|
|
305
|
+
FileUtils.mv(old_image_name, new_image_name, :verbose => true)
|
|
306
|
+
end unless File.exists?(new_image_name)
|
|
307
|
+
puts "change_image_name_in_mediawiki #{Dir.pwd}/#{mediawiki_file}: #{old_image_name.inspect} => #{new_image_name.inspect}" # if $VERBOSE
|
|
308
|
+
newLines = []
|
|
309
|
+
lines = IO.readlines(mediawiki_file)
|
|
310
|
+
lines.each{
|
|
311
|
+
|line|
|
|
312
|
+
unless m = ImagePattern.match(line)
|
|
313
|
+
newLines << line
|
|
314
|
+
else
|
|
315
|
+
unless old_image_name.downcase.eql?(m[2].downcase) or /\/#{old_image_name}/i.match(m[2])
|
|
316
|
+
puts "change_image_name_in_mediawiki #{__LINE__} skip #{m}" if $VERBOSE
|
|
317
|
+
newLines << line
|
|
318
|
+
else
|
|
319
|
+
dirName = File.dirname(mediawiki_file)
|
|
320
|
+
simpleName = File.join(dirName, File.basename(new_image_name))
|
|
321
|
+
if files = Dir.glob(simpleName, File::FNM_CASEFOLD) and files.size >= 1
|
|
322
|
+
# if files = (Dir.glob(simpleName, File::FNM_CASEFOLD) +Dir.glob(old_image_name, File::FNM_CASEFOLD)) and files.size >= 1
|
|
323
|
+
new_line = line.sub(m[2], new_image_name)
|
|
324
|
+
puts "change_image_name_in_mediawiki #{__LINE__} #{line} aus #{m[2]} mit #{new_image_name}" if $VERBOSE
|
|
325
|
+
newLines << new_line
|
|
326
|
+
else
|
|
327
|
+
msg = "#{__LINE__} Could not find image for #{m[0]} searched for #{simpleName} in #{Dir.pwd}. files are #{files}"
|
|
328
|
+
raise msg
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
}
|
|
333
|
+
File.open(mediawiki_file, "w") {|f| f.write newLines.join.gsub(/\[\[Datei:|\[\[Image:/i, '[[File:')}
|
|
334
|
+
run_git_cmd("git add #{mediawiki_file}")
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
end
|