fsinv 0.1.2 → 0.1.3
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 +8 -8
- data/README.md +2 -0
- data/bin/fsinv +100 -110
- data/lib/fsinv.rb +1 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjJjNmU0YjVlMzliMjVjNjIxOTUyZGUxYzkxYTA5ZWZlY2YxNDkzNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzZjYzFlYThhMTY2ZTRlZGFjMTQ1M2UxZmY0YWVhY2IzMWE4MDQyYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjM4Yzg1NjZjYmQ2ZjE1ZTBkYjY4ZmYwZTcyYTMwMjA1ODNkMGMyNTkxZmM0
|
10
|
+
YTQzNTMxYzVlZjM3NWIxMThhZmEwZDQ1ZDk5MmFmMTU3ZmNhOGVkY2I4ZjM1
|
11
|
+
NmQzNDAwMWMxMjYyNjYyY2QyOGEzNTExMjI0NjUxODFiZWViNTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTUxM2JhMDc1MGQ4MWI5ZDVkNTczNzUxMGI4ZTRlOTEzYWMzYjhhOGUzNDll
|
14
|
+
YTEzZDVjMGUyM2Q0YmQyMWU4OTc4ZDA0MDNiODQ2YjIzZTkyMWY5ZTk4YTFl
|
15
|
+
YTk4YWM2YzEzN2FiOGU3MWI0MGQ1MzRkZDRmYTdlYzk3MTM0NjE=
|
data/README.md
CHANGED
data/bin/fsinv
CHANGED
@@ -6,9 +6,9 @@ require 'optparse'
|
|
6
6
|
require 'fsinv'
|
7
7
|
|
8
8
|
DEFAULT_NAME = "inventory"
|
9
|
-
USAGE = "Usage: fsinv
|
9
|
+
USAGE = "Usage: fsinv [options] basepath [basepath [...]]"
|
10
10
|
|
11
|
-
Fsinv
|
11
|
+
Fsinv::options = {}
|
12
12
|
OptionParser.new do |opts|
|
13
13
|
opts.banner = USAGE
|
14
14
|
opts.separator ""
|
@@ -39,102 +39,92 @@ OptionParser.new do |opts|
|
|
39
39
|
opts.separator "Specific options:"
|
40
40
|
opts.separator ""
|
41
41
|
|
42
|
-
opts.on("-a", "--all", "Save in all formats to the default destinations.
|
43
|
-
|
44
|
-
|
45
|
-
Fsinv
|
46
|
-
Fsinv
|
47
|
-
Fsinv
|
48
|
-
Fsinv
|
49
|
-
Fsinv
|
42
|
+
opts.on("-a", "--all", "Save in all formats to the default destinations.",
|
43
|
+
"Equal to -b -j -q -x -y. Use -n to change the ",
|
44
|
+
"file names of all inventorys at once.") do |all_flag|
|
45
|
+
Fsinv::options[:binary] = true
|
46
|
+
Fsinv::options[:json] = true
|
47
|
+
Fsinv::options[:db] = true
|
48
|
+
Fsinv::options[:xml] = true
|
49
|
+
Fsinv::options[:yaml] = true
|
50
50
|
end
|
51
|
-
opts.separator ""
|
51
|
+
#opts.separator ""
|
52
52
|
|
53
|
-
opts.on("--binary [FILE]", "Dump
|
54
|
-
|
55
|
-
Fsinv
|
56
|
-
Fsinv.options[:binary_file] = binary_file
|
53
|
+
opts.on("--binary [FILE]", "Dump inventory data in binary format. Default is ~/#{DEFAULT_NAME}.bin") do |binary_file|
|
54
|
+
Fsinv::options[:binary] = true
|
55
|
+
Fsinv::options[:binary_file] = binary_file
|
57
56
|
end
|
58
|
-
opts.separator ""
|
57
|
+
#opts.separator ""
|
59
58
|
|
60
|
-
opts.on("--crc32", "Calculate CRC32 checksum for
|
61
|
-
Fsinv
|
59
|
+
opts.on("--crc32", "Calculate CRC32 checksum for files") do |crc|
|
60
|
+
Fsinv::options[:crc32] = true
|
62
61
|
end
|
63
|
-
opts.separator ""
|
62
|
+
#opts.separator ""
|
64
63
|
|
65
|
-
opts.on("--db [FILE]", "Save inventory as SQLite database.
|
66
|
-
|
67
|
-
Fsinv
|
68
|
-
Fsinv.options[:db_file] = sql_file
|
64
|
+
opts.on("--db [FILE]", "Save inventory as SQLite database. Default is ~/#{DEFAULT_NAME}.db") do |sql_file|
|
65
|
+
Fsinv::options[:db] = true
|
66
|
+
Fsinv::options[:db_file] = sql_file
|
69
67
|
end
|
70
|
-
opts.separator ""
|
68
|
+
#opts.separator ""
|
71
69
|
|
72
|
-
opts.
|
73
|
-
|
74
|
-
|
70
|
+
opts.on("-j", "--json [FILE]", "Save inventory in JSON file format. Default is ~/#{DEFAULT_NAME}.json") do |json_file|
|
71
|
+
Fsinv::options[:json] = true
|
72
|
+
Fsinv::options[:json_file] = json_file
|
75
73
|
end
|
76
|
-
opts.separator ""
|
77
|
-
|
78
|
-
opts.on("-j", "--json [FILE]", "Save inventory in JSON file format.
|
79
|
-
Default destination is ~/#{DEFAULT_NAME}.json") do |json_file|
|
80
|
-
Fsinv.options[:json] = true
|
81
|
-
Fsinv.options[:json_file] = json_file
|
82
|
-
end
|
83
|
-
opts.separator ""
|
74
|
+
#opts.separator ""
|
84
75
|
|
85
|
-
opts.on("--md5", "Calculate MD5 hash for
|
86
|
-
Fsinv
|
76
|
+
opts.on("--md5", "Calculate MD5 hash for files") do |md5|
|
77
|
+
Fsinv::options[:md5] = true
|
87
78
|
end
|
88
|
-
opts.separator ""
|
79
|
+
#opts.separator ""
|
89
80
|
|
90
|
-
opts.on("-n", "--name NAME", "
|
91
|
-
|
92
|
-
|
93
|
-
Fsinv.options[:name] = name
|
81
|
+
opts.on("-n", "--name NAME", "Change outputfile name. Default is '#{DEFAULT_NAME}'.",
|
82
|
+
"Specific targets for file formats will overwrite this.") do |name|
|
83
|
+
Fsinv::options[:name] = name
|
94
84
|
end
|
95
|
-
opts.separator ""
|
85
|
+
#opts.separator ""
|
96
86
|
|
97
87
|
opts.on("-p", "--print FORMAT", [:json, :yaml, :xml], "Print a format to stdout (json|yaml|xml)") do |format|
|
98
|
-
Fsinv
|
99
|
-
Fsinv
|
88
|
+
Fsinv::options[:print] = true
|
89
|
+
Fsinv::options[:print_format] = format
|
100
90
|
end
|
101
|
-
opts.separator ""
|
91
|
+
#opts.separator ""
|
102
92
|
|
103
|
-
opts.on("-s", "--silent", "
|
104
|
-
|
105
|
-
Fsinv.options[:silent] = s
|
93
|
+
opts.on("-s", "--silent", "No output or non-critical error messages will be printed") do |s|
|
94
|
+
Fsinv::options[:silent] = s
|
106
95
|
end
|
107
|
-
opts.separator ""
|
96
|
+
#opts.separator ""
|
108
97
|
|
109
|
-
opts.on("-v", "--verbose", "
|
110
|
-
|
111
|
-
Fsinv.options[:verbose] = v
|
98
|
+
opts.on("-v", "--verbose", "Output processed filenames and non-critical errors too") do |v|
|
99
|
+
Fsinv::options[:verbose] = v
|
112
100
|
end
|
113
|
-
opts.separator ""
|
101
|
+
#opts.separator ""
|
102
|
+
|
103
|
+
opts.on("--xml [FILE]", "Save inventory in XML file format. Default is ~/#{DEFAULT_NAME}.xml") do |xml_file|
|
104
|
+
Fsinv::options[:xml] = true
|
105
|
+
Fsinv::options[:xml_file] = xml_file
|
106
|
+
end
|
107
|
+
#opts.separator ""
|
108
|
+
|
109
|
+
opts.on("--yaml [FILE]", "Save inventory in YAML file format. Default is ~/#{DEFAULT_NAME}.yaml") do |yaml_file|
|
110
|
+
Fsinv::options[:yaml] = true
|
111
|
+
Fsinv::options[:yaml_file] = yaml_file
|
112
|
+
end
|
113
|
+
#opts.separator ""
|
114
114
|
|
115
115
|
opts.on_tail("--version", "Show version") do
|
116
116
|
puts ::Version.join('.')
|
117
117
|
exit
|
118
118
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
Fsinv.options[:xml] = true
|
124
|
-
Fsinv.options[:xml_file] = xml_file
|
125
|
-
end
|
126
|
-
opts.separator ""
|
127
|
-
|
128
|
-
opts.on("--yaml [FILE]", "Save inventory in YAML file format.
|
129
|
-
Default destination is ~/#{DEFAULT_NAME}.yaml") do |yaml_file|
|
130
|
-
Fsinv.options[:yaml] = true
|
131
|
-
Fsinv.options[:yaml_file] = yaml_file
|
119
|
+
|
120
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
121
|
+
puts opts
|
122
|
+
exit
|
132
123
|
end
|
133
|
-
opts.separator ""
|
134
124
|
|
135
125
|
end.parse! # do the parsing. do it now!
|
136
126
|
|
137
|
-
#p Fsinv
|
127
|
+
#p Fsinv::options
|
138
128
|
#p ARGV
|
139
129
|
|
140
130
|
if ARGV[0].nil?
|
@@ -151,7 +141,7 @@ ARGV.each do |arg|
|
|
151
141
|
end
|
152
142
|
end
|
153
143
|
|
154
|
-
if Fsinv
|
144
|
+
if Fsinv::options[:crc32]
|
155
145
|
begin
|
156
146
|
require 'digest/crc32'
|
157
147
|
rescue
|
@@ -161,7 +151,7 @@ if Fsinv.options[:crc32]
|
|
161
151
|
end
|
162
152
|
end
|
163
153
|
|
164
|
-
if Fsinv
|
154
|
+
if Fsinv::options[:md5]
|
165
155
|
begin
|
166
156
|
require 'digest/md5'
|
167
157
|
rescue
|
@@ -178,7 +168,7 @@ end
|
|
178
168
|
|
179
169
|
inventory = Fsinv::Inventory.new(file_structure)
|
180
170
|
|
181
|
-
unless Fsinv
|
171
|
+
unless Fsinv::options[:silent]
|
182
172
|
file_structure.each do |fs_tree|
|
183
173
|
size = fs_tree.bytes
|
184
174
|
puts "basepath: #{fs_tree.path}"
|
@@ -195,18 +185,18 @@ unless Fsinv.options[:silent]
|
|
195
185
|
end
|
196
186
|
|
197
187
|
# this is the default output
|
198
|
-
unless (Fsinv
|
199
|
-
if Fsinv
|
200
|
-
Fsinv
|
201
|
-
if Fsinv
|
188
|
+
unless (Fsinv::options[:binary] || Fsinv::options[:db] || Fsinv::options[:xml] || Fsinv::options[:yaml]) && Fsinv::options[:json].nil?
|
189
|
+
if Fsinv::options[:json_file].nil?
|
190
|
+
Fsinv::options[:json_file] = File.join(Dir.home,
|
191
|
+
if Fsinv::options[:name].nil?
|
202
192
|
"#{DEFAULT_NAME}.json"
|
203
193
|
else
|
204
|
-
"#{Fsinv
|
194
|
+
"#{Fsinv::options[:name]}.json"
|
205
195
|
end
|
206
196
|
)
|
207
197
|
end
|
208
198
|
|
209
|
-
puts "writing JSON to #{Fsinv
|
199
|
+
puts "writing JSON to #{Fsinv::options[:json_file]}" unless Fsinv::options[:silent]
|
210
200
|
|
211
201
|
begin
|
212
202
|
require 'json'
|
@@ -225,7 +215,7 @@ unless (Fsinv.options[:binary] || Fsinv.options[:db] || Fsinv.options[:xml] || F
|
|
225
215
|
|
226
216
|
unless json_data.nil?
|
227
217
|
begin
|
228
|
-
file = File.open(Fsinv
|
218
|
+
file = File.open(Fsinv::options[:json_file], 'w')
|
229
219
|
file.write(json_data)
|
230
220
|
rescue
|
231
221
|
puts "error writing JSON file"
|
@@ -238,21 +228,21 @@ unless (Fsinv.options[:binary] || Fsinv.options[:db] || Fsinv.options[:xml] || F
|
|
238
228
|
end
|
239
229
|
end
|
240
230
|
|
241
|
-
if Fsinv
|
242
|
-
if Fsinv
|
243
|
-
Fsinv
|
244
|
-
if Fsinv
|
231
|
+
if Fsinv::options[:yaml]
|
232
|
+
if Fsinv::options[:yaml_file].nil?
|
233
|
+
Fsinv::options[:yaml_file] = File.join(Dir.home,
|
234
|
+
if Fsinv::options[:name].nil?
|
245
235
|
"#{DEFAULT_NAME}.yaml"
|
246
236
|
else
|
247
|
-
"#{Fsinv
|
237
|
+
"#{Fsinv::options[:name]}.yaml"
|
248
238
|
end
|
249
239
|
)
|
250
240
|
end
|
251
|
-
puts "writing YAML to #{Fsinv
|
241
|
+
puts "writing YAML to #{Fsinv::options[:yaml_file]}" unless Fsinv::options[:silent]
|
252
242
|
yaml_data = Fsinv.inventory_to_yaml(inventory)
|
253
243
|
unless yaml_data.nil?
|
254
244
|
begin
|
255
|
-
file = File.open(Fsinv
|
245
|
+
file = File.open(Fsinv::options[:yaml_file], 'w')
|
256
246
|
file.write(yaml_data)
|
257
247
|
rescue
|
258
248
|
puts "error writing YAML file"
|
@@ -262,19 +252,19 @@ if Fsinv.options[:yaml]
|
|
262
252
|
end
|
263
253
|
end
|
264
254
|
|
265
|
-
if Fsinv
|
266
|
-
if Fsinv
|
267
|
-
Fsinv
|
268
|
-
if Fsinv
|
255
|
+
if Fsinv::options[:binary]
|
256
|
+
if Fsinv::options[:binary_file].nil?
|
257
|
+
Fsinv::options[:binary_file] = File.join(Dir.home,
|
258
|
+
if Fsinv::options[:name].nil?
|
269
259
|
"#{DEFAULT_NAME}.bin"
|
270
260
|
else
|
271
|
-
"#{Fsinv
|
261
|
+
"#{Fsinv::options[:name]}.bin"
|
272
262
|
end
|
273
263
|
)
|
274
264
|
end
|
275
|
-
puts "writing binary dump to #{Fsinv
|
265
|
+
puts "writing binary dump to #{Fsinv::options[:binary_file]}" unless Fsinv::options[:silent]
|
276
266
|
begin
|
277
|
-
file = File.open(Fsinv
|
267
|
+
file = File.open(Fsinv::options[:binary_file], 'wb')
|
278
268
|
file.write(Marshal.dump(inventory))
|
279
269
|
rescue
|
280
270
|
puts "error writing binary dump file"
|
@@ -283,19 +273,19 @@ if Fsinv.options[:binary]
|
|
283
273
|
end
|
284
274
|
end
|
285
275
|
|
286
|
-
if Fsinv
|
287
|
-
if Fsinv
|
288
|
-
Fsinv
|
289
|
-
if Fsinv
|
276
|
+
if Fsinv::options[:db]
|
277
|
+
if Fsinv::options[:db_file].nil?
|
278
|
+
Fsinv::options[:db_file] = File.join(Dir.home,
|
279
|
+
if Fsinv::options[:name].nil?
|
290
280
|
"#{DEFAULT_NAME}.db"
|
291
281
|
else
|
292
|
-
"#{Fsinv
|
282
|
+
"#{Fsinv::options[:name]}.db"
|
293
283
|
end
|
294
284
|
)
|
295
285
|
end
|
296
286
|
|
297
|
-
puts "writing database dump to #{Fsinv
|
298
|
-
`rm #{Fsinv
|
287
|
+
puts "writing database dump to #{Fsinv::options[:db_file]}" unless Fsinv::options[:silent]
|
288
|
+
`rm #{Fsinv::options[:db_file]}` if File.exists?(Fsinv::options[:db_file])
|
299
289
|
|
300
290
|
begin
|
301
291
|
|
@@ -303,7 +293,7 @@ if Fsinv.options[:db]
|
|
303
293
|
|
304
294
|
ActiveRecord::Base.establish_connection(
|
305
295
|
:adapter => "sqlite3",
|
306
|
-
:database => Fsinv
|
296
|
+
:database => Fsinv::options[:db_file]
|
307
297
|
)
|
308
298
|
|
309
299
|
ActiveRecord::Schema.define do
|
@@ -381,25 +371,25 @@ if Fsinv.options[:db]
|
|
381
371
|
end
|
382
372
|
end
|
383
373
|
|
384
|
-
if Fsinv
|
385
|
-
if Fsinv
|
386
|
-
Fsinv
|
387
|
-
if Fsinv
|
374
|
+
if Fsinv::options[:xml]
|
375
|
+
if Fsinv::options[:xml_file].nil?
|
376
|
+
Fsinv::options[:xml_file] = File.join(Dir.home,
|
377
|
+
if Fsinv::options[:name].nil?
|
388
378
|
"#{DEFAULT_NAME}.xml"
|
389
379
|
else
|
390
|
-
"#{Fsinv
|
380
|
+
"#{Fsinv::options[:name]}.xml"
|
391
381
|
end
|
392
382
|
)
|
393
383
|
end
|
394
384
|
|
395
|
-
puts "writing XML to #{Fsinv
|
385
|
+
puts "writing XML to #{Fsinv::options[:xml_file]}" unless Fsinv::options[:silent]
|
396
386
|
|
397
387
|
#$progressbar = ProgressBar.new(inventory.file_structure.inject{ |arr,item| arr + item.item_count }, :bar, :counter)
|
398
388
|
xml_data = Fsinv.inventory_to_xml(inventory)
|
399
389
|
|
400
390
|
unless xml_data.nil?
|
401
391
|
begin
|
402
|
-
file = File.open(Fsinv
|
392
|
+
file = File.open(Fsinv::options[:xml_file], 'w')
|
403
393
|
file.write(xml_data)
|
404
394
|
rescue
|
405
395
|
puts "error writing XML file"
|
@@ -409,8 +399,8 @@ if Fsinv.options[:xml]
|
|
409
399
|
end
|
410
400
|
end
|
411
401
|
|
412
|
-
if Fsinv
|
413
|
-
print_data = case Fsinv
|
402
|
+
if Fsinv::options[:print]
|
403
|
+
print_data = case Fsinv::options[:print_format]
|
414
404
|
when :json then Fsinv.inventory_to_json(inventory)
|
415
405
|
when :xml then Fsinv.inventory_to_xml(inventory)
|
416
406
|
when :yaml then Fsinv.inventory_to_yaml(inventory)
|
data/lib/fsinv.rb
CHANGED
@@ -31,7 +31,7 @@ end
|
|
31
31
|
|
32
32
|
module Fsinv
|
33
33
|
|
34
|
-
VERSION = '0.1.
|
34
|
+
VERSION = '0.1.3'
|
35
35
|
|
36
36
|
# Kibibyte, Mebibyte, Gibibyte, etc... all the IEC sizes
|
37
37
|
BYTES_IN_KiB = 2**10
|
@@ -105,7 +105,6 @@ module Fsinv
|
|
105
105
|
return "#{bytes} B"
|
106
106
|
end
|
107
107
|
|
108
|
-
#returns DirectoryDefinition object
|
109
108
|
def parse(folder_path, reduced_scan = false)
|
110
109
|
|
111
110
|
if IGNORE_FILES.include?(File.basename(folder_path))
|