dir-to-xml 1.0.0 → 1.0.5
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 +2 -3
- data/lib/dir-to-xml.rb +82 -18
- 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: 001e83927dbcc6a8bbde99e4eca19b904a5344b02f5ab8ad2b1fc63a7e55a24b
|
4
|
+
data.tar.gz: 67404d3cec0b93c5c2a4fbea8ff01e3e18ea24df2176c6ac4dcaaf6495a97c69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ed16618d5d1bdd857b1cf1739b59f9964e90ce315437cc0e5dbe995e87b258dcfbde302cdd5f47233f95b8b55324801af65884b6aef1fd6b5e72b6a62295ed
|
7
|
+
data.tar.gz: d0ab3ede67051850dada5596979063397a875f1a25655acd5242f0ffe5899fefe30a71605c26fe437bfb451dc49c7a3bff518b006392834d3885ac72bd7b62e3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
w7+=]$�UlBe&�7���N7D�Ѷ�l�����=y�L��5´՚�WNU��a��Z�}a��hH3+��TJTJ{�t�>�à�] :U=d�e��LČ�Boq�����`��/��2.Rш{:'ƣ�]�!7���u���z�1ۻ�� ��I�A1~���՜*]�M�?0�@��ڕ��jA=xy�K��VV�X��E��ľ�o-�⯿��,�m��g��r
|
1
|
+
D����")xefc=cw��n��xf��bE{�gcϽ�}�X�FI6!1D_+�)�y0��מSL��E_�qԺ�?�CIQ�Ǻ&x&뼘�C���ſ�m/�0V�X{LDt�.��',�6Wk����<��]��ր@bߢWbhh,+���.1dD �Zj��ī0Og�|����xz���& �ׂβ��65�i=����nR�Dy+���3�b-��#��F�{CK������sz�z��"�J6�D��0�$a`����
|
2
|
+
����]!�{r�,�\8I�a�.���+���b�S0���D;�;+�v����K�̸��]���>��n�:P@-���~x��o^I�3b�`�B�x9����6�����_Bq��Ik{:u�^
|
data/lib/dir-to-xml.rb
CHANGED
@@ -7,7 +7,7 @@ require 'dxlite'
|
|
7
7
|
|
8
8
|
class DirToXML
|
9
9
|
|
10
|
-
attr_reader :dx
|
10
|
+
attr_reader :dx, :activity
|
11
11
|
|
12
12
|
def initialize(x= '.', recursive: false, index: 'dir.xml', debug: false)
|
13
13
|
|
@@ -15,6 +15,9 @@ class DirToXML
|
|
15
15
|
|
16
16
|
@debug = debug
|
17
17
|
|
18
|
+
@dx = nil
|
19
|
+
@activity = {new: [], modified: []}
|
20
|
+
|
18
21
|
if x.is_a? DxLite then
|
19
22
|
|
20
23
|
@dx = x
|
@@ -29,9 +32,30 @@ class DirToXML
|
|
29
32
|
@path, @index, @recursive = path, index, recursive
|
30
33
|
|
31
34
|
raise "Directory not found." unless File.exists? path
|
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)')
|
32
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
|
+
|
33
57
|
a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
|
34
|
-
|
58
|
+
|
35
59
|
a.delete index
|
36
60
|
|
37
61
|
a2 = a.inject([]) do |r, filename|
|
@@ -52,10 +76,54 @@ class DirToXML
|
|
52
76
|
end
|
53
77
|
|
54
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
|
+
|
55
120
|
|
56
121
|
command = File.exists?(File.join(path, index)) ? :refresh : :dxify
|
57
122
|
|
58
|
-
|
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
|
+
|
59
127
|
|
60
128
|
@a = @dx.to_a
|
61
129
|
|
@@ -131,9 +199,15 @@ class DirToXML
|
|
131
199
|
end
|
132
200
|
|
133
201
|
def sort_by(sym)
|
202
|
+
|
203
|
+
puts 'inside sort_by' if @debug
|
134
204
|
procs = [[:mtime, lambda{|obj| obj.sort_by{|x| x[:mtime]}}]]
|
135
205
|
proc1 = procs.assoc(sym).last
|
206
|
+
|
207
|
+
puts '@object: ' + @object.inspect if @debug
|
208
|
+
@object = @a = @dx.to_a if @object.nil?
|
136
209
|
proc1.call(@object)
|
210
|
+
|
137
211
|
end
|
138
212
|
|
139
213
|
def sort_by_last_modified()
|
@@ -164,27 +238,17 @@ class DirToXML
|
|
164
238
|
|
165
239
|
def dxify(a)
|
166
240
|
|
167
|
-
dx =
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
dx.title = 'Index of ' + File.expand_path(@path)
|
172
|
-
dx.file_path = File.expand_path(@path)
|
173
|
-
|
174
|
-
dx.import a
|
175
|
-
|
176
|
-
dx.save File.join(@path, @index)
|
177
|
-
|
178
|
-
return dx
|
241
|
+
@dx.last_modified = Time.now.to_s if @dx.respond_to :last_modified
|
242
|
+
@dx.import a
|
243
|
+
@dx.save File.join(@path, @index)
|
179
244
|
|
180
245
|
end
|
181
246
|
|
182
247
|
def refresh(cur_files)
|
183
248
|
|
184
|
-
puts 'inside refresh' if @debug
|
185
|
-
dx = DxLite.new(File.join(@path, @index), debug: @debug)
|
249
|
+
puts 'inside refresh' if @debug
|
186
250
|
|
187
|
-
prev_files = dx.to_a
|
251
|
+
prev_files = @dx.to_a
|
188
252
|
|
189
253
|
#puts 'prev_files: ' + prev_files.inspect
|
190
254
|
#puts 'cur_files: ' + cur_files.inspect
|
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.5
|
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-01
|
38
|
+
date: 2021-02-01 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
|