dir-to-xml 0.9.5 → 1.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dir-to-xml.rb +88 -24
- metadata +33 -32
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f155b43f7372db3ad7636b3c54f8369d78387d155ec4230f24b2ecf6a6b7d206
|
4
|
+
data.tar.gz: 3def96a9380e89e249275346f39ca5d6eebcbc60996e66c5d2a5786d9a250f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade701a7b673a6305a73f52f10ce05e828588f4d235acc747aa5adb72a7e02a4dd11ac7312f0661ef843a8df9d848943eb8ddac53c954bc4b5176b0838efcfa0
|
7
|
+
data.tar.gz: a542531fdbfe27e2621c7f0db8b034b32528f0aa284e4038c9ee1239655e419a00d9e5e82c98ab5c7e86e634e1cba56677e1186318b8e58598632f08fb8b8af6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dir-to-xml.rb
CHANGED
@@ -2,18 +2,23 @@
|
|
2
2
|
|
3
3
|
# file: dir-to-xml.rb
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'dxlite'
|
6
6
|
|
7
7
|
|
8
8
|
class DirToXML
|
9
9
|
|
10
|
-
attr_reader :dx
|
10
|
+
attr_reader :dx, :activity
|
11
11
|
|
12
|
-
def initialize(x= '.', recursive: false, index: 'dir.xml')
|
13
|
-
|
12
|
+
def initialize(x= '.', recursive: false, index: 'dir.xml', debug: false)
|
13
|
+
|
14
14
|
super()
|
15
15
|
|
16
|
-
|
16
|
+
@debug = debug
|
17
|
+
|
18
|
+
@dx = nil
|
19
|
+
@activity = {new: [], modified: []}
|
20
|
+
|
21
|
+
if x.is_a? DxLite then
|
17
22
|
|
18
23
|
@dx = x
|
19
24
|
@a = @dx.to_a
|
@@ -27,9 +32,30 @@ class DirToXML
|
|
27
32
|
@path, @index, @recursive = path, index, recursive
|
28
33
|
|
29
34
|
raise "Directory not found." unless File.exists? path
|
30
|
-
|
35
|
+
filepath = File.join(path, index)
|
36
|
+
|
37
|
+
|
38
|
+
if File.exists? filepath then
|
39
|
+
|
40
|
+
@dx = DxLite.new(File.join(@path, @index), debug: @debug)
|
41
|
+
|
42
|
+
else
|
43
|
+
|
44
|
+
@dx = DxLite.new('directory[title, file_path, last_modified, ' + \
|
45
|
+
'description]/file(name, type, ext, ctime, mtime, atime, ' + \
|
46
|
+
'description, owner, group, permissions)')
|
47
|
+
|
48
|
+
puts 'before title' if @debug
|
49
|
+
@dx.title = 'Index of ' + File.expand_path(@path)
|
50
|
+
@dx.file_path = File.expand_path(@path)
|
51
|
+
@dx.last_modified = ''
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
puts 'before Dir.glob' if @debug
|
56
|
+
|
31
57
|
a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
|
32
|
-
|
58
|
+
|
33
59
|
a.delete index
|
34
60
|
|
35
61
|
a2 = a.inject([]) do |r, filename|
|
@@ -50,10 +76,54 @@ class DirToXML
|
|
50
76
|
end
|
51
77
|
|
52
78
|
end
|
79
|
+
|
80
|
+
# has the directory been modified since last time?
|
81
|
+
#
|
82
|
+
if @dx and @dx.respond_to? :last_modified and \
|
83
|
+
@dx.last_modified.length > 0 then
|
84
|
+
|
85
|
+
puts 'nothing to do' if @debug
|
86
|
+
|
87
|
+
file = a2.max_by {|x| x[:mtime]}
|
88
|
+
puts 'file: ' + file.inspect if @debug
|
89
|
+
return if Time.parse(@dx.last_modified) >= (file[:mtime])
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
if @dx and @dx.respond_to? :last_modified then
|
96
|
+
|
97
|
+
if @dx.last_modified.length > 0 then
|
98
|
+
|
99
|
+
t = Time.parse(@dx.last_modified)
|
100
|
+
|
101
|
+
# find the most recently modified cur_files
|
102
|
+
recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
|
103
|
+
- %w(dir.xml dir.json)
|
104
|
+
|
105
|
+
# is it a new file or recently modified?
|
106
|
+
new_files = recent - @dx.to_a.map {|x| x[:name]}
|
107
|
+
modified = recent - new_files
|
108
|
+
|
109
|
+
else
|
110
|
+
|
111
|
+
new_files = a2.select {|x| x[:type] == 'file'}.map {|x| x[:name]}
|
112
|
+
modified = []
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
@activity = {modified: modified, new: new_files}
|
117
|
+
|
118
|
+
end
|
119
|
+
|
53
120
|
|
54
121
|
command = File.exists?(File.join(path, index)) ? :refresh : :dxify
|
55
122
|
|
56
|
-
|
123
|
+
self.method(command).call a2
|
124
|
+
puts '@dx: ' + @dx.inspect if @debug
|
125
|
+
puts '@dx.last_modified: ' + @dx.last_modified.inspect if @debug
|
126
|
+
|
57
127
|
|
58
128
|
@a = @dx.to_a
|
59
129
|
|
@@ -122,7 +192,7 @@ class DirToXML
|
|
122
192
|
@object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
|
123
193
|
return if @object.empty?
|
124
194
|
|
125
|
-
dx =
|
195
|
+
dx = DxLite.new
|
126
196
|
dx.import @object
|
127
197
|
dtx = DirToXML.new(dx)
|
128
198
|
block_given? ? dtx.dx.all.map(&:name).each(&blk) : dtx
|
@@ -162,31 +232,25 @@ class DirToXML
|
|
162
232
|
|
163
233
|
def dxify(a)
|
164
234
|
|
165
|
-
dx =
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
dx.title = 'Index of ' + File.expand_path(@path)
|
170
|
-
dx.file_path = File.expand_path(@path)
|
171
|
-
|
172
|
-
dx.import a
|
173
|
-
|
174
|
-
dx.save File.join(@path, @index)
|
175
|
-
|
176
|
-
return dx
|
235
|
+
@dx.last_modified = Time.now.to_s
|
236
|
+
@dx.import a
|
237
|
+
@dx.save File.join(@path, @index)
|
177
238
|
|
178
239
|
end
|
179
240
|
|
180
241
|
def refresh(cur_files)
|
181
242
|
|
182
|
-
|
243
|
+
puts 'inside refresh' if @debug
|
183
244
|
|
184
|
-
prev_files = dx.to_a
|
245
|
+
prev_files = @dx.to_a
|
246
|
+
|
247
|
+
#puts 'prev_files: ' + prev_files.inspect
|
248
|
+
#puts 'cur_files: ' + cur_files.inspect
|
185
249
|
|
186
250
|
cur_files.each do |x|
|
187
251
|
|
188
252
|
file = prev_files.find {|item| item[:name] == x[:name] }
|
189
|
-
|
253
|
+
#puts 'found : ' + file.inspect if @debug
|
190
254
|
x[:description] = file[:description] if file and file[:description]
|
191
255
|
end
|
192
256
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir-to-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,54 +11,54 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwMTIzMTgwNTQ4WhcN
|
15
|
+
MjIwMTIzMTgwNTQ4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24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IKyzXzSAwFmrek
|
30
|
+
3VUVAhdqOIrIrf16Zpm4NoOGTOst+6sXZ9KQ52DPPwxdLbRCL7HkUFBMIVf2x2LV
|
31
|
+
XflA8IOlSUPH2vmHJnE0yfs7Lzd5+xYpKeOzQSHo0p+SBDzIim3mOZ3ryf4IZQhv
|
32
|
+
wh0fYGJ2iC/w3rPA78Awm6FNPlGCPjgPIz4mliMicRI/sZmFQvn8+2HYWEzDDOO8
|
33
|
+
zYvUB7rkjDGXYqN1Ft3N6EOuNworOFjUlcPrDFCQHf4UgPjD6Z8WbYkI9c7LWtjc
|
34
|
+
HJCyl/PVyS0Srbl8IPn7JsgUCS7S02KOnVzukQ7PTc1wBlAZ4mNb7N9EOp90GP9a
|
35
|
+
YSREEphg3phQsU9LV4Dlc2Id4gB3W+//c1Ek6TFieKoVemKMkbtB1lgqsEpTCfwh
|
36
|
+
oNUg84DlSmZ2z9LKagBVAlDy
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: dxlite
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '0.3'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 0.3.2
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '0.3'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 0.3.2
|
60
60
|
description:
|
61
|
-
email:
|
61
|
+
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
@@ -76,14 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 2.
|
79
|
+
version: 2.5.3
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.10
|
87
88
|
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: Dir-to-xml saves a directory listing in the Dynarex XML format
|
metadata.gz.sig
CHANGED
Binary file
|