dir-to-xml 0.6.2 → 0.7.0

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
  SHA1:
3
- metadata.gz: 4998b6d46270e28da59d130d05325abac6f47dcd
4
- data.tar.gz: 572ff620f7843bb58fed25581a7b13c5e20b1f3a
3
+ metadata.gz: 7fa7c3734845467a3d98751753c039b7fe4aadcf
4
+ data.tar.gz: 291e33ee74d2bac3a424d9872fb00adea0c3de1f
5
5
  SHA512:
6
- metadata.gz: cb3856faa4719d8327937a5740d78d61ed3c1e70d2ccc14d514b63a1a03a5c2c34b307262a0074121899d5581eeea07061479dd00844495088075b7953e75a31
7
- data.tar.gz: 439244faafb626edd247aaf4c7a706fa28fee7547e1e29d87411d7f7b3075b1a620718c78ecb4bc30dbe02aebe855c03fb2892761deb3219b3cd41adfc587817
6
+ metadata.gz: a75b46bf2769935e624aa30b7c32aff05c491fb7ef80a11813b037b8d70c23b4e7d323666bd469ee935d8dbd0d003540c018f54e1de0f67a1492321ba1e9d298
7
+ data.tar.gz: 9d4e8ee319557c9a880768721b7b53f9a2c31f9411cda7757829bc0931f8dc4f22deacb1a043ecf708945d73fb407504180dbbdad573767ffad59167acaa44af
Binary file
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- ��ݼ���ҙ�go5!�i]0��S]R #lW.
2
- �l�x����d9'^?�wڗ戩�MVv6�'y�-��qK7� K(�6Ȼ_�����4���f.�%���ݻӛyơ�ݟ8㡒��"T,��MW��lq��_�v��,m�ˡBᲾ�p ~��}��&�t����':6�i�umJ��
3
- ��L�-���i'�A�M��ח�
4
- /�t�6F�Z,���+�� �^�%����N8.A���Ƴ��k��]k�Dx����
1
+ G��.3:CN:�Ƃ� aw&#v2�� #�� ���1_��dKt�z�y@HC�u�H�%&�m��7�jI�A���n�
@@ -4,9 +4,9 @@
4
4
 
5
5
  require 'dynarex'
6
6
 
7
+
7
8
  class DirToXML
8
9
 
9
- attr_reader :status
10
10
 
11
11
  def initialize(path= '.', recursive: false)
12
12
  super()
@@ -16,17 +16,33 @@ class DirToXML
16
16
  Dir.chdir path
17
17
 
18
18
  a = Dir.glob("*").sort
19
+ a.delete 'dir.xml'
20
+
21
+ a2 = a.inject([]) do |r, x|
19
22
 
20
- command = a.include?('dir.xml') ? 'run' : 'new_run'
21
- @doc, @status = self.send command, a
23
+ r << {
24
+ name: x,
25
+ type: File::ftype(x),
26
+ ext: File.extname(x),
27
+ created: File::ctime(x),
28
+ last_modified: File::mtime(x),
29
+ last_accessed: File::atime(x)
30
+ }
22
31
 
23
- Dir.chdir old_path #File.expand_path('~')
24
- @h = self.to_dynarex.to_h
32
+ end
33
+
34
+ command = File.exists?('dir.xml') ? :refresh : :dxify
35
+
36
+ @dx = self.method(command).call a2
37
+
38
+ Dir.chdir old_path
39
+
40
+ @h = @dx.to_h
25
41
  @object = @h
26
42
 
27
43
  @path = path
28
44
  @recursive = recursive
29
-
45
+
30
46
  end
31
47
 
32
48
  def filter(pattern=/.*/)
@@ -75,102 +91,45 @@ class DirToXML
75
91
  @object || @h
76
92
  end
77
93
 
78
- def to_xml
79
- @doc.to_s
94
+ def to_xml(options=nil)
95
+ @dx.to_xml options
80
96
  end
81
97
 
82
98
  def to_dynarex
83
- Dynarex.new @doc.to_s
99
+ @dx.clone
84
100
  end
85
101
 
86
102
  private
87
103
 
88
- def new_element(name, text=nil)
89
- new_node = Rexle::Element.new(name)
90
- new_node.text = text if text
91
- new_node
92
- end
104
+ def dxify(a)
105
+
106
+ dx = Dynarex.new 'directory[title,file_path]/file(name, ' + \
107
+ 'type, ext, created, last_modified, last_accessed,' + \
108
+ ' description, owner, group, permissions)'
93
109
 
94
- def new_file(name, type, ext, ctime, mtime, atime)
95
- node = Rexle::Element.new('file')
96
- node.add_element new_element('name', name)
97
- node.add_element new_element('type', type)
98
- node.add_element new_element('ext', ext)
99
- node.add_element new_element('created', ctime)
100
- node.add_element new_element('last_modified', mtime)
101
- node.add_element new_element('last_accessed', atime)
102
- node.add_element new_element('description')
103
- node.add_element new_element('owner')
104
- node.add_element new_element('group')
105
- node.add_element new_element('permissions')
106
- node
107
- end
110
+ dx.title = 'Index of ' + File.basename(Dir.pwd)
111
+ dx.file_path = Dir.pwd
108
112
 
109
- def add_files(doc, a)
113
+ dx.import a
114
+ dx.save 'dir.xml'
110
115
 
111
- dir_files = a.map do |x|
112
- [x, File.extname(x), File::ftype(x), File::ctime(x), \
113
- File::mtime(x), File::atime(x)]
114
- end
115
-
116
- records = doc.root.element('records')
117
- i = '0'
116
+ return dx
118
117
 
119
- dir_files.each do |name, ext, type, ctime, mtime, atime|
120
- records.add_element new_file(name, type, ext, ctime, mtime, atime)
121
- i.succ!
122
- end
123
118
  end
124
119
 
125
- def new_run(a)
120
+ def refresh(cur_files)
126
121
 
127
- summary = "
128
- <summary>
129
- <title>Index of #{File.basename(Dir.pwd)}</title>
130
- <file_path>#{File.dirname(Dir.pwd)}</file_path>
131
- <recordx_type>dynarex</recordx_type>
132
- <schema>directory[title,file_path]/file(name, type, ext, created, " \
133
- + "last_modified, last_accessed, description, owner, group, permissions)" \
134
- + "</schema>\n</summary>"
122
+ dx = Dynarex.new 'dir.xml'
135
123
 
136
- buffer = "<directory>%s<records/></directory>" % summary
137
- doc = Rexle.new(buffer)
138
- add_files(doc, a)
139
-
140
- doc.root.element('records').add_element new_file(name='dir.xml', type=nil, ext='.xml', *[Time.now] * 3)
141
-
142
- File.open('dir.xml','w'){|f| f.write doc.xml pretty: false}
143
- [doc, "created"]
144
- end
145
-
146
- def run(a)
147
-
148
- doc = Rexle.new(File.open('dir.xml','r').read)
149
-
150
- doc.root.xpath('records/file').each do |x|
151
- x.element('last_modified').text = File.mtime x.text('name') if File.exists?(x.text('name'))
152
- end
153
-
154
- a_dir = doc.root.xpath('records/file/name/text()').sort
155
-
156
- if a == a_dir then
157
- File.open('dir.xml','w'){|f| doc.write f}
158
- return [doc, "nothing new"]
124
+ prev_files = dx.to_a
125
+
126
+ cur_files.each do |x|
127
+ file = prev_files.find {|item| item[:name] == x[:name] }
128
+ x[:description] = file[:description] if file and file[:description]
159
129
  end
160
130
 
161
- # files to add
162
- files_to_insert = a - a_dir
163
- add_files(doc, files_to_insert)
131
+ dxify(cur_files)
164
132
 
165
- # files to delete
166
- files_to_delete = a_dir - a
167
-
168
- files_to_delete.each do |filename|
169
- node = doc.root.element("records/file[name='#{filename}']")
170
- node.delete
171
- end
172
-
173
- File.write 'dir.xml', doc.xml(pretty: true)
174
- [doc, "updated"]
175
133
  end
176
- end
134
+
135
+ end
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.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  iqgRYucyTfq3VLTy6wrGN2HJj8unXh4JIFjyEvR3yvcCYl6IaHxuDfgoDfBI6MeQ
32
32
  Em7HctRLQorltw==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-09-22 00:00:00.000000000 Z
34
+ date: 2015-12-18 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
@@ -39,20 +39,20 @@ dependencies:
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '1.5'
42
+ version: '1.6'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 1.5.33
45
+ version: 1.6.2
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '1.5'
52
+ version: '1.6'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 1.5.33
55
+ version: 1.6.2
56
56
  description:
57
57
  email: james@r0bertson.co.uk
58
58
  executables: []
metadata.gz.sig CHANGED
Binary file