storazzo 0.4.10 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,24 +3,24 @@
3
3
  # module Storazzo
4
4
  # class Storazzo::RicDiskUgly
5
5
  # RICDISK_VERSION = "1.0ugly"
6
- # DEFAULT_MEDIA_DIRS = %w{
7
- # /media/riccardo/
8
- # /Volumes/
9
- # /mnt/
6
+ # DEFAULT_MEDIA_DIRS = %w{
7
+ # /media/riccardo/
8
+ # /Volumes/
9
+ # /mnt/
10
10
  # ~/storazzo/var/test/disks/
11
11
  # }.append(Storazzo.root + "/var/test/disks/")
12
12
 
13
13
  # include Hashify
14
14
  # extend Storazzo::Colors
15
-
15
+
16
16
  # # todo substitute with protobuf..
17
17
  # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr
18
-
18
+
19
19
  # def self.interesting_mount_points(opts={})
20
20
  # #https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
21
21
  # `mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '`.split(/\n+/)
22
22
  # end
23
-
23
+
24
24
  # def initialize(path, ricdisk_file)
25
25
  # puts "[DEB] RicDiskUgly initialize.. path=#{path}"
26
26
  # @local_mountpoint = path
@@ -38,15 +38,15 @@
38
38
  # find_info_from_mount(path)
39
39
  # find_info_from_df()
40
40
  # end
41
-
41
+
42
42
  # def ricdisk_absolute_path
43
43
  # @local_mountpoint + "/" + @ricdisk_file
44
44
  # end
45
-
45
+
46
46
  # def add_tag(tag)
47
47
  # @tags += ", #{tag}"
48
48
  # end
49
-
49
+
50
50
  # # might have other things in the future...
51
51
  # def find_info_from_mount(path)
52
52
  # mount_table_lines = interesting_mount_points()
@@ -55,9 +55,9 @@
55
55
  # next if line =~ /^map /
56
56
  # dev, on, mount_path, mode = line.split(/ /)
57
57
  # if mount_path==path
58
- # mount_line = line
58
+ # mount_line = line
59
59
  # else
60
- # @info_from_mount = false
60
+ # @info_from_mount = false
61
61
  # end
62
62
  # end
63
63
  # @info_from_mount = ! (mount_line.nil?)
@@ -69,7 +69,7 @@
69
69
  # add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
70
70
  # end
71
71
  # end
72
-
72
+
73
73
  # def find_info_from_df()
74
74
  # path = @local_mountpoint
75
75
  # df_info = `df -h "#{path}"`
@@ -78,15 +78,13 @@
78
78
  # raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
79
79
  # mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
80
80
  # end
81
-
82
-
83
-
81
+
84
82
  # def self.sbrodola_ricdisk(subdir)
85
83
  # # given a path, if .ricdisk exists i do stuff with it..
86
84
  # disk_info = nil
87
85
  # unless self.ok_dir?(subdir)
88
86
  # puts("Nothing for me here. Existing")
89
- # return
87
+ # return
90
88
  # end
91
89
  # if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
92
90
  # deb("Interesting1. Empty file! Now I write YAML with it.")
@@ -116,12 +114,12 @@
116
114
  # #puts(white `cat "#{subdir}/.ricdisk"`)
117
115
  # end
118
116
  # end
119
-
117
+
120
118
  # # separiamo cosi usiamo meglio...
121
119
  # def self.ok_dir?(subdir)
122
120
  # File.exists?( "#{subdir}/.ricdisk") or File.exists?( "#{subdir}/.ricdisk.yaml")
123
121
  # end
124
-
122
+
125
123
  # def self.obsolescence_seconds file_path
126
124
  # creation_time = File.stat(file_path).ctime
127
125
  # deb("[obsolescence_seconds] File #{file_path}: #{creation_time} - #{(Time.now - creation_time)} seconds ago")
@@ -130,13 +128,13 @@
130
128
  # def self.obsolescence_days(file_path)
131
129
  # return obsolescence_seconds(file_path) / 86400
132
130
  # end
133
-
131
+
134
132
  # def self.backquote_execute(cmd)
135
133
  # # executed a command wrapped by dryrun though
136
134
  # return "DRYRUN backquote_execute(#{cmd})" if $opts[:dryrun]
137
135
  # `#{cmd}`
138
136
  # end
139
-
137
+
140
138
  # def self.upload_to_gcs(file, opts={})
141
139
  # deb("upload_to_gcs(#{file}). TODO(ricc) after breafast upload to GCS : #{file}")
142
140
  # mount_name = file.split('/')[-2]
@@ -152,12 +150,12 @@
152
150
  # # end
153
151
  # ret
154
152
  # end
155
-
153
+
156
154
  # # Create RDS file.
157
155
  # def self.calculate_stats_files(dir, opts={})
158
- # opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
156
+ # opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
159
157
  # full_file_path = "#{dir}/#{$stats_file}"
160
-
158
+
161
159
  # puts("calculate_stats_files(#{white dir}): #{white full_file_path}")
162
160
  # puts "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
163
161
  # Dir.chdir(dir)
@@ -165,23 +163,23 @@
165
163
  # puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
166
164
  # # TODO check for file time...
167
165
  # print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
168
- # if obsolescence_days(full_file_path) > 7
166
+ # if obsolescence_days(full_file_path) > 7
169
167
  # puts("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
170
168
  # end
171
169
  # upload_to_gcs(full_file_path) if opts_upload_to_gcs
172
170
  # else
173
- # puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
171
+ # puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
174
172
  # command = "find . -print0 | xargs -0 stats-with-md5.rb --no-color | tee '#{full_file_path}'"
175
173
  # puts("[#{`pwd`.chomp}] Executing: #{azure command}")
176
174
  # ret = backquote_execute command
177
175
  # puts "Done. #{ret.split("\n").count} files processed."
178
176
  # end
179
177
  # end
180
-
178
+
181
179
  # def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
182
- # base_dirs = DEFAULT_MEDIA_DIRS if base_dirs.nil?
180
+ # base_dirs = DEFAULT_MEDIA_DIRS if base_dirs.nil?
183
181
  # active_dirs = []
184
- # base_dirs.each do |ugly_dir|
182
+ # base_dirs.each do |ugly_dir|
185
183
  # # https://stackoverflow.com/questions/1899072/getting-a-list-of-folders-in-a-directory#:~:text=Dir.chdir(%27/destination_directory%27)%0ADir.glob(%27*%27).select%20%7B%7Cf%7C%20File.directory%3F%20f%7D
186
184
  # dir = File.expand_path(ugly_dir)
187
185
  # begin
@@ -189,12 +187,12 @@
189
187
  # # puts "TEST2 DIR EXISTS: #{dir} -> #{Dir.exists?(dir)}"
190
188
  # unless Dir.exists?(dir)
191
189
  # deb "Dir doesnt exist, skipping: #{dir}"
192
- # next
190
+ # next
193
191
  # end
194
- # Dir.chdir(dir)
192
+ # Dir.chdir(dir)
195
193
  # x = Dir.glob('*').select {|f| File.directory? f}
196
194
  # subdirs = x.map{|subdir| "#{dir}#{subdir}"}
197
- # subdirs.each{|subdir|
195
+ # subdirs.each{|subdir|
198
196
  # #puts `ls -al "#{subdir}"`
199
197
  # active_dirs << subdir if self.ok_dir?(subdir)
200
198
  # }
@@ -204,9 +202,9 @@
204
202
  # ensure # will always get executed
205
203
  # #deb 'Always gets executed.'
206
204
  # #x = []
207
- # end
205
+ # end
208
206
  # end
209
-
207
+
210
208
  # if also_mountpoints
211
209
  # =begin
212
210
  # Example output from mount:
@@ -237,15 +235,14 @@
237
235
  # puts("find_active_dirs(): found dirs " + green(active_dirs))
238
236
  # return active_dirs
239
237
  # end
240
-
241
238
 
242
239
  # def analyze_local_system()
243
- # puts :TODO
240
+ # puts :TODO
244
241
  # puts "1. Interesting Mounts: #{green interesting_mount_points}"
245
242
  # puts "2. Sbrodoling everything: :TODO"
246
243
  # # find_info_from_mount(path)
247
244
  # # find_info_from_df()
248
245
  # end
249
-
246
+
250
247
  # end
251
- # end
248
+ # end
@@ -1,12 +1,12 @@
1
1
  # copied from https://github.com/rails/strong_parameters/edit/master/lib/strong_parameters/version.rb
2
2
  # I;'m copying the DHH philosophy here.
3
3
  module Storazzo
4
- #DHH_VERSION = "0.2.3._TODOFileRead.1" # TODO file.read ../../VERSION . chomp
5
- RICC_VERSION = File.read("../VERSION").chomp
4
+ # DHH_VERSION = "0.2.3._TODOFileRead.1" # TODO file.read ../../VERSION . chomp
5
+ RICC_VERSION = File.read("../VERSION").chomp
6
6
 
7
- public
8
- def self.version
9
- RICC_VERSION
10
- end
7
+ public
8
+
9
+ def self.version
10
+ RICC_VERSION
11
+ end
11
12
  end
12
-
data/lib/storazzo.rb CHANGED
@@ -1,43 +1,43 @@
1
1
  # Inspired from https://guides.rubygems.org/make-your-own-gem/#introduction
2
2
 
3
3
  module Storazzo
4
- #VERSION = File.read('./VERSION').chomp # "10.0.0"
5
- #require 'storazzo/translator'
6
-
7
- def latest_parser_version
8
- "1.2"
9
- end
10
-
11
- # Finds RAILS_ROOT for Storazzo Gem. Copied from:
12
- # https://stackoverflow.com/questions/10132949/finding-the-gem-root
13
- def self.root
14
- File.expand_path '../..', __FILE__
15
- end
16
-
17
- def self.version
18
- File.read(self.root + '/VERSION').chomp # "10.0.0"
19
- end
20
-
21
- # alias_method :VERSION, :version
22
- def self.VERSION
23
- version
24
- end
25
-
26
- def self.storazzo_classes
27
- [42, 43]
28
- end
29
- end
4
+ # VERSION = File.read('./VERSION').chomp # "10.0.0"
5
+ # require 'storazzo/translator'
6
+
7
+ def latest_parser_version
8
+ '1.2'
9
+ end
10
+
11
+ # Finds RAILS_ROOT for Storazzo Gem. Copied from:
12
+ # https://stackoverflow.com/questions/10132949/finding-the-gem-root
13
+ def self.root
14
+ File.expand_path '..', __dir__
15
+ end
16
+
17
+ def self.version
18
+ File.read(root + '/VERSION').chomp # "10.0.0"
19
+ end
20
+
21
+ # alias_method :VERSION, :version
22
+ def self.VERSION
23
+ version
24
+ end
25
+
26
+ def self.storazzo_classes
27
+ [42, 43]
28
+ end
29
+ end
30
30
 
31
31
  # nice to paste nice output
32
32
  require 'pp'
33
- require 'require_all'
34
-
35
- #require_all './' , 'media/'
36
- #require_all 'lib/**/*.rb'
37
- #require_rel '.', 'media'
38
- Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
39
- puts "+ Requiring... #{file}"
40
- require File.basename(file, File.extname(file))
33
+ # require 'require_all'
34
+
35
+ # require_all './' , 'media/'
36
+ # require_all 'lib/**/*.rb'
37
+ # require_rel '.', 'media'
38
+ Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
39
+ puts "+ Requiring... #{file}"
40
+ require File.basename(file, File.extname(file))
41
41
  end
42
42
 
43
43
  require 'storazzo'
@@ -46,11 +46,11 @@ require 'storazzo/colors'
46
46
  require 'storazzo/hashify'
47
47
  require 'storazzo/ric_disk' # NEW and will build from ground up using multiple files..
48
48
  require 'storazzo/media/abstract_ric_disk'
49
- require 'storazzo/media/gcs_bucket'
50
- require 'storazzo/media/local_folder'
51
- require 'storazzo/media/mount_point'
49
+ require 'storazzo/media/gcs_bucket'
50
+ require 'storazzo/media/local_folder'
51
+ require 'storazzo/media/mount_point'
52
52
  require 'storazzo/ric_disk_ugly' # OLD and 90% working
53
- require 'storazzo/ric_disk_config' # => RicDiskConfif
53
+ require 'storazzo/ric_disk_config' # => RicDiskConfif
54
54
  require 'storazzo/ric_disk_sample_config' # => NOTHING!!
55
55
  require 'storazzo/ric_disk_statsfile'
56
56
  require 'storazzo/main'
data/storazzo.gemspec CHANGED
@@ -1,22 +1,23 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = "storazzo"
3
- # TOSDO: copy approach from here to dry version calculating: https://github.com/rails/strong_parameters/blob/master/strong_parameters.gemspec#L15
4
- s.version = File.read("VERSION").chomp # TODO cat version File.read(@,.VERSION).chomp
5
- s.summary = "storazzo is an amazing gem. Code is in https://github.com/palladius/storazzo"
6
- s.description = "A simple gem to manage your external hard drives and extract MD5 and common stuff from them."
7
- s.authors = ["Riccardo Carlesso"]
8
- s.email = "name dot surname at popular Google-owned Mail"
9
- # Autoglob as per https://stackoverflow.com/questions/11873294/determining-the-gems-list-of-files-for-the-specification
10
- s.files = %w(Gemfile LICENSE README.md Makefile Rakefile storazzo.gemspec VERSION) + Dir["{bin,lib,test,var}/**/*"]
11
- s.test_files = Dir["test/**/*"] + Dir["var/test/**/*"]
12
- s.executables = [
13
- # todo: everything in bin/
14
- "ricdisk-magic",
15
- "stats-with-md5",
16
- "hello-storazzo",
17
- ]
18
- s.homepage = "https://rubygems.org/gems/storazzo" # maybe https://github.com/palladius/storazzo
19
- s.license = "MIT"
20
- #s.add_dependency "activesupport", "~> 3.0"
21
- s.add_dependency "pry" # , "~> 3.0"
22
- end
2
+ s.name = "storazzo"
3
+ # TOSDO: copy approach from here to dry version calculating: https://github.com/rails/strong_parameters/blob/master/strong_parameters.gemspec#L15
4
+ s.version = File.read("VERSION").chomp # TODO cat version File.read(@,.VERSION).chomp
5
+ s.summary = "storazzo is an amazing gem. Code is in https://github.com/palladius/storazzo"
6
+ s.description = "A simple gem to manage your external hard drives and extract MD5 and common stuff from them."
7
+ s.authors = ["Riccardo Carlesso"]
8
+ s.email = "name dot surname at popular Google-owned Mail"
9
+ # Autoglob as per https://stackoverflow.com/questions/11873294/determining-the-gems-list-of-files-for-the-specification
10
+ s.files = %w(Gemfile LICENSE README.md Makefile Rakefile storazzo.gemspec
11
+ VERSION) + Dir["{bin,lib,test,var}/**/*"]
12
+ s.test_files = Dir["test/**/*"] + Dir["var/test/**/*"]
13
+ s.executables = [
14
+ # todo: everything in bin/
15
+ "ricdisk-magic",
16
+ "stats-with-md5",
17
+ "hello-storazzo",
18
+ ]
19
+ s.homepage = "https://rubygems.org/gems/storazzo" # maybe https://github.com/palladius/storazzo
20
+ s.license = "MIT"
21
+ # s.add_dependency "activesupport", "~> 3.0"
22
+ s.add_dependency "pry" # , "~> 3.0"
23
+ end
@@ -2,22 +2,18 @@
2
2
  require "minitest/autorun"
3
3
  require "storazzo"
4
4
 
5
-
6
- #require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
7
-
5
+ # require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
8
6
 
9
7
  class AbstractRicDiskTest < Minitest::Test
8
+ include Storazzo::Common
10
9
 
11
- include Storazzo::Common
12
-
13
- def TODO_test_super_duper_list_all_with_type_returns_something
14
- deb "This would be already... something :) it means they're all implemented"
15
- ret = Storazzo::Media::AbstractRicDisk.super_duper_list_all_with_type
16
- assert(
17
- ret.class,
18
- Array,
19
- "test_super_duper_list_all_with_type_returns_something should return an array.."
20
- )
21
- end
22
-
23
- end
10
+ def TODO_test_super_duper_list_all_with_type_returns_something
11
+ deb "This would be already... something :) it means they're all implemented"
12
+ ret = Storazzo::Media::AbstractRicDisk.super_duper_list_all_with_type
13
+ assert(
14
+ ret.class,
15
+ Array,
16
+ "test_super_duper_list_all_with_type_returns_something should return an array.."
17
+ )
18
+ end
19
+ end
@@ -7,55 +7,52 @@ require "storazzo/media/local_folder"
7
7
 
8
8
  require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
9
9
 
10
-
11
10
  class GcsBucketTest < Minitest::Test
12
-
13
- include Storazzo::Common
14
-
15
- def setup # tear_up
16
- deb "[GcsBucketTest] TEAR_UP with sample Config"
17
- #removeme = Storazzo::RicDiskConfig.instance()
18
- $sample_config_obj = Storazzo::RicDiskSampleConfig.instance()
19
- $sample_config_hash = $sample_config_obj.load()
20
- deb "[GcsBucketTest] TEAR_UP config_obj: '''#{$sample_config_obj}'''"
21
- end
22
-
23
- def test_buckets_are_the_two_i_know
24
- # copied from etc/sample.yaml :)
25
- expected_list = %w{
26
- gs://my-local-backup/storazzo/backups/
27
- gs://my-other-bucket/
28
- }
29
- actual_list = Storazzo::RicDisk::GcsBucket.list_all($sample_config_obj)
30
- assert_equal(
31
- expected_list.sort,
32
- actual_list.sort,
33
- "These are the two lists from Sample Storazzo Config")
34
- end
35
-
36
- def test_import_sample_class_correctly
37
- #require "storazzo/ric_disk_sample_config" rescue nil
38
- #require "storazzo/ric_disk_config"
39
-
40
- #puts Storazzo.class
41
- deb " Storazzo.constants: #{ Storazzo.constants}"
42
- #puts Storazzo::RicDiskSampleConfig
43
- #config_obj = Storazzo::RicDiskSampleConfig.instance()
44
- if_deb? do
45
- Pry::ColorPrinter.pp($sample_config_obj.to_verbose_s())
46
- end
47
- #pp green(config_obj.to_verbose_s())
48
-
49
- l = $sample_config_obj.load
50
- Pry::ColorPrinter.pp(l) if $DEBUG
51
-
52
- puts "$sample_config_obj: #{$sample_config_obj}"
53
- #config_obj.load # _sample_version
11
+ include Storazzo::Common
12
+
13
+ def setup # tear_up
14
+ deb "[GcsBucketTest] TEAR_UP with sample Config"
15
+ # removeme = Storazzo::RicDiskConfig.instance()
16
+ $sample_config_obj = Storazzo::RicDiskSampleConfig.instance()
17
+ $sample_config_hash = $sample_config_obj.load()
18
+ deb "[GcsBucketTest] TEAR_UP config_obj: '''#{$sample_config_obj}'''"
19
+ end
20
+
21
+ def test_buckets_are_the_two_i_know
22
+ # copied from etc/sample.yaml :)
23
+ expected_list = %w{
24
+ gs://my-local-backup/storazzo/backups/
25
+ gs://my-other-bucket/
26
+ }
27
+ actual_list = Storazzo::RicDisk::GcsBucket.list_all($sample_config_obj)
28
+ assert_equal(
29
+ expected_list.sort,
30
+ actual_list.sort,
31
+ "These are the two lists from Sample Storazzo Config"
32
+ )
33
+ end
34
+
35
+ def test_import_sample_class_correctly
36
+ # require "storazzo/ric_disk_sample_config" rescue nil
37
+ # require "storazzo/ric_disk_config"
38
+
39
+ # puts Storazzo.class
40
+ deb " Storazzo.constants: #{Storazzo.constants}"
41
+ # puts Storazzo::RicDiskSampleConfig
42
+ # config_obj = Storazzo::RicDiskSampleConfig.instance()
43
+ if_deb? do
44
+ Pry::ColorPrinter.pp($sample_config_obj.to_verbose_s())
54
45
  end
46
+ # pp green(config_obj.to_verbose_s())
55
47
 
48
+ l = $sample_config_obj.load
49
+ Pry::ColorPrinter.pp(l) if $DEBUG
56
50
 
57
- # def teardown
58
- # puts :TEAR_DOWN_TODO
59
- # end
51
+ puts "$sample_config_obj: #{$sample_config_obj}"
52
+ # config_obj.load # _sample_version
53
+ end
60
54
 
61
- end
55
+ # def teardown
56
+ # puts :TEAR_DOWN_TODO
57
+ # end
58
+ end