dim-toolkit 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dim +9 -9
- data/lib/dim/commands/check.rb +13 -13
- data/lib/dim/commands/export.rb +145 -145
- data/lib/dim/commands/format.rb +196 -198
- data/lib/dim/commands/stats.rb +64 -64
- data/lib/dim/consistency.rb +157 -187
- data/lib/dim/dimmain.rb +28 -28
- data/lib/dim/encoding.rb +4 -4
- data/lib/dim/exit_helper.rb +23 -23
- data/lib/dim/exporter/csv.rb +24 -25
- data/lib/dim/exporter/exporterInterface.rb +37 -37
- data/lib/dim/exporter/json.rb +30 -32
- data/lib/dim/exporter/rst.rb +142 -142
- data/lib/dim/ext/psych.rb +63 -63
- data/lib/dim/ext/string.rb +85 -85
- data/lib/dim/globals.rb +12 -12
- data/lib/dim/helpers/attribute_helper.rb +126 -126
- data/lib/dim/helpers/file_helper.rb +25 -25
- data/lib/dim/loader.rb +561 -581
- data/lib/dim/options.rb +116 -116
- data/lib/dim/requirement.rb +217 -236
- data/lib/dim/ver.rb +7 -7
- data/lib/dim.rb +1 -1
- data/license.txt +205 -205
- data/version.txt +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173d098fa605d123b8d4f71c3adaf3069d48e71da75559fc3811ea040391e7fc
|
4
|
+
data.tar.gz: 1cd97eee8d5b3b72dbb8d82c33ea8fc358c4de5980c02fe2d924df8eeb6accb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d60ecd8de45760335f9ad22d5b202f43c886779a055d4f0891a6d4c523feaaa90c5a2284526be4ceb976bb6aa6d7937cd8bdd261307d23416b1232c41d2cfee8
|
7
|
+
data.tar.gz: f7a8ed3879a70f40462ae619835c25757f1f0de60c84a4e95c4e22be72d5a489a8f182ccf825f8bea2cf0687fda0cd740b3da38e661c1e1734f48ad11870e761
|
data/bin/dim
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
|
4
|
-
|
5
|
-
require 'dim/encoding'
|
6
|
-
require 'dim/ver'
|
7
|
-
require 'dim'
|
8
|
-
|
9
|
-
Dim.main
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
|
4
|
+
|
5
|
+
require 'dim/encoding'
|
6
|
+
require 'dim/ver'
|
7
|
+
require 'dim'
|
8
|
+
|
9
|
+
Dim.main
|
data/lib/dim/commands/check.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require_relative '../globals'
|
2
|
-
|
3
|
-
module Dim
|
4
|
-
class Check
|
5
|
-
SUBCOMMANDS['check'] = self
|
6
|
-
|
7
|
-
def initialize(_loader); end
|
8
|
-
|
9
|
-
def execute(silent: true)
|
10
|
-
# checks are always done after loading, so this is just a placeholder for command line option
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require_relative '../globals'
|
2
|
+
|
3
|
+
module Dim
|
4
|
+
class Check
|
5
|
+
SUBCOMMANDS['check'] = self
|
6
|
+
|
7
|
+
def initialize(_loader); end
|
8
|
+
|
9
|
+
def execute(silent: true)
|
10
|
+
# checks are always done after loading, so this is just a placeholder for command line option
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/dim/commands/export.rb
CHANGED
@@ -1,145 +1,145 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'digest'
|
3
|
-
|
4
|
-
require_relative '../globals'
|
5
|
-
require_relative '../exporter/exporterInterface'
|
6
|
-
require_relative '../exporter/rst'
|
7
|
-
require_relative '../exporter/csv'
|
8
|
-
require_relative '../exporter/json'
|
9
|
-
require_relative 'check'
|
10
|
-
|
11
|
-
module Dim
|
12
|
-
class Export
|
13
|
-
SUBCOMMANDS['export'] = self
|
14
|
-
|
15
|
-
attr_accessor :file_list, :export_dir
|
16
|
-
|
17
|
-
def initialize(loader)
|
18
|
-
@loader = loader
|
19
|
-
@file_list = []
|
20
|
-
@export_dir = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def execute(silent: true)
|
24
|
-
@silent = silent
|
25
|
-
@loader.filter(OPTIONS[:filter]) unless OPTIONS[:filter].empty?
|
26
|
-
|
27
|
-
puts 'Exporting...' unless @silent
|
28
|
-
export
|
29
|
-
clean_destination
|
30
|
-
puts 'Done.' unless @silent
|
31
|
-
end
|
32
|
-
|
33
|
-
def copy_files(mod)
|
34
|
-
@loader.module_data[mod][:files].each do |f, list|
|
35
|
-
d = File.dirname(f)
|
36
|
-
|
37
|
-
list.uniq.each do |l|
|
38
|
-
src_pattern = File.join(d, l)
|
39
|
-
Dir.glob(src_pattern).each do |src|
|
40
|
-
src = Pathname.new(src).cleanpath.to_s
|
41
|
-
dst = File.join(OPTIONS[:folder], mod.sanitize, Pathname.new(src).relative_path_from(Pathname(d)))
|
42
|
-
@file_list << dst
|
43
|
-
FileUtils.mkdir_p(File.dirname(dst))
|
44
|
-
|
45
|
-
if File.exist?(dst)
|
46
|
-
md5_src = Digest::MD5.file(src)
|
47
|
-
md5_dst = Digest::MD5.file(dst)
|
48
|
-
next if md5_src == md5_dst
|
49
|
-
end
|
50
|
-
|
51
|
-
puts "Copying #{src} to #{dst}..." unless @silent
|
52
|
-
FileUtils.cp_r(src, dst)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def write_content(filename, content)
|
59
|
-
old_content = (File.exist?(filename) ? File.read(filename) : nil)
|
60
|
-
if content != old_content
|
61
|
-
File.write(filename, content)
|
62
|
-
puts ' done' unless @silent
|
63
|
-
else
|
64
|
-
puts ' skipped' unless @silent
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_index(requirements_by_module)
|
69
|
-
return unless @exporter.hasIndex
|
70
|
-
|
71
|
-
files = {}
|
72
|
-
@loader.module_data.each do |mod, data|
|
73
|
-
next if requirements_by_module[mod].empty?
|
74
|
-
|
75
|
-
c = data[:category]
|
76
|
-
o = data[:origin]
|
77
|
-
files[c] ||= {}
|
78
|
-
files[c][o] ||= []
|
79
|
-
files[c][o] << mod
|
80
|
-
end
|
81
|
-
ind = 0
|
82
|
-
files.each do |category, data|
|
83
|
-
data.each do |origin, modules|
|
84
|
-
ind += 1
|
85
|
-
filename = "index_#{format('%03d', ind)}_#{category.downcase}_#{origin.downcase.sanitize}"
|
86
|
-
filepath = "#{OPTIONS[:folder]}/#{filename}.#{OPTIONS[:type]}"
|
87
|
-
file_list << filepath
|
88
|
-
new_content = StringIO.new
|
89
|
-
print "Creating #{filepath}..." unless @silent
|
90
|
-
@exporter.index(new_content, category, origin, modules)
|
91
|
-
write_content(filepath, new_content.string)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def export
|
97
|
-
requirements_by_module = {}
|
98
|
-
module_keys = @loader.module_data.keys
|
99
|
-
module_keys.each { |um| requirements_by_module[um] = [] }
|
100
|
-
@loader.requirements.each { |_id, r| requirements_by_module[r.document] << r }
|
101
|
-
|
102
|
-
@exporter = EXPORTER[OPTIONS[:type]].new(@loader)
|
103
|
-
requirements_by_module.each do |doc, reqs|
|
104
|
-
next if reqs.empty?
|
105
|
-
|
106
|
-
@export_dir = File.join(OPTIONS[:folder])
|
107
|
-
filename = File.join(export_dir, doc.sanitize, "Requirements.#{OPTIONS[:type]}")
|
108
|
-
file_list << filename
|
109
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
110
|
-
copy_files(doc)
|
111
|
-
|
112
|
-
new_content = StringIO.new
|
113
|
-
print "Creating #{filename}..." unless @silent
|
114
|
-
@exporter.header(new_content)
|
115
|
-
@exporter.document(new_content, doc)
|
116
|
-
meta = @loader.metadata[doc]
|
117
|
-
@exporter.metadata(new_content, meta) if meta != ''
|
118
|
-
reqs.each do |r|
|
119
|
-
@exporter.requirement(new_content, r)
|
120
|
-
end
|
121
|
-
@exporter.footer(new_content)
|
122
|
-
write_content(filename, new_content.string)
|
123
|
-
end
|
124
|
-
|
125
|
-
create_index(requirements_by_module)
|
126
|
-
end
|
127
|
-
|
128
|
-
def clean_destination(dir_path = export_dir)
|
129
|
-
Dir.new(dir_path).children.each do |file|
|
130
|
-
dst = File.join(dir_path, file)
|
131
|
-
path = Pathname.new(dst)
|
132
|
-
|
133
|
-
clean_destination(dst) if path.directory?
|
134
|
-
|
135
|
-
next if file_list.include? dst
|
136
|
-
|
137
|
-
if path.directory?
|
138
|
-
path.rmdir if path.empty?
|
139
|
-
else
|
140
|
-
path.delete
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
1
|
+
require 'pathname'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
require_relative '../globals'
|
5
|
+
require_relative '../exporter/exporterInterface'
|
6
|
+
require_relative '../exporter/rst'
|
7
|
+
require_relative '../exporter/csv'
|
8
|
+
require_relative '../exporter/json'
|
9
|
+
require_relative 'check'
|
10
|
+
|
11
|
+
module Dim
|
12
|
+
class Export
|
13
|
+
SUBCOMMANDS['export'] = self
|
14
|
+
|
15
|
+
attr_accessor :file_list, :export_dir
|
16
|
+
|
17
|
+
def initialize(loader)
|
18
|
+
@loader = loader
|
19
|
+
@file_list = []
|
20
|
+
@export_dir = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(silent: true)
|
24
|
+
@silent = silent
|
25
|
+
@loader.filter(OPTIONS[:filter]) unless OPTIONS[:filter].empty?
|
26
|
+
|
27
|
+
puts 'Exporting...' unless @silent
|
28
|
+
export
|
29
|
+
clean_destination
|
30
|
+
puts 'Done.' unless @silent
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_files(mod)
|
34
|
+
@loader.module_data[mod][:files].each do |f, list|
|
35
|
+
d = File.dirname(f)
|
36
|
+
|
37
|
+
list.uniq.each do |l|
|
38
|
+
src_pattern = File.join(d, l)
|
39
|
+
Dir.glob(src_pattern).each do |src|
|
40
|
+
src = Pathname.new(src).cleanpath.to_s
|
41
|
+
dst = File.join(OPTIONS[:folder], mod.sanitize, Pathname.new(src).relative_path_from(Pathname(d)))
|
42
|
+
@file_list << dst
|
43
|
+
FileUtils.mkdir_p(File.dirname(dst))
|
44
|
+
|
45
|
+
if File.exist?(dst)
|
46
|
+
md5_src = Digest::MD5.file(src)
|
47
|
+
md5_dst = Digest::MD5.file(dst)
|
48
|
+
next if md5_src == md5_dst
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "Copying #{src} to #{dst}..." unless @silent
|
52
|
+
FileUtils.cp_r(src, dst)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def write_content(filename, content)
|
59
|
+
old_content = (File.exist?(filename) ? File.read(filename) : nil)
|
60
|
+
if content != old_content
|
61
|
+
File.write(filename, content)
|
62
|
+
puts ' done' unless @silent
|
63
|
+
else
|
64
|
+
puts ' skipped' unless @silent
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_index(requirements_by_module)
|
69
|
+
return unless @exporter.hasIndex
|
70
|
+
|
71
|
+
files = {}
|
72
|
+
@loader.module_data.each do |mod, data|
|
73
|
+
next if requirements_by_module[mod].empty?
|
74
|
+
|
75
|
+
c = data[:category]
|
76
|
+
o = data[:origin]
|
77
|
+
files[c] ||= {}
|
78
|
+
files[c][o] ||= []
|
79
|
+
files[c][o] << mod
|
80
|
+
end
|
81
|
+
ind = 0
|
82
|
+
files.each do |category, data|
|
83
|
+
data.each do |origin, modules|
|
84
|
+
ind += 1
|
85
|
+
filename = "index_#{format('%03d', ind)}_#{category.downcase}_#{origin.downcase.sanitize}"
|
86
|
+
filepath = "#{OPTIONS[:folder]}/#{filename}.#{OPTIONS[:type]}"
|
87
|
+
file_list << filepath
|
88
|
+
new_content = StringIO.new
|
89
|
+
print "Creating #{filepath}..." unless @silent
|
90
|
+
@exporter.index(new_content, category, origin, modules)
|
91
|
+
write_content(filepath, new_content.string)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def export
|
97
|
+
requirements_by_module = {}
|
98
|
+
module_keys = @loader.module_data.keys
|
99
|
+
module_keys.each { |um| requirements_by_module[um] = [] }
|
100
|
+
@loader.requirements.each { |_id, r| requirements_by_module[r.document] << r }
|
101
|
+
|
102
|
+
@exporter = EXPORTER[OPTIONS[:type]].new(@loader)
|
103
|
+
requirements_by_module.each do |doc, reqs|
|
104
|
+
next if reqs.empty?
|
105
|
+
|
106
|
+
@export_dir = File.join(OPTIONS[:folder])
|
107
|
+
filename = File.join(export_dir, doc.sanitize, "Requirements.#{OPTIONS[:type]}")
|
108
|
+
file_list << filename
|
109
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
110
|
+
copy_files(doc)
|
111
|
+
|
112
|
+
new_content = StringIO.new
|
113
|
+
print "Creating #{filename}..." unless @silent
|
114
|
+
@exporter.header(new_content)
|
115
|
+
@exporter.document(new_content, doc)
|
116
|
+
meta = @loader.metadata[doc]
|
117
|
+
@exporter.metadata(new_content, meta) if meta != ''
|
118
|
+
reqs.each do |r|
|
119
|
+
@exporter.requirement(new_content, r)
|
120
|
+
end
|
121
|
+
@exporter.footer(new_content)
|
122
|
+
write_content(filename, new_content.string)
|
123
|
+
end
|
124
|
+
|
125
|
+
create_index(requirements_by_module)
|
126
|
+
end
|
127
|
+
|
128
|
+
def clean_destination(dir_path = export_dir)
|
129
|
+
Dir.new(dir_path).children.each do |file|
|
130
|
+
dst = File.join(dir_path, file)
|
131
|
+
path = Pathname.new(dst)
|
132
|
+
|
133
|
+
clean_destination(dst) if path.directory?
|
134
|
+
|
135
|
+
next if file_list.include? dst
|
136
|
+
|
137
|
+
if path.directory?
|
138
|
+
path.rmdir if path.empty?
|
139
|
+
else
|
140
|
+
path.delete
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|