dir-to-xml 0.9.2 → 1.0.1

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
- SHA1:
3
- metadata.gz: 59219ab2db1951fd62a36a833fbc4253961bbb4c
4
- data.tar.gz: 8ac53b24217951922458f98b8e903b91140058c6
2
+ SHA256:
3
+ metadata.gz: 6d3847feaade1ff658c8dda0403e10b0a98c6350333b01fc4048e97d86cdcd0d
4
+ data.tar.gz: 99a0cad18703df51c90405b585a2aeab5820dca22b52d27acba5dc96dc5e1bb8
5
5
  SHA512:
6
- metadata.gz: ad02c21b2b1173e6511271987465625c3127961a183a07b623ef55570b907dbbb101c817cca5cb1a48d1647c6cdcc747aa360e8314ff2740fb25b449224457a0
7
- data.tar.gz: 20646cc68aa7aefe2b6e102e4ac391712d69f492eb9e20c567689b2e3143eb350e2871e8bc9884c3fe405dac036b27686515596e05095a0f6b4460337ca25ffc
6
+ metadata.gz: 37bee8d677c8a5801715d92d2d0617be2d8b559244d4f58b0d0b6fb0cef37f0e803d1a76214dcc92b09012a6fe5d15b51bfe0949feb0bdaa3af6d9e53721d515
7
+ data.tar.gz: 60d691388d4e8f46f15307b50e01f4358fad88ced3f6656d29b8be9e1fa408a256f20f641146b8d375041800952818ed752d78043b79d03e4bae93868781d979
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,18 +2,20 @@
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
+ if x.is_a? DxLite then
17
19
 
18
20
  @dx = x
19
21
  @a = @dx.to_a
@@ -27,9 +29,20 @@ class DirToXML
27
29
  @path, @index, @recursive = path, index, recursive
28
30
 
29
31
  raise "Directory not found." unless File.exists? path
32
+
33
+ @dx = DxLite.new(File.join(@path, @index), debug: @debug)
30
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
+
31
44
  a = Dir.glob(File.join(path, "*")).map{|x| File.basename(x) }.sort
32
-
45
+
33
46
  a.delete index
34
47
 
35
48
  a2 = a.inject([]) do |r, filename|
@@ -50,6 +63,23 @@ class DirToXML
50
63
  end
51
64
 
52
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
+
53
83
 
54
84
  command = File.exists?(File.join(path, index)) ? :refresh : :dxify
55
85
 
@@ -74,15 +104,19 @@ class DirToXML
74
104
  @dx.filter &blk
75
105
  end
76
106
 
77
- def filter_by(pattern=/.*/, type: nil)
107
+ def filter_by(pattern=/.*/, type: nil, ext: nil)
78
108
 
79
109
  @object = @a.select do |x|
80
110
 
81
111
  pattern_match = x[:name] =~ pattern
112
+
82
113
  type_match = type ? x[:type] == type.to_s : true
114
+ ext_match = ext ? x[:ext] == ext.to_s : true
115
+
116
+ pattern_match and type_match and ext_match
83
117
 
84
118
  end
85
-
119
+
86
120
  self
87
121
  end
88
122
 
@@ -113,12 +147,15 @@ class DirToXML
113
147
  @dx.save File.join(@path, @index)
114
148
  end
115
149
 
116
- def select_by_ext(ext)
150
+ def select_by_ext(ext, &blk)
151
+
152
+ @object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}$/]} : @a
153
+ return if @object.empty?
117
154
 
118
- @object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}/]} : @a
119
- dx = Dynarex.new json_out: false
155
+ dx = DxLite.new
120
156
  dx.import @object
121
- DirToXML.new(dx)
157
+ dtx = DirToXML.new(dx)
158
+ block_given? ? dtx.dx.all.map(&:name).each(&blk) : dtx
122
159
  end
123
160
 
124
161
  def sort_by(sym)
@@ -149,17 +186,20 @@ class DirToXML
149
186
  @dx.clone
150
187
  end
151
188
 
189
+ alias to_dx to_dynarex
190
+
152
191
  private
153
192
 
154
193
  def dxify(a)
155
194
 
156
- dx = Dynarex.new('directory[title, file_path, description]/file(name, ' + \
195
+ dx = DxLite.new('directory[title, file_path, last_modified, description]/file(name, ' + \
157
196
  'type, ext, ctime, mtime, atime, description, owner, ' + \
158
- 'group, permissions)', json_out: false)
197
+ 'group, permissions)')
159
198
 
160
199
  dx.title = 'Index of ' + File.expand_path(@path)
161
200
  dx.file_path = File.expand_path(@path)
162
-
201
+ dx.last_modified = Time.now.to_s
202
+
163
203
  dx.import a
164
204
 
165
205
  dx.save File.join(@path, @index)
@@ -170,14 +210,18 @@ class DirToXML
170
210
 
171
211
  def refresh(cur_files)
172
212
 
173
- dx = Dynarex.new(File.join(@path, @index), json_out: false)
213
+ puts 'inside refresh' if @debug
214
+
174
215
 
175
- prev_files = dx.to_a
216
+ prev_files = @dx.to_a
217
+
218
+ #puts 'prev_files: ' + prev_files.inspect
219
+ #puts 'cur_files: ' + cur_files.inspect
176
220
 
177
221
  cur_files.each do |x|
178
222
 
179
223
  file = prev_files.find {|item| item[:name] == x[:name] }
180
-
224
+ #puts 'found : ' + file.inspect if @debug
181
225
  x[:description] = file[:description] if file and file[:description]
182
226
  end
183
227
 
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.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,51 +10,55 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE2MDczMTE1MDg0MFoXDTE3MDczMTE1MDg0MFowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAKe0Tx9cyuP49OURT7IiCnuCaeFllrizfGPz71cWJwRwG3tTKgyahn929V6N
19
- 8ALUq10u1g3s1ZtOxhpv0UXj8DkqrV6Y7B37ASrKgfeN8+oKOOYldFlcP0Bixyfp
20
- K7Y1O3xrd66O2qNjtTdD7uTEzOPhLw3SUkO0IkuF+Kqam81fsmAcAIWdROGiD9ax
21
- DL4j7ykZ/AYmi6R8NKrYN637w2sOnkYXufIQ8wx9qibY3HMW5+X21L6gEaFUDeSW
22
- 2m//fkHlxmFN+IICo6DFc5VZKtwQmJVK1HnpKOVtWfsVN4bll7ANy54AxvyPsz0r
23
- AO6/53uNtf6aJXGNkgAoSnRskXMCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
- DwQEAwIEsDAdBgNVHQ4EFgQUaNTA8KT0NF8E1x4S7UJf8EzbHJYwJgYDVR0RBB8w
25
- HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2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000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
- name: dynarex
41
+ name: dxlite
38
42
  requirement: !ruby/object:Gem::Requirement
39
43
  requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1.7'
43
44
  - - ">="
44
45
  - !ruby/object:Gem::Version
45
- version: 1.7.22
46
+ version: 0.3.0
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.3'
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '1.7'
53
54
  - - ">="
54
55
  - !ruby/object:Gem::Version
55
- version: 1.7.22
56
+ version: 0.3.0
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.3'
56
60
  description:
57
- email: james@jamesrobertson.eu
61
+ email: digital.robertson@gmail.com
58
62
  executables: []
59
63
  extensions: []
60
64
  extra_rdoc_files: []
@@ -72,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
76
  requirements:
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: 2.1.2
79
+ version: 2.5.3
76
80
  required_rubygems_version: !ruby/object:Gem::Requirement
77
81
  requirements:
78
82
  - - ">="
@@ -80,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
84
  version: '0'
81
85
  requirements: []
82
86
  rubyforge_project:
83
- rubygems_version: 2.6.8
87
+ rubygems_version: 2.7.10
84
88
  signing_key:
85
89
  specification_version: 4
86
90
  summary: Dir-to-xml saves a directory listing in the Dynarex XML format
metadata.gz.sig CHANGED
Binary file