xlo 0.0.1.5 → 0.0.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/README.md +1 -1
- data/lib/xlo.rb +68 -48
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6093051b78a35019ac0deee5d6449e904ed31492
|
4
|
+
data.tar.gz: afbc066cc514e55264cf96cc94bed301f32ea750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a42f4edc4bffab04157da99caed215ea573dda51d450d2ecfeec2f5b753ac3dd41f4a5d42ed1cbcdfd2e614d29e05bce6b06066b1314743dcda07d55c597b9
|
7
|
+
data.tar.gz: a392d6dfdcd481cbac3c6261c0b2947b8b4fe8803f69f55cd9214562b828a4dac440ba7069e581c687a3c5588bc0ea33a0f3a5cd24cd4f84ff46726aad634d3c
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ XLO is a rnv/xmllint wrapper who captures the error generate by this validators
|
|
10
10
|
1. `gem install xlo`
|
11
11
|
2. `apt-get install rnv`
|
12
12
|
3. `apt-get install xmllint`
|
13
|
-
4. `xlo rnc-schema xml-folder`
|
13
|
+
4. `xlo start rnc-schema xml-folder`
|
14
14
|
|
15
15
|
## Note
|
16
16
|
the code contains several functions who could be use to like a ruby api
|
data/lib/xlo.rb
CHANGED
@@ -1,28 +1,38 @@
|
|
1
|
+
require 'os'
|
1
2
|
require 'open3'
|
2
3
|
|
3
4
|
class Xlo
|
4
5
|
attr_accessor :rnv, :xmllint, :csv
|
5
6
|
|
6
|
-
def initialize(
|
7
|
+
def initialize(*args)
|
7
8
|
@rnv = []
|
8
9
|
@xmllint = []
|
9
|
-
|
10
|
-
|
10
|
+
|
11
|
+
if args.size == 1
|
12
|
+
@csv = File.new(args[0],"w+")
|
13
|
+
@csv << "type; error; freq; files \n"
|
14
|
+
end
|
15
|
+
|
11
16
|
@error = {}
|
17
|
+
@mutex = Mutex.new
|
12
18
|
end
|
13
19
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
def get_error
|
21
|
+
return @error
|
22
|
+
end
|
23
|
+
|
24
|
+
def rnv_wrapper (_rnc, _file)
|
25
|
+
rnv = []
|
26
|
+
stdout = Open3.capture3("rnv #{_rnc} #{_file}")
|
27
|
+
stdout = stdout[1].split("\n")
|
28
|
+
stdout.each do |line|
|
29
|
+
rnv << line
|
21
30
|
end
|
31
|
+
return rnv
|
22
32
|
end
|
23
33
|
|
24
|
-
def rnv_aggregate
|
25
|
-
|
34
|
+
def rnv_aggregate(_rnv)
|
35
|
+
_rnv.each do |el|
|
26
36
|
if (el.include?("error") && !el.include?("are invalid"))
|
27
37
|
|
28
38
|
type = el.split("error")[1].split(" ")[1]
|
@@ -37,64 +47,74 @@ class Xlo
|
|
37
47
|
filename = File.basename(el.split("error")[0])
|
38
48
|
filename[filename.length - 2] = ""
|
39
49
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
@mutex.synchronize do
|
51
|
+
if (@error.has_key?(key))
|
52
|
+
@error[key] << " || " + filename
|
53
|
+
else
|
54
|
+
@error[key] = filename
|
55
|
+
end
|
45
56
|
end
|
46
|
-
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
def xmllint_wrapper (
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
61
|
+
def xmllint_wrapper (_file)
|
62
|
+
xmllint = []
|
63
|
+
stdout = Open3.capture3("xmllint #{_file}")
|
64
|
+
stdout = stdout[1].split("\n")
|
65
|
+
stdout.each do |line|
|
66
|
+
xmllint << line
|
58
67
|
end
|
68
|
+
return xmllint
|
59
69
|
end
|
60
70
|
|
61
|
-
def xmllint_aggregate
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@xmllint.each do |el|
|
71
|
+
def xmllint_aggregate(_xmllint)
|
72
|
+
_xmllint.delete_if {|el| el.include?("^")}
|
73
|
+
_xmllint.map { |e| e.chomp }
|
74
|
+
_xmllint = _xmllint.values_at(* _xmllint.each_index.select {|i| i.even?})
|
75
|
+
_xmllint.each do |el|
|
67
76
|
split_el = el.split(" ")
|
68
77
|
type = el[/element|attribute|parser error/]
|
69
78
|
key = type + ";" + el.split(":")[-1]
|
70
79
|
filename = File.basename(split_el[0])[0..-2]
|
71
|
-
|
72
|
-
@error
|
73
|
-
|
74
|
-
|
80
|
+
@mutex.synchronize do
|
81
|
+
if (@error.has_key?(key))
|
82
|
+
@error[key] << " || " + filename
|
83
|
+
else
|
84
|
+
@error[key] = filename
|
85
|
+
end
|
75
86
|
end
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
79
90
|
def csv_writer
|
80
91
|
@error.each do |entry|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
92
|
+
line = entry.dup
|
93
|
+
line[-1] = line[-1].split("||")[0..50].join
|
94
|
+
freq = entry[1].split("||").length
|
95
|
+
@csv.write(line.insert(1, freq.to_s).join(";")[0..-2] + "\n" )
|
96
|
+
end
|
86
97
|
end
|
87
98
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
xlo.rnv_wrapper(_rnv_arg, _folder_arg)
|
93
|
-
xlo.rnv_aggregate
|
99
|
+
def run(_rnv_arg, _folder_arg, _pool_size = 1)
|
100
|
+
jobs = Queue.new
|
101
|
+
Dir[_folder_arg + "/" + "*.xml"].each {|f| jobs.push f}
|
94
102
|
|
95
|
-
|
96
|
-
|
103
|
+
workers = (_pool_size).times.map do
|
104
|
+
Thread.new do
|
105
|
+
while jobs.size != 0
|
106
|
+
file = jobs.pop
|
107
|
+
rnv_aggregate(rnv_wrapper(_rnv_arg,file))
|
108
|
+
xmllint_aggregate(xmllint_wrapper(file))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
workers.map(&:join)
|
113
|
+
end
|
97
114
|
|
115
|
+
def self.main(_rnv_arg,_folder_arg)
|
116
|
+
xlo = Xlo.new("error.csv")
|
117
|
+
xlo.run(_rnv_arg, _folder_arg, OS.cpu_count)
|
98
118
|
xlo.csv_writer
|
99
119
|
end
|
100
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Meoni
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: facter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.4.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.4.6
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: thor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|