dir-to-xml 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6496a0f8c9d61c424059f610d41ec4694af6b0978becff48d288fa69f6e92a1
4
- data.tar.gz: 727f869e42d65809b44ae09fa8047d8489b861030545dfc4697823bf0803f7f0
3
+ metadata.gz: 6d3847feaade1ff658c8dda0403e10b0a98c6350333b01fc4048e97d86cdcd0d
4
+ data.tar.gz: 99a0cad18703df51c90405b585a2aeab5820dca22b52d27acba5dc96dc5e1bb8
5
5
  SHA512:
6
- metadata.gz: 66b044181149d1560fe343c4de959667475322503ac124a522b33a2b6ad8625b2325d7c949ec1dca2adc01c0fc03413d8b273b35ae973297afec99cb9bb95beb
7
- data.tar.gz: 2e04fe70291f883a0c165baa5dd4337841682f34888d36a3a57763e4b1867d1746650ae2375a525eece11c576b75bdbd5503b21b263be691b5f9e7384e241840
6
+ metadata.gz: 37bee8d677c8a5801715d92d2d0617be2d8b559244d4f58b0d0b6fb0cef37f0e803d1a76214dcc92b09012a6fe5d15b51bfe0949feb0bdaa3af6d9e53721d515
7
+ data.tar.gz: 60d691388d4e8f46f15307b50e01f4358fad88ced3f6656d29b8be9e1fa408a256f20f641146b8d375041800952818ed752d78043b79d03e4bae93868781d979
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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
 
@@ -29,9 +29,20 @@ class DirToXML
29
29
  @path, @index, @recursive = path, index, recursive
30
30
 
31
31
  raise "Directory not found." unless File.exists? path
32
+
33
+ @dx = DxLite.new(File.join(@path, @index), debug: @debug)
32
34
 
35
+ # has the directory been modified since last time?
36
+ #
37
+ if @dx.respond_to? :last_modified and @dx.last_modified.length > 0 then
38
+ return if Time.parse(@dx.last_modified) >= \
39
+ File.mtime(File.expand_path(path))
40
+ end
41
+
42
+ puts 'before Dir.glob' if @debug
43
+
33
44
  a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
34
-
45
+
35
46
  a.delete index
36
47
 
37
48
  a2 = a.inject([]) do |r, filename|
@@ -52,6 +63,23 @@ class DirToXML
52
63
  end
53
64
 
54
65
  end
66
+
67
+ if @dx.respond_to? :last_modified and @dx.last_modified.length > 0 then
68
+
69
+ t = Time.parse(@dx.last_modified)
70
+
71
+ # find the most recently modified cur_files
72
+ recent = a2.select {|x| x[:mtime] > t }.map {|x| x[:name]} \
73
+ - %w(dir.xml dir.json)
74
+
75
+ # is it a new file or recently modified?
76
+ new_files = recent - @dx.to_a.map {|x| x[:name]}
77
+ modified = recent - new_files
78
+
79
+ @activity = {modified: modified, new: new_files}
80
+
81
+ end
82
+
55
83
 
56
84
  command = File.exists?(File.join(path, index)) ? :refresh : :dxify
57
85
 
@@ -164,13 +192,14 @@ class DirToXML
164
192
 
165
193
  def dxify(a)
166
194
 
167
- dx = DxLite.new('directory[title, file_path, description]/file(name, ' + \
195
+ dx = DxLite.new('directory[title, file_path, last_modified, description]/file(name, ' + \
168
196
  'type, ext, ctime, mtime, atime, description, owner, ' + \
169
197
  'group, permissions)')
170
198
 
171
199
  dx.title = 'Index of ' + File.expand_path(@path)
172
200
  dx.file_path = File.expand_path(@path)
173
-
201
+ dx.last_modified = Time.now.to_s
202
+
174
203
  dx.import a
175
204
 
176
205
  dx.save File.join(@path, @index)
@@ -182,9 +211,9 @@ class DirToXML
182
211
  def refresh(cur_files)
183
212
 
184
213
  puts 'inside refresh' if @debug
185
- dx = DxLite.new(File.join(@path, @index), debug: @debug)
214
+
186
215
 
187
- prev_files = dx.to_a
216
+ prev_files = @dx.to_a
188
217
 
189
218
  #puts 'prev_files: ' + prev_files.inspect
190
219
  #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.0
4
+ version: 1.0.1
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: 2021-01-23 00:00:00.000000000 Z
38
+ date: 2021-01-24 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dxlite
metadata.gz.sig CHANGED
Binary file