dir-to-xml 0.9.5 → 1.0.4

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: f5eb4944a687b83409892b6df2f1c1841383022fc70042fee18ff784a4a09702
4
- data.tar.gz: 85cb703ba3fb49d41d0d22b8b8eb4d7518fc43442158825a5db8a5b26fcf8203
3
+ metadata.gz: f155b43f7372db3ad7636b3c54f8369d78387d155ec4230f24b2ecf6a6b7d206
4
+ data.tar.gz: 3def96a9380e89e249275346f39ca5d6eebcbc60996e66c5d2a5786d9a250f03
5
5
  SHA512:
6
- metadata.gz: 208c4022a9adef5f4d6db07085541870a70597ccf7c44f215698ef81e21873689f8cc11b4c6d697bc6449062cd0d6d514feaab806a1402c4b50cba7289bc043a
7
- data.tar.gz: 99502e1db39fa1914f2f58f6ca0412c98cfbd1d5a2ccc716262dcb99dfa9ed92a55d610e695a61ac315be8ad1f7410d987b33d47375046592f9857d459aecdb4
6
+ metadata.gz: ade701a7b673a6305a73f52f10ce05e828588f4d235acc747aa5adb72a7e02a4dd11ac7312f0661ef843a8df9d848943eb8ddac53c954bc4b5176b0838efcfa0
7
+ data.tar.gz: a542531fdbfe27e2621c7f0db8b034b32528f0aa284e4038c9ee1239655e419a00d9e5e82c98ab5c7e86e634e1cba56677e1186318b8e58598632f08fb8b8af6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,18 +2,23 @@
2
2
 
3
3
  # file: dir-to-xml.rb
4
4
 
5
- require 'dynarex'
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
- if x.is_a? Dynarex then
16
+ @debug = debug
17
+
18
+ @dx = nil
19
+ @activity = {new: [], modified: []}
20
+
21
+ if x.is_a? DxLite then
17
22
 
18
23
  @dx = x
19
24
  @a = @dx.to_a
@@ -27,9 +32,30 @@ class DirToXML
27
32
  @path, @index, @recursive = path, index, recursive
28
33
 
29
34
  raise "Directory not found." unless File.exists? path
30
-
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)')
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
+
31
57
  a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
32
-
58
+
33
59
  a.delete index
34
60
 
35
61
  a2 = a.inject([]) do |r, filename|
@@ -50,10 +76,54 @@ class DirToXML
50
76
  end
51
77
 
52
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
+
53
120
 
54
121
  command = File.exists?(File.join(path, index)) ? :refresh : :dxify
55
122
 
56
- @dx = self.method(command).call a2
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
+
57
127
 
58
128
  @a = @dx.to_a
59
129
 
@@ -122,7 +192,7 @@ class DirToXML
122
192
  @object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
123
193
  return if @object.empty?
124
194
 
125
- dx = Dynarex.new json_out: false
195
+ dx = DxLite.new
126
196
  dx.import @object
127
197
  dtx = DirToXML.new(dx)
128
198
  block_given? ? dtx.dx.all.map(&:name).each(&blk) : dtx
@@ -162,31 +232,25 @@ class DirToXML
162
232
 
163
233
  def dxify(a)
164
234
 
165
- dx = Dynarex.new('directory[title, file_path, description]/file(name, ' + \
166
- 'type, ext, ctime, mtime, atime, description, owner, ' + \
167
- 'group, permissions)', json_out: false)
168
-
169
- dx.title = 'Index of ' + File.expand_path(@path)
170
- dx.file_path = File.expand_path(@path)
171
-
172
- dx.import a
173
-
174
- dx.save File.join(@path, @index)
175
-
176
- return dx
235
+ @dx.last_modified = Time.now.to_s
236
+ @dx.import a
237
+ @dx.save File.join(@path, @index)
177
238
 
178
239
  end
179
240
 
180
241
  def refresh(cur_files)
181
242
 
182
- dx = Dynarex.new(File.join(@path, @index), json_out: false)
243
+ puts 'inside refresh' if @debug
183
244
 
184
- prev_files = dx.to_a
245
+ prev_files = @dx.to_a
246
+
247
+ #puts 'prev_files: ' + prev_files.inspect
248
+ #puts 'cur_files: ' + cur_files.inspect
185
249
 
186
250
  cur_files.each do |x|
187
251
 
188
252
  file = prev_files.find {|item| item[:name] == x[:name] }
189
-
253
+ #puts 'found : ' + file.inspect if @debug
190
254
  x[:description] = file[:description] if file and file[:description]
191
255
  end
192
256
 
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.9.5
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,54 +11,54 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwMjA5MTI1MDQ2WhcN
15
- MjAwMjA5MTI1MDQ2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDZ4t3Z
17
- RMbb5Rq5td/W9rc8g40wxGUMWbpbTgAakq6En2t4tDg06Cp6VkW7fJQXh4lz5cB3
18
- 2IsgRuQ3rI5dBWWbWzoBV4stsk2Cbr5LZfL0jriAE9Itxz0+9EUaEN/BSak6tjS7
19
- HxW9nqwqgHigpr55BJV1VuiNUWcYvWxMv2FYSpb9x6Txi5InjLSBuG+4VLkjYq6W
20
- 5ZW1EdTLMD+INJmu9L0/6gRuspLna6hgr3yvbs6U99xSZXAKDz1ACvSauStIV9Tg
21
- JFtZVMX9gP5YoV/LGKOa9UcaNowQn5BVtYkkx4u+zunWQMXNjJdhNKd1q9M5hKj3
22
- xsiLdOPUgvPD6yxIdc4P/HhFRj8uUV1qvGTwVvWtM3AQgTUauIU6ywxxy9VJWFVm
23
- Dx9IM8e8C1iRIe+eJHOjC3gNdJylQd4dkJRdk3eg98lKU3HJ4l+Hx71gbKbT6AkX
24
- veaO0ROVEhqfyphqcxsQUsUiqwzU3TXucQ0ox/WgsxERn7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JCyl/PVyS0Srbl8IPn7JsgUCS7S02KOnVzukQ7PTc1wBlAZ4mNb7N9EOp90GP9a
35
+ YSREEphg3phQsU9LV4Dlc2Id4gB3W+//c1Ek6TFieKoVemKMkbtB1lgqsEpTCfwh
36
+ oNUg84DlSmZ2z9LKagBVAlDy
37
37
  -----END CERTIFICATE-----
38
- date: 2019-02-09 00:00:00.000000000 Z
38
+ date: 2021-01-28 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
- name: dynarex
41
+ name: dxlite
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.8'
46
+ version: '0.3'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.15
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
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '1.8'
56
+ version: '0.3'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.8.15
59
+ version: 0.3.2
60
60
  description:
61
- email: james@jamesrobertson.eu
61
+ email: digital.robertson@gmail.com
62
62
  executables: []
63
63
  extensions: []
64
64
  extra_rdoc_files: []
@@ -76,14 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 2.1.2
79
+ version: 2.5.3
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.2
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.10
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Dir-to-xml saves a directory listing in the Dynarex XML format
metadata.gz.sig CHANGED
Binary file