dir-to-xml 0.6.2 → 0.7.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -4
- data/lib/dir-to-xml.rb +45 -86
- metadata +6 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fa7c3734845467a3d98751753c039b7fe4aadcf
|
4
|
+
data.tar.gz: 291e33ee74d2bac3a424d9872fb00adea0c3de1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a75b46bf2769935e624aa30b7c32aff05c491fb7ef80a11813b037b8d70c23b4e7d323666bd469ee935d8dbd0d003540c018f54e1de0f67a1492321ba1e9d298
|
7
|
+
data.tar.gz: 9d4e8ee319557c9a880768721b7b53f9a2c31f9411cda7757829bc0931f8dc4f22deacb1a043ecf708945d73fb407504180dbbdad573767ffad59167acaa44af
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
|
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:�Ƃ� a�w&#v2�� #�� ���1�_��dK�t�z�y@HC�u�H�%&�m��7�jI�A���n�
|
data/lib/dir-to-xml.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
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
|
-
@
|
94
|
+
def to_xml(options=nil)
|
95
|
+
@dx.to_xml options
|
80
96
|
end
|
81
97
|
|
82
98
|
def to_dynarex
|
83
|
-
|
99
|
+
@dx.clone
|
84
100
|
end
|
85
101
|
|
86
102
|
private
|
87
103
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
95
|
-
|
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
|
-
|
113
|
+
dx.import a
|
114
|
+
dx.save 'dir.xml'
|
110
115
|
|
111
|
-
|
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
|
120
|
+
def refresh(cur_files)
|
126
121
|
|
127
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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.
|
42
|
+
version: '1.6'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
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.
|
52
|
+
version: '1.6'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.6.2
|
56
56
|
description:
|
57
57
|
email: james@r0bertson.co.uk
|
58
58
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|