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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4612af405a2a24d589028a583d28b3217c7c44db120ad68d015c412efe86b16
4
- data.tar.gz: 8d66e4b320b585972be52e6085186858b2fd99dbd369b3d3c0919cc0cd36afa2
3
+ metadata.gz: a3383c2c66c62fb7de0316da47639a9416de37ac18907c12dbba947603237ffa
4
+ data.tar.gz: 5886daf349f5ac8b0fa13c1ddaa37cf76890a7a8a9117de5495f01642f2fe516
5
5
  SHA512:
6
- metadata.gz: bd2821ac72de327ed54318f5d2ac63c14c184dae26181e6ff38ba455466a067de75dffd48b3749ce5b9ba03ca542d98db4ac94818e929f9e6ce86df43406a4ff
7
- data.tar.gz: 48852e32ca730dc65bc3a4363bf87eb8d365742ea20add65ec22adf97e9e80fabf59716cf1cdcea171a234bda6f3dc7dac4ecf994314e26241863b66f3957380
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
- return if Time.parse(@dx.last_modified) >= \
49
- File.mtime(File.expand_path(path))
50
- end
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
- if @dx and @dx.respond_to? :last_modified \
78
- and @dx.last_modified.length > 0 then
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
- t = Time.parse(@dx.last_modified)
85
+ puts 'nothing to do' if @debug
81
86
 
82
- # find the most recently modified cur_files
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
- # is it a new file or recently modified?
87
- new_files = recent - @dx.to_a.map {|x| x[:name]}
88
- modified = recent - new_files
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
- @dx = self.method(command).call a2
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
- procs = [[:mtime, lambda{|obj| obj.sort_by{|x| x[:mtime]}}]]
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 = DxLite.new('directory[title, file_path, last_modified, description]/file(name, ' + \
207
- 'type, ext, ctime, mtime, atime, description, owner, ' + \
208
- 'group, permissions)')
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.2
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-01-24 00:00:00.000000000 Z
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