dir-to-xml 1.0.7 → 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 +126 -91
- 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,64 +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
|
-
|
94
|
+
|
89
95
|
if @debug then
|
90
|
-
puts 'file: ' + file.inspect
|
96
|
+
puts 'file: ' + file.inspect
|
91
97
|
puts 'd1: ' + Time.parse(@dx.last_modified).inspect
|
92
98
|
puts 'd2: ' + (file[:mtime]).inspect
|
93
99
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
+
|
101
110
|
if @dx and @dx.respond_to? :last_modified then
|
102
|
-
|
111
|
+
|
103
112
|
if @dx.last_modified.length > 0 then
|
104
|
-
|
113
|
+
|
105
114
|
t = Time.parse(@dx.last_modified)
|
106
|
-
|
115
|
+
|
107
116
|
# find the most recently modified cur_files
|
108
117
|
recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
|
109
118
|
- %w(dir.xml dir.json)
|
110
|
-
|
119
|
+
|
111
120
|
# is it a new file or recently modified?
|
112
121
|
new_files = recent - @dx.to_a.map {|x| x[:name]}
|
113
122
|
modified = recent - new_files
|
114
|
-
|
123
|
+
|
115
124
|
else
|
116
|
-
|
125
|
+
|
117
126
|
new_files = a2.select {|x| x[:type] == 'file'}.map {|x| x[:name]}
|
118
127
|
modified = []
|
119
|
-
|
128
|
+
|
120
129
|
end
|
121
|
-
|
130
|
+
|
122
131
|
@activity = {modified: modified, new: new_files}
|
123
|
-
|
132
|
+
|
124
133
|
end
|
125
|
-
|
134
|
+
|
126
135
|
|
127
136
|
command = File.exists?(File.join(path, index)) ? :refresh : :dxify
|
128
137
|
|
129
138
|
self.method(command).call a2
|
130
139
|
puts '@dx: ' + @dx.inspect if @debug
|
131
140
|
puts '@dx.last_modified: ' + @dx.last_modified.inspect if @debug
|
132
|
-
|
133
|
-
|
134
|
-
@a = @dx.to_a
|
135
|
-
|
141
|
+
|
142
|
+
|
143
|
+
@a = @dx.to_a
|
144
|
+
|
136
145
|
if recursive then
|
137
146
|
|
138
147
|
self.filter_by(type: :directory).to_a.each do |x|
|
@@ -141,21 +150,28 @@ class DirToXML
|
|
141
150
|
DirToXML.new(path2, recursive: true)
|
142
151
|
end
|
143
152
|
end
|
144
|
-
|
153
|
+
|
145
154
|
@object = @a
|
146
155
|
|
147
156
|
end
|
148
|
-
|
157
|
+
|
158
|
+
def directories(&blk)
|
159
|
+
|
160
|
+
self.to_dx.all.select {|x| x.type == 'directory'}.map(&:name)
|
161
|
+
|
162
|
+
end
|
163
|
+
|
149
164
|
def filter(&blk)
|
150
165
|
@dx.filter &blk
|
151
166
|
end
|
152
|
-
|
153
|
-
def filter_by(pattern=/.*/, type: nil, ext: nil)
|
154
|
-
|
155
|
-
@object = @a.select do |x|
|
156
|
-
|
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
|
157
173
|
pattern_match = x[:name] =~ pattern
|
158
|
-
|
174
|
+
|
159
175
|
type_match = type ? x[:type] == type.to_s : true
|
160
176
|
ext_match = ext ? x[:ext] == ext.to_s : true
|
161
177
|
|
@@ -163,89 +179,108 @@ class DirToXML
|
|
163
179
|
|
164
180
|
end
|
165
181
|
|
166
|
-
|
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
|
+
|
167
189
|
end
|
168
|
-
|
190
|
+
|
191
|
+
def find_all_by_ext(s)
|
192
|
+
@dx.all.select {|item| item.ext == s}
|
193
|
+
end
|
194
|
+
|
169
195
|
def find_by_filename(s)
|
170
196
|
@dx.all.find {|item| item.name == s}
|
171
197
|
end
|
172
|
-
|
198
|
+
|
173
199
|
alias find_by_file find_by_filename
|
174
|
-
|
200
|
+
|
175
201
|
def last_modified(ext=nil)
|
176
202
|
|
177
203
|
if ext and ext != '*' then
|
178
204
|
@object = @a.select{|x| x[:ext][/#{ext}/] or x[:type] == 'directory'}
|
179
205
|
end
|
180
|
-
|
206
|
+
|
181
207
|
a = sort_by :mtime
|
182
208
|
|
183
209
|
lm = a[-1]
|
184
|
-
|
210
|
+
|
185
211
|
if @recursive and lm[:type] == 'directory' then
|
186
212
|
return [lm, DirToXML.new(File.join(@path, lm[:name])).last_modified]
|
187
213
|
else
|
188
214
|
lm
|
189
215
|
end
|
190
216
|
end
|
191
|
-
|
217
|
+
|
192
218
|
def save()
|
193
219
|
@dx.save File.join(@path, @index)
|
194
220
|
end
|
195
|
-
|
221
|
+
|
196
222
|
def select_by_ext(ext, &blk)
|
197
|
-
|
223
|
+
|
198
224
|
@a = @dx.to_a unless @a
|
199
|
-
|
225
|
+
|
200
226
|
@object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
|
201
227
|
return if @object.empty?
|
202
|
-
|
228
|
+
|
203
229
|
dx = DxLite.new
|
204
230
|
dx.import @object
|
205
231
|
dtx = DirToXML.new(dx)
|
206
232
|
block_given? ? dtx.dx.all.map(&:name).each(&blk) : dtx
|
207
233
|
end
|
208
|
-
|
234
|
+
|
209
235
|
def sort_by(sym)
|
210
|
-
|
236
|
+
|
211
237
|
puts 'inside sort_by' if @debug
|
212
|
-
procs = [
|
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
|
+
]
|
213
248
|
proc1 = procs.assoc(sym).last
|
214
|
-
|
249
|
+
|
215
250
|
puts '@object: ' + @object.inspect if @debug
|
216
251
|
@object = @a = @dx.to_a if @object.nil?
|
217
252
|
proc1.call(@object)
|
218
|
-
|
253
|
+
|
219
254
|
end
|
220
|
-
|
255
|
+
|
221
256
|
def sort_by_last_modified()
|
222
257
|
sort_by :mtime
|
223
258
|
end
|
224
|
-
|
259
|
+
|
225
260
|
alias sort_by_lastmodified sort_by_last_modified
|
226
|
-
|
261
|
+
|
227
262
|
def to_a
|
228
263
|
@object || @a
|
229
264
|
end
|
230
|
-
|
265
|
+
|
231
266
|
def to_h()
|
232
267
|
self.to_a.inject({}){|r,x| r.merge(x[:name] => x)}
|
233
268
|
end
|
234
|
-
|
269
|
+
|
235
270
|
def to_xml(options=nil)
|
236
271
|
@dx.to_xml options
|
237
272
|
end
|
238
|
-
|
273
|
+
|
239
274
|
def to_dynarex
|
240
275
|
@dx.clone
|
241
276
|
end
|
242
|
-
|
277
|
+
|
243
278
|
alias to_dx to_dynarex
|
244
|
-
|
279
|
+
|
245
280
|
private
|
246
|
-
|
281
|
+
|
247
282
|
def dxify(a)
|
248
|
-
|
283
|
+
|
249
284
|
@dx.last_modified = Time.now.to_s if @dx.respond_to? :last_modified
|
250
285
|
@dx.import a
|
251
286
|
@dx.save File.join(@path, @index)
|
@@ -254,13 +289,13 @@ class DirToXML
|
|
254
289
|
|
255
290
|
def refresh(cur_files)
|
256
291
|
|
257
|
-
puts 'inside refresh' if @debug
|
292
|
+
puts 'inside refresh' if @debug
|
258
293
|
|
259
294
|
prev_files = @dx.to_a
|
260
|
-
|
295
|
+
|
261
296
|
#puts 'prev_files: ' + prev_files.inspect
|
262
297
|
#puts 'cur_files: ' + cur_files.inspect
|
263
|
-
|
298
|
+
|
264
299
|
cur_files.each do |x|
|
265
300
|
|
266
301
|
file = prev_files.find {|item| item[:name] == x[:name] }
|
@@ -269,7 +304,7 @@ class DirToXML
|
|
269
304
|
end
|
270
305
|
|
271
306
|
dxify(cur_files)
|
272
|
-
|
307
|
+
|
273
308
|
end
|
274
|
-
|
309
|
+
|
275
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
|