dir-to-xml 1.0.4 → 1.0.8
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/lib/dir-to-xml.rb +134 -85
- data.tar.gz.sig +0 -0
- metadata +6 -6
- 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: bfe35ab7508e85463cf2aeb0105e30e38372912a8a47f7d90a298caa702ff0dd
|
4
|
+
data.tar.gz: fff6e43ea00d6a697e0b4aaa7aedbd5ef7d38645756b01329b0f9095edea3b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ee8ffb01712045e85717db1c74f67ccd68e526ee74e18d1905800eea6d55d75e634badb9f13b00f36d5eac1204d1ea62961db5f84ad03ae49bd9f1c36dae86
|
7
|
+
data.tar.gz: 8243bee16134b8a3d41de944b37eff432fcd7b785f83703537ff156d4e6f127cc17c59c858e957b942fc21e24b1805d24fa0608e1f539f7226d3a16f0f4235b4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/dir-to-xml.rb
CHANGED
@@ -8,39 +8,39 @@ require 'dxlite'
|
|
8
8
|
class DirToXML
|
9
9
|
|
10
10
|
attr_reader :dx, :activity
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(x= '.', recursive: false, index: 'dir.xml', debug: false)
|
13
|
-
|
13
|
+
|
14
14
|
super()
|
15
|
-
|
15
|
+
|
16
16
|
@debug = debug
|
17
|
-
|
17
|
+
|
18
18
|
@dx = nil
|
19
19
|
@activity = {new: [], modified: []}
|
20
|
-
|
20
|
+
|
21
21
|
if x.is_a? DxLite then
|
22
|
-
|
23
|
-
@dx = x
|
24
|
-
@a = @dx.to_a
|
25
|
-
@object = @a
|
26
|
-
|
22
|
+
|
23
|
+
@dx = x
|
24
|
+
@a = @dx.to_a
|
25
|
+
@object = @a
|
26
|
+
|
27
27
|
return self
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
path = x
|
31
|
-
|
31
|
+
|
32
32
|
@path, @index, @recursive = path, index, recursive
|
33
|
-
|
33
|
+
|
34
34
|
raise "Directory not found." unless File.exists? path
|
35
35
|
filepath = File.join(path, index)
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
|
38
38
|
if File.exists? filepath then
|
39
|
-
|
39
|
+
|
40
40
|
@dx = DxLite.new(File.join(@path, @index), debug: @debug)
|
41
|
-
|
41
|
+
|
42
42
|
else
|
43
|
-
|
43
|
+
|
44
44
|
@dx = DxLite.new('directory[title, file_path, last_modified, ' + \
|
45
45
|
'description]/file(name, type, ext, ctime, mtime, atime, ' + \
|
46
46
|
'description, owner, group, permissions)')
|
@@ -49,19 +49,25 @@ class DirToXML
|
|
49
49
|
@dx.title = 'Index of ' + File.expand_path(@path)
|
50
50
|
@dx.file_path = File.expand_path(@path)
|
51
51
|
@dx.last_modified = ''
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
if @debug then
|
56
|
+
puts 'before Dir.glob'
|
57
|
+
puts '_path: ' + File.join(path, "*").inspect
|
58
|
+
end
|
59
|
+
|
57
60
|
a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
|
58
|
-
|
61
|
+
puts 'a: ' + a.inspect if @debug
|
62
|
+
|
59
63
|
a.delete index
|
60
64
|
|
65
|
+
return if a.empty?
|
66
|
+
|
61
67
|
a2 = a.inject([]) do |r, filename|
|
62
68
|
|
63
69
|
x = File.join(path, filename)
|
64
|
-
|
70
|
+
|
65
71
|
begin
|
66
72
|
r << {
|
67
73
|
name: filename,
|
@@ -75,58 +81,67 @@ class DirToXML
|
|
75
81
|
r
|
76
82
|
end
|
77
83
|
|
78
|
-
end
|
79
|
-
|
84
|
+
end
|
85
|
+
|
80
86
|
# has the directory been modified since last time?
|
81
87
|
#
|
82
88
|
if @dx and @dx.respond_to? :last_modified and \
|
83
89
|
@dx.last_modified.length > 0 then
|
84
|
-
|
90
|
+
|
85
91
|
puts 'nothing to do' if @debug
|
86
|
-
|
92
|
+
puts 'a2: ' + a2.inspect if @debug
|
87
93
|
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
|
|
94
|
-
|
95
|
+
if @debug then
|
96
|
+
puts 'file: ' + file.inspect
|
97
|
+
puts 'd1: ' + Time.parse(@dx.last_modified).inspect
|
98
|
+
puts 'd2: ' + (file[:mtime]).inspect
|
99
|
+
end
|
100
|
+
|
101
|
+
if Time.parse(@dx.last_modified) >= file[:mtime] then
|
102
|
+
@a = @dx.to_a
|
103
|
+
return
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
puts 'stage 2' if @debug
|
109
|
+
|
95
110
|
if @dx and @dx.respond_to? :last_modified then
|
96
|
-
|
111
|
+
|
97
112
|
if @dx.last_modified.length > 0 then
|
98
|
-
|
113
|
+
|
99
114
|
t = Time.parse(@dx.last_modified)
|
100
|
-
|
115
|
+
|
101
116
|
# find the most recently modified cur_files
|
102
117
|
recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
|
103
118
|
- %w(dir.xml dir.json)
|
104
|
-
|
119
|
+
|
105
120
|
# is it a new file or recently modified?
|
106
121
|
new_files = recent - @dx.to_a.map {|x| x[:name]}
|
107
122
|
modified = recent - new_files
|
108
|
-
|
123
|
+
|
109
124
|
else
|
110
|
-
|
125
|
+
|
111
126
|
new_files = a2.select {|x| x[:type] == 'file'}.map {|x| x[:name]}
|
112
127
|
modified = []
|
113
|
-
|
128
|
+
|
114
129
|
end
|
115
|
-
|
130
|
+
|
116
131
|
@activity = {modified: modified, new: new_files}
|
117
|
-
|
132
|
+
|
118
133
|
end
|
119
|
-
|
134
|
+
|
120
135
|
|
121
136
|
command = File.exists?(File.join(path, index)) ? :refresh : :dxify
|
122
137
|
|
123
138
|
self.method(command).call a2
|
124
139
|
puts '@dx: ' + @dx.inspect if @debug
|
125
140
|
puts '@dx.last_modified: ' + @dx.last_modified.inspect if @debug
|
126
|
-
|
127
|
-
|
128
|
-
@a = @dx.to_a
|
129
|
-
|
141
|
+
|
142
|
+
|
143
|
+
@a = @dx.to_a
|
144
|
+
|
130
145
|
if recursive then
|
131
146
|
|
132
147
|
self.filter_by(type: :directory).to_a.each do |x|
|
@@ -135,21 +150,28 @@ class DirToXML
|
|
135
150
|
DirToXML.new(path2, recursive: true)
|
136
151
|
end
|
137
152
|
end
|
138
|
-
|
153
|
+
|
139
154
|
@object = @a
|
140
155
|
|
141
156
|
end
|
142
|
-
|
157
|
+
|
158
|
+
def directories(&blk)
|
159
|
+
|
160
|
+
self.to_dx.all.select {|x| x.type == 'directory'}.map(&:name)
|
161
|
+
|
162
|
+
end
|
163
|
+
|
143
164
|
def filter(&blk)
|
144
165
|
@dx.filter &blk
|
145
166
|
end
|
146
|
-
|
147
|
-
def filter_by(pattern=/.*/, type: nil, ext: nil)
|
148
|
-
|
149
|
-
@object = @a.select do |x|
|
150
|
-
|
167
|
+
|
168
|
+
def filter_by(pattern=/.*/, type: nil, ext: nil, &blk)
|
169
|
+
|
170
|
+
@object = @a.select do |x|
|
171
|
+
|
172
|
+
puts '_x: ' + x.inspect if @debug
|
151
173
|
pattern_match = x[:name] =~ pattern
|
152
|
-
|
174
|
+
|
153
175
|
type_match = type ? x[:type] == type.to_s : true
|
154
176
|
ext_match = ext ? x[:ext] == ext.to_s : true
|
155
177
|
|
@@ -157,82 +179,109 @@ class DirToXML
|
|
157
179
|
|
158
180
|
end
|
159
181
|
|
160
|
-
|
182
|
+
return if @object.empty?
|
183
|
+
|
184
|
+
@dx = DxLite.new
|
185
|
+
@dx.import @object
|
186
|
+
|
187
|
+
block_given? ? @dx.all.map(&:name).each(&blk) : self
|
188
|
+
|
161
189
|
end
|
162
|
-
|
190
|
+
|
191
|
+
def find_all_by_ext(s)
|
192
|
+
@dx.all.select {|item| item.ext == s}
|
193
|
+
end
|
194
|
+
|
163
195
|
def find_by_filename(s)
|
164
196
|
@dx.all.find {|item| item.name == s}
|
165
197
|
end
|
166
|
-
|
198
|
+
|
167
199
|
alias find_by_file find_by_filename
|
168
|
-
|
200
|
+
|
169
201
|
def last_modified(ext=nil)
|
170
202
|
|
171
203
|
if ext and ext != '*' then
|
172
204
|
@object = @a.select{|x| x[:ext][/#{ext}/] or x[:type] == 'directory'}
|
173
205
|
end
|
174
|
-
|
206
|
+
|
175
207
|
a = sort_by :mtime
|
176
208
|
|
177
209
|
lm = a[-1]
|
178
|
-
|
210
|
+
|
179
211
|
if @recursive and lm[:type] == 'directory' then
|
180
212
|
return [lm, DirToXML.new(File.join(@path, lm[:name])).last_modified]
|
181
213
|
else
|
182
214
|
lm
|
183
215
|
end
|
184
216
|
end
|
185
|
-
|
217
|
+
|
186
218
|
def save()
|
187
219
|
@dx.save File.join(@path, @index)
|
188
220
|
end
|
189
|
-
|
221
|
+
|
190
222
|
def select_by_ext(ext, &blk)
|
191
|
-
|
223
|
+
|
224
|
+
@a = @dx.to_a unless @a
|
225
|
+
|
192
226
|
@object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
|
193
227
|
return if @object.empty?
|
194
|
-
|
228
|
+
|
195
229
|
dx = DxLite.new
|
196
230
|
dx.import @object
|
197
231
|
dtx = DirToXML.new(dx)
|
198
232
|
block_given? ? dtx.dx.all.map(&:name).each(&blk) : dtx
|
199
233
|
end
|
200
|
-
|
234
|
+
|
201
235
|
def sort_by(sym)
|
202
|
-
|
236
|
+
|
237
|
+
puts 'inside sort_by' if @debug
|
238
|
+
procs = [
|
239
|
+
[
|
240
|
+
:mtime,
|
241
|
+
lambda do |obj|
|
242
|
+
obj.sort_by do |x|
|
243
|
+
x[:mtime].is_a?(String) ? Time.parse(x[:mtime]) : x[:mtime]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
]
|
247
|
+
]
|
203
248
|
proc1 = procs.assoc(sym).last
|
249
|
+
|
250
|
+
puts '@object: ' + @object.inspect if @debug
|
251
|
+
@object = @a = @dx.to_a if @object.nil?
|
204
252
|
proc1.call(@object)
|
253
|
+
|
205
254
|
end
|
206
|
-
|
255
|
+
|
207
256
|
def sort_by_last_modified()
|
208
257
|
sort_by :mtime
|
209
258
|
end
|
210
|
-
|
259
|
+
|
211
260
|
alias sort_by_lastmodified sort_by_last_modified
|
212
|
-
|
261
|
+
|
213
262
|
def to_a
|
214
263
|
@object || @a
|
215
264
|
end
|
216
|
-
|
265
|
+
|
217
266
|
def to_h()
|
218
267
|
self.to_a.inject({}){|r,x| r.merge(x[:name] => x)}
|
219
268
|
end
|
220
|
-
|
269
|
+
|
221
270
|
def to_xml(options=nil)
|
222
271
|
@dx.to_xml options
|
223
272
|
end
|
224
|
-
|
273
|
+
|
225
274
|
def to_dynarex
|
226
275
|
@dx.clone
|
227
276
|
end
|
228
|
-
|
277
|
+
|
229
278
|
alias to_dx to_dynarex
|
230
|
-
|
279
|
+
|
231
280
|
private
|
232
|
-
|
281
|
+
|
233
282
|
def dxify(a)
|
234
|
-
|
235
|
-
@dx.last_modified = Time.now.to_s
|
283
|
+
|
284
|
+
@dx.last_modified = Time.now.to_s if @dx.respond_to? :last_modified
|
236
285
|
@dx.import a
|
237
286
|
@dx.save File.join(@path, @index)
|
238
287
|
|
@@ -240,13 +289,13 @@ class DirToXML
|
|
240
289
|
|
241
290
|
def refresh(cur_files)
|
242
291
|
|
243
|
-
puts 'inside refresh' if @debug
|
292
|
+
puts 'inside refresh' if @debug
|
244
293
|
|
245
294
|
prev_files = @dx.to_a
|
246
|
-
|
295
|
+
|
247
296
|
#puts 'prev_files: ' + prev_files.inspect
|
248
297
|
#puts 'cur_files: ' + cur_files.inspect
|
249
|
-
|
298
|
+
|
250
299
|
cur_files.each do |x|
|
251
300
|
|
252
301
|
file = prev_files.find {|item| item[:name] == x[:name] }
|
@@ -255,7 +304,7 @@ class DirToXML
|
|
255
304
|
end
|
256
305
|
|
257
306
|
dxify(cur_files)
|
258
|
-
|
307
|
+
|
259
308
|
end
|
260
|
-
|
309
|
+
|
261
310
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
YSREEphg3phQsU9LV4Dlc2Id4gB3W+//c1Ek6TFieKoVemKMkbtB1lgqsEpTCfwh
|
36
36
|
oNUg84DlSmZ2z9LKagBVAlDy
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-01-15 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: dxlite
|
@@ -43,20 +43,20 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.4'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
49
|
+
version: 0.4.1
|
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: '0.
|
56
|
+
version: '0.4'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.
|
59
|
+
version: 0.4.1
|
60
60
|
description:
|
61
61
|
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|