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.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +2 -0
  3. data/bin/fsinv +100 -110
  4. data/lib/fsinv.rb +1 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzM2OGFhZGJlOWI5MmRjZDQyOWE4Y2E1NjgyYjk1ZDMxZTA3ZDVjMw==
4
+ YjJjNmU0YjVlMzliMjVjNjIxOTUyZGUxYzkxYTA5ZWZlY2YxNDkzNQ==
5
5
  data.tar.gz: !binary |-
6
- YWU5MjBiMDc5NTgzMDI5OWZlZDM4NDBkYmZhNTQ1Mjk2M2EyZmY3NQ==
6
+ MzZjYzFlYThhMTY2ZTRlZGFjMTQ1M2UxZmY0YWVhY2IzMWE4MDQyYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWY5ZDk3NTJkMTVkYTYzOGU2ZTFiNDdhNjNmZjk1ZWJkNzczNjcyYmNiN2U4
10
- NzUxNWQzYzcwYzcwMmEyYTM3MTQ1ZTM5NWVjM2EyN2NkY2UzMzdkYTU3NDUx
11
- YTRkOWM5MDFjYjNmOGRlZmI5N2E3OGI5N2FjY2E5ZjM4ZDgzZWE=
9
+ YjM4Yzg1NjZjYmQ2ZjE1ZTBkYjY4ZmYwZTcyYTMwMjA1ODNkMGMyNTkxZmM0
10
+ YTQzNTMxYzVlZjM3NWIxMThhZmEwZDQ1ZDk5MmFmMTU3ZmNhOGVkY2I4ZjM1
11
+ NmQzNDAwMWMxMjYyNjYyY2QyOGEzNTExMjI0NjUxODFiZWViNTE=
12
12
  data.tar.gz: !binary |-
13
- MjRhMzFjNDY0NjcwZjNiNTRmMDVmYzUxZDE4MjJjZDUxMTNhZTUwMjc4NzIw
14
- ZTAyNThiZTU1NWY4MWVjNDgyNTA2MDMwOGFhNDY3NTA0YWYwYzIzMjk5ZGI5
15
- M2QzMjM5ODliMzFlNzIzYmYzZDRjN2I2YTVjMjZlOWY0YWEyZWI=
13
+ ZTUxM2JhMDc1MGQ4MWI5ZDVkNTczNzUxMGI4ZTRlOTEzYWMzYjhhOGUzNDll
14
+ YTEzZDVjMGUyM2Q0YmQyMWU4OTc4ZDA0MDNiODQ2YjIzZTkyMWY5ZTk4YTFl
15
+ YTk4YWM2YzEzN2FiOGU3MWI0MGQ1MzRkZDRmYTdlYzk3MTM0NjE=
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # fsinv: file system inventory tool
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/fsinv.svg)](http://badge.fury.io/rb/fsinv)
4
+
3
5
  imagine a very detailed README message here (please?)
4
6
 
5
7
  ## Installation
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 basepath1 [basepath2 [basepath3 [...]]] [options]"
9
+ USAGE = "Usage: fsinv [options] basepath [basepath [...]]"
10
10
 
11
- Fsinv.options = {}
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
- Equal to -b -j -q -x -y. Use -n to change the
44
- file names of all target 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
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 iventory data stuctures in binary format.
54
- Default destination is ~/#{DEFAULT_NAME}.bin") do |binary_file|
55
- Fsinv.options[:binary] = true
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 each file") do |crc|
61
- Fsinv.options[:crc32] = true
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
- Default destination is ~/#{DEFAULT_NAME}.db") do |sql_file|
67
- Fsinv.options[:db] = true
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.on_tail("-h", "--help", "Show this message") do
73
- puts opts
74
- exit
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 each file") do |md5|
86
- Fsinv.options[:md5] = true
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", "This will change the name of the output files.
91
- Default is '#{DEFAULT_NAME}'. Specific targets for
92
- file formats will overwrite this.") do |name|
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.options[:print] = true
99
- Fsinv.options[:print_format] = format
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", "Run in silent mode. No output or non-critical
104
- error messages will be printed") do |s|
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", "Run verbosely. This will output processed
110
- filenames and error messages too") do |v|
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
- opts.separator ""
120
-
121
- opts.on("--xml [FILE]", "Save inventory in XML file format.
122
- Default destination is ~/#{DEFAULT_NAME}.xml") do |xml_file|
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.options
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.options[:crc32]
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.options[:md5]
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.options[:silent]
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.options[:binary] || Fsinv.options[:db] || Fsinv.options[:xml] || Fsinv.options[:yaml]) && Fsinv.options[:json].nil?
199
- if Fsinv.options[:json_file].nil?
200
- Fsinv.options[:json_file] = File.join(Dir.home,
201
- if Fsinv.options[:name].nil?
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.options[:name]}.json"
194
+ "#{Fsinv::options[:name]}.json"
205
195
  end
206
196
  )
207
197
  end
208
198
 
209
- puts "writing JSON to #{Fsinv.options[:json_file]}" unless Fsinv.options[:silent]
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.options[:json_file], 'w')
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.options[:yaml]
242
- if Fsinv.options[:yaml_file].nil?
243
- Fsinv.options[:yaml_file] = File.join(Dir.home,
244
- if Fsinv.options[:name].nil?
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.options[:name]}.yaml"
237
+ "#{Fsinv::options[:name]}.yaml"
248
238
  end
249
239
  )
250
240
  end
251
- puts "writing YAML to #{Fsinv.options[:yaml_file]}" unless Fsinv.options[:silent]
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.options[:yaml_file], 'w')
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.options[:binary]
266
- if Fsinv.options[:binary_file].nil?
267
- Fsinv.options[:binary_file] = File.join(Dir.home,
268
- if Fsinv.options[:name].nil?
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.options[:name]}.bin"
261
+ "#{Fsinv::options[:name]}.bin"
272
262
  end
273
263
  )
274
264
  end
275
- puts "writing binary dump to #{Fsinv.options[:binary_file]}" unless Fsinv.options[:silent]
265
+ puts "writing binary dump to #{Fsinv::options[:binary_file]}" unless Fsinv::options[:silent]
276
266
  begin
277
- file = File.open(Fsinv.options[:binary_file], 'wb')
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.options[:db]
287
- if Fsinv.options[:db_file].nil?
288
- Fsinv.options[:db_file] = File.join(Dir.home,
289
- if Fsinv.options[:name].nil?
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.options[:name]}.db"
282
+ "#{Fsinv::options[:name]}.db"
293
283
  end
294
284
  )
295
285
  end
296
286
 
297
- puts "writing database dump to #{Fsinv.options[:db_file]}" unless Fsinv.options[:silent]
298
- `rm #{Fsinv.options[:db_file]}` if File.exists?(Fsinv.options[:db_file])
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.options[:db_file]
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.options[:xml]
385
- if Fsinv.options[:xml_file].nil?
386
- Fsinv.options[:xml_file] = File.join(Dir.home,
387
- if Fsinv.options[:name].nil?
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.options[:name]}.xml"
380
+ "#{Fsinv::options[:name]}.xml"
391
381
  end
392
382
  )
393
383
  end
394
384
 
395
- puts "writing XML to #{Fsinv.options[:xml_file]}" unless Fsinv.options[:silent]
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.options[:xml_file], 'w')
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.options[:print]
413
- print_data = case Fsinv.options[:print_format]
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.2'
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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsinv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximilian Irro