dir-to-xml 1.0.2 → 1.0.7
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 +68 -36
- metadata +8 -8
- 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: a3383c2c66c62fb7de0316da47639a9416de37ac18907c12dbba947603237ffa
|
4
|
+
data.tar.gz: 5886daf349f5ac8b0fa13c1ddaa37cf76890a7a8a9117de5495f01642f2fe516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978914ab049ad0660a667295c63bf994f26358fd975e10fbd7390a063322caee77a30d645bfc672598da58b8d3ed87385412dda8643d18809b55424669513c75
|
7
|
+
data.tar.gz: ce2768f88448e621d886f01aadc6964b16a1d9deab82879482e56d95e72dec36d724cc6a557e0b05b376e69e22b88a136624cff7b3536b39fdc7b8513edc46b9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dir-to-xml.rb
CHANGED
@@ -16,6 +16,7 @@ class DirToXML
|
|
16
16
|
@debug = debug
|
17
17
|
|
18
18
|
@dx = nil
|
19
|
+
@activity = {new: [], modified: []}
|
19
20
|
|
20
21
|
if x.is_a? DxLite then
|
21
22
|
|
@@ -37,17 +38,19 @@ class DirToXML
|
|
37
38
|
if File.exists? filepath then
|
38
39
|
|
39
40
|
@dx = DxLite.new(File.join(@path, @index), debug: @debug)
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# has the directory been modified since last time?
|
44
|
-
#
|
45
|
-
if @dx and @dx.respond_to? :last_modified and \
|
46
|
-
@dx.last_modified.length > 0 then
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
51
54
|
|
52
55
|
puts 'before Dir.glob' if @debug
|
53
56
|
|
@@ -74,18 +77,47 @@ class DirToXML
|
|
74
77
|
|
75
78
|
end
|
76
79
|
|
77
|
-
|
78
|
-
|
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
|
79
84
|
|
80
|
-
|
85
|
+
puts 'nothing to do' if @debug
|
81
86
|
|
82
|
-
|
83
|
-
recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
|
84
|
-
- %w(dir.xml dir.json)
|
87
|
+
file = a2.max_by {|x| x[:mtime]}
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
if @debug then
|
90
|
+
puts 'file: ' + file.inspect
|
91
|
+
puts 'd1: ' + Time.parse(@dx.last_modified).inspect
|
92
|
+
puts 'd2: ' + (file[:mtime]).inspect
|
93
|
+
end
|
94
|
+
|
95
|
+
return if Time.parse(@dx.last_modified) >= file[:mtime]
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
puts 'stage 2'
|
100
|
+
|
101
|
+
if @dx and @dx.respond_to? :last_modified then
|
102
|
+
|
103
|
+
if @dx.last_modified.length > 0 then
|
104
|
+
|
105
|
+
t = Time.parse(@dx.last_modified)
|
106
|
+
|
107
|
+
# find the most recently modified cur_files
|
108
|
+
recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
|
109
|
+
- %w(dir.xml dir.json)
|
110
|
+
|
111
|
+
# is it a new file or recently modified?
|
112
|
+
new_files = recent - @dx.to_a.map {|x| x[:name]}
|
113
|
+
modified = recent - new_files
|
114
|
+
|
115
|
+
else
|
116
|
+
|
117
|
+
new_files = a2.select {|x| x[:type] == 'file'}.map {|x| x[:name]}
|
118
|
+
modified = []
|
119
|
+
|
120
|
+
end
|
89
121
|
|
90
122
|
@activity = {modified: modified, new: new_files}
|
91
123
|
|
@@ -94,7 +126,10 @@ class DirToXML
|
|
94
126
|
|
95
127
|
command = File.exists?(File.join(path, index)) ? :refresh : :dxify
|
96
128
|
|
97
|
-
|
129
|
+
self.method(command).call a2
|
130
|
+
puts '@dx: ' + @dx.inspect if @debug
|
131
|
+
puts '@dx.last_modified: ' + @dx.last_modified.inspect if @debug
|
132
|
+
|
98
133
|
|
99
134
|
@a = @dx.to_a
|
100
135
|
|
@@ -160,6 +195,8 @@ class DirToXML
|
|
160
195
|
|
161
196
|
def select_by_ext(ext, &blk)
|
162
197
|
|
198
|
+
@a = @dx.to_a unless @a
|
199
|
+
|
163
200
|
@object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
|
164
201
|
return if @object.empty?
|
165
202
|
|
@@ -170,9 +207,15 @@ class DirToXML
|
|
170
207
|
end
|
171
208
|
|
172
209
|
def sort_by(sym)
|
173
|
-
|
210
|
+
|
211
|
+
puts 'inside sort_by' if @debug
|
212
|
+
procs = [[:mtime, lambda{|obj| obj.sort_by{|x| Time.parse(x[:mtime])}}]]
|
174
213
|
proc1 = procs.assoc(sym).last
|
214
|
+
|
215
|
+
puts '@object: ' + @object.inspect if @debug
|
216
|
+
@object = @a = @dx.to_a if @object.nil?
|
175
217
|
proc1.call(@object)
|
218
|
+
|
176
219
|
end
|
177
220
|
|
178
221
|
def sort_by_last_modified()
|
@@ -203,26 +246,15 @@ class DirToXML
|
|
203
246
|
|
204
247
|
def dxify(a)
|
205
248
|
|
206
|
-
dx =
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
dx.title = 'Index of ' + File.expand_path(@path)
|
211
|
-
dx.file_path = File.expand_path(@path)
|
212
|
-
dx.last_modified = Time.now.to_s
|
213
|
-
|
214
|
-
dx.import a
|
215
|
-
|
216
|
-
dx.save File.join(@path, @index)
|
217
|
-
|
218
|
-
return dx
|
249
|
+
@dx.last_modified = Time.now.to_s if @dx.respond_to? :last_modified
|
250
|
+
@dx.import a
|
251
|
+
@dx.save File.join(@path, @index)
|
219
252
|
|
220
253
|
end
|
221
254
|
|
222
255
|
def refresh(cur_files)
|
223
256
|
|
224
|
-
puts 'inside refresh' if @debug
|
225
|
-
|
257
|
+
puts 'inside refresh' if @debug
|
226
258
|
|
227
259
|
prev_files = @dx.to_a
|
228
260
|
|
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: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
YSREEphg3phQsU9LV4Dlc2Id4gB3W+//c1Ek6TFieKoVemKMkbtB1lgqsEpTCfwh
|
36
36
|
oNUg84DlSmZ2z9LKagBVAlDy
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-
|
38
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: dxlite
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.3.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
46
|
version: '0.3'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::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
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 0.3.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
56
|
version: '0.3'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.3.2
|
60
60
|
description:
|
61
61
|
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|