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