storazzo 0.3.1 → 0.3.5

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
  SHA256:
3
- metadata.gz: 4db1949b0d85621b95927e0ddf072306267f4f210832d822b4dccbb1ed19d550
4
- data.tar.gz: a50fb6d254c7d9622ad9bfd53caf817bb596a7acc61d153d2422c43ffc5fa51c
3
+ metadata.gz: 9d9055989b612babb7a7d19c5c3edad19504541e1c9f65086e62676041826490
4
+ data.tar.gz: 7747d21ba2b2fc9ad046bc46b4aef95c5ff3ed0f9c3bf08e0d220a8b79725352
5
5
  SHA512:
6
- metadata.gz: 2f861d91797a978925de00623b2228c47c27079aec9e92d979a6e3f87d613f3d50e102436ba54b0b5dfc0cf084c11d8946830cf520b2f5d36f5fa0dc4443ecc9
7
- data.tar.gz: 47424f3327c4ca07e766000f2351bc4866660151a499b5f20392c92539f9f89f89d80f32852486979c4e83be80d34cb1aa30117da51c3dc75703b99f8d42b4b0
6
+ metadata.gz: 14dca4f3c57b21e8a8a7b45a9a8ff6746eca5b53041bab8b5542ecb4343dadac38e575c8a3142aa530eae985d5ada6898881006fe89617533a22dd5f2481385e
7
+ data.tar.gz: 77ac0db74bc3f55ca77ed5d3ae791a0e8e5bf6d0ad34aae8e5bb6ad850797894a6983a6f86de8c4216096a776a8e25bfa4d6a6c40b77f13b69a165e36c378966
data/Makefile CHANGED
@@ -17,6 +17,8 @@ install:
17
17
 
18
18
  push-to-rubygems: build-local test
19
19
  gem push ./storazzo-$(VER).gem
20
+ push-to-rubygems-without-tests: build-local
21
+ gem push ./storazzo-$(VER).gem
20
22
 
21
23
  list:
22
24
  gem list -r storazzo
@@ -46,4 +48,7 @@ irb-test:
46
48
  ./irb-test.sh
47
49
 
48
50
  watch-test:
49
- watch -c make test
51
+ watch -c make test
52
+
53
+ test-gcs-bucket:
54
+ ruby -I test test/test_gcs_bucket.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.5
data/bin/ricdisk-magic CHANGED
@@ -14,17 +14,18 @@ require 'optparse' # http://ruby.about.com/od/advancedruby/a/optionparser.
14
14
 
15
15
  # Including local gem.
16
16
  #puts File.expand_path(FileUtils.pwd, "/../")
17
- local_gem_path = File.expand_path(FileUtils.pwd, "/../")
18
- gem 'storazzo', path: local_gem_path
17
+ #local_gem_path = File.expand_path(FileUtils.pwd, "/../")
18
+ #gem 'storazzo', path: local_gem_path
19
19
  require 'storazzo'
20
20
  #include Storazzo
21
21
  #include Storazzo::Colors
22
+ extend Storazzo::Colors
23
+ include Storazzo::Common #instead
22
24
 
23
25
 
24
- puts "First I need to figure out how to bring in all the libraries in here.."
25
- puts Storazzo::Main.hi(ARGV.join '::')
26
- puts Storazzo::RICC_VERSION
27
- #exit(0)
26
+ #puts "First I need to figure out how to bring in all the libraries in here.."
27
+ #Storazzo::Main.say_hi("ARGV is: #{ ARGV.join ', '}")
28
+ #puts Storazzo.version
28
29
  ############# ############# ############# ############# ############# ############# ############# #############
29
30
 
30
31
 
@@ -40,7 +41,9 @@ if RUBY_VERSION.split('.')[0] == 1
40
41
  end
41
42
 
42
43
  $PROG_VER = '0.4'
43
- $DEBUG = true
44
+ $DEBUG = ENV['DEBUG'] == 'true' # (true/false)
45
+ # p ENV['DEBUG']
46
+ # p $DEBUG
44
47
 
45
48
  HISTORY = <<-BIG_LONG_MULTILINE
46
49
  2022-07-13 v0.4 Now that library has stabilized this kind of works! I can just push gem, update amd include here and work quite well :)
@@ -67,8 +70,15 @@ $myconf = {
67
70
  :app_name => "RicDisk Magic should be sth like #{$0}",
68
71
  :description => "
69
72
  This program is loosely inspired to ricdisk-magic.sh but its much better.
70
- Idea di base: trovare tutti le directory con file ricdisk e da esso estrarre info e magari METTERE info.
71
- Il tutto condito con un bel protobuf e un'entita che metto in Lib.
73
+ The idea is: iterate through all ARGV elements and build a DB of all files with length and MD5.
74
+ Then if folder is writeable, put this list INSIDE IT as its so conveniente.
75
+ If not, put in a ENV-var-defined folder which defaults to ./.storazzo/ :)
76
+
77
+ And maybe someday - add a nice protobuf and an entity in lib/.
78
+
79
+ Note. This software is part of the Storazzo gem ('sai chi ti saluta un casino?'):
80
+
81
+ $ gem install storazzo
72
82
  ".strip.gsub(/^\s+/, "").gsub(/\s+$/, ""),
73
83
  # TODO move to some class default
74
84
  :media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
@@ -126,6 +136,8 @@ def real_program
126
136
  puts "Description: '''#{white $myconf[:description] }'''"
127
137
 
128
138
  config = Storazzo::RicDiskConfig.instance()
139
+ config.load
140
+ puts "StorazzoConfig: #{config}"
129
141
  #config.load # auto_sbrodola(ARGV)
130
142
  puts yellow("ARGV: #{ARGV}")
131
143
  config.iterate_through_file_list_for_disks(ARGV)
@@ -158,8 +170,15 @@ def main(filename)
158
170
  deb "HISTORY: #{gray HISTORY}"
159
171
  #deb "To remove this shit, just set $DEBUG=false :)"
160
172
  init # Enable this to have command line parsing capabilities!
173
+ puts white("$DEBUG is #{$DEBUG }. Tu turn on, call me with -d") unless $DEBUG
161
174
  #warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
162
175
  real_program
176
+
177
+ if ($DEBUG)
178
+ puts "First I need to figure out how to bring in all the libraries in here.."
179
+ Storazzo::Main.say_hi("ARGV is: #{ ARGV.join ', '}")
180
+ puts Storazzo.version
181
+ end
163
182
  end
164
183
 
165
184
  main(__FILE__)
@@ -13,7 +13,8 @@ module Storazzo::Colors
13
13
 
14
14
  PREPEND_ME = "[Storazzo::Colors] "
15
15
 
16
- def deb(s); puts "#DEB #{gray(s)}" if $DEBUG; end
16
+
17
+ def deb2(s); puts "#DEB_OBSOLETE #{gray(s)} [include Storazzo::Common instead]" if $DEBUG; end # Use the Common instead
17
18
 
18
19
  # colors 16
19
20
  def yellow(s) "\033[1;33m#{s}\033[0m" ; end
@@ -1,12 +1,27 @@
1
1
  # Ric common stuff! :)
2
-
2
+ #
3
+ #
4
+ # Usage:
5
+ # include Storazzo::Common
6
+ #
7
+ require_relative 'colors'
3
8
 
4
9
  module Storazzo::Common
5
10
 
11
+ include Storazzo::Colors
6
12
 
7
- def deb(str)
8
- puts "[DEB] #{str}"
9
- end
10
13
 
14
+ def deb(s)
15
+ puts "[DEB] #{yellow(s)}" if $DEBUG
16
+ end
17
+ def warn(s)
18
+ puts "[WRN] #{azure(s)}"
19
+ end
20
+ def err(str)
21
+ puts "[ERR] #{red(s)}"
22
+ end
23
+ def bug(s)
24
+ puts "[🐛] #{gray s}"
25
+ end
11
26
 
12
27
  end
@@ -5,29 +5,42 @@ module Storazzo
5
5
  # instance variable from its hash representation by overriding
6
6
  # this method
7
7
  def ivars_excluded_from_hash
8
- [ 'this_doesnt_exist' ]
8
+ [ 'this_doesnt_exist' ]
9
9
  end
10
10
 
11
11
  def to_hash
12
- hash = {}
13
- excluded_ivars = ivars_excluded_from_hash
14
-
15
- # Iterate over all the instance variables and store their
16
- # names and values in a hash
17
- instance_variables.each do |var|
18
- next if excluded_ivars.include? var.to_s
19
-
20
- value = instance_variable_get(var)
21
- value = value.map(&:to_hash) if value.is_a? Array
22
-
23
- hash[var.to_s.delete("@")] = value
12
+ hash = {}
13
+ excluded_ivars = ivars_excluded_from_hash
14
+
15
+ # Iterate over all the instance variables and store their
16
+ # names and values in a hash
17
+ instance_variables.each do |var|
18
+ next if excluded_ivars.include? var.to_s
19
+
20
+ value = instance_variable_get(var)
21
+ value = value.map(&:to_hash) if value.is_a? Array
22
+
23
+ hash[var.to_s.delete("@")] = value
24
+ end
25
+
26
+ return hash
24
27
  end
25
-
26
- return hash
28
+
29
+ def obj_to_hash
30
+ h = {}
31
+ puts self
32
+ self.instance_variables.each{|var|
33
+ #puts var
34
+ h[var.to_s.delete('@')] = self.instance_variable_get(var) # send(var.to_s.delete('@'))
35
+ }
36
+ h
27
37
  end
28
38
 
29
39
  def to_yaml
30
- to_hash.to_yaml
40
+ to_hash.to_yaml
41
+ end
42
+ def obj_to_yaml
43
+ obj_to_hash.to_yaml
31
44
  end
32
45
  end
33
46
  end
@@ -40,11 +40,10 @@ module Storazzo::Media
40
40
  File.writable?(@local_mountpoint)
41
41
  end
42
42
 
43
-
44
- # def stats_filename
45
- # #'42'
46
- # self.default_stats_filename
47
- # end
43
+ def default_stats_filename
44
+ #'42'
45
+ Storazzo::RicDiskStatsFile.default_name
46
+ end
48
47
 
49
48
  end
50
49
 
@@ -1,27 +1,33 @@
1
1
  # A RicDisk wraps a local mount/disk/folder
2
2
  # it's considered interesting if there's a ".ricdisk/.ricdisk"
3
3
 
4
+ require 'digest'
5
+
4
6
  module Storazzo
5
7
  class Storazzo::RicDisk
6
8
 
7
9
  include Hashify
10
+ include Storazzo::Common
8
11
  extend Storazzo::Colors
9
12
 
10
13
 
11
14
  ## Instance variables
12
15
 
13
16
  # in order of finding, so the first will be the one we actually READ and use. I could looknat the date but cmon...
14
- @@config_files = %W{ ricdisk.yaml .ricdisk }
15
- @@ricdisk_version = '2.0'
16
- @@default_gemfile_test_disks_folder = Storazzo.root + "/var/test/disks/"
17
+ # These are the files I do accept.
18
+ ConfigFiles = %W{ ricdisk.yaml .ricdisk }
19
+ RicdiskVersion = '2.0'
20
+ DefaultGemfileTestDiskFolder = Storazzo.root + "/var/test/disks/" # was: @@default_gemfile_test_disks_folder
17
21
  # Immutable
18
- DEFAULT_MEDIA_FOLDERS = %w{
22
+ DefaultMediaFolders = %w{
19
23
  /Volumes/
20
24
  /mnt/
21
- }.append(@@default_gemfile_test_disks_folder ).append("/media/#{ENV["USER"]}/" )
25
+ }.append(DefaultGemfileTestDiskFolder ).append("/media/#{ENV["USER"]}/" )
22
26
 
23
27
  # # todo substitute with protobuf..
24
- attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
28
+ attr_accessor :name, :description, :ricdisk_file,:ricdisk_file_full, :local_mountpoint, :wr, :path,
29
+ :ricdisk_file_empty, :size, :active_dirs, :ricdisk_version,
30
+ :unique_hash # new 202207
25
31
 
26
32
 
27
33
  ################################
@@ -30,36 +36,41 @@ module Storazzo
30
36
 
31
37
 
32
38
  def initialize(path, opts={})
33
- puts "[DEB] RicDisk initialize.. path=#{path}"
34
- @local_mountpoint = path
35
- @description = "This is an automated RicDisk description from v.#{@@ricdisk_version}. Created on #{Time.now}'"
36
- @ricdisk_version = @@ricdisk_version
37
- #@ricdisk_file = ricdisk_file
38
- @ricdisk_file = RicDisk.get_ricdisk_file(path)
39
+ deb "RicDisk initialize.. path=#{path}"
40
+ # @local_mountpoint = path
41
+ @local_mountpoint = File.expand_path(path)
42
+ @description = "This is an automated RicDisk description from v.#{RicdiskVersion}. Created on #{Time.now}'"
43
+ @ricdisk_version = RicdiskVersion
44
+ @ricdisk_file = compute_ricdisk_file() # Storazzo::RicDisk.get_ricdisk_file(path)
45
+ @ricdisk_file_full = "#{@local_mountpoint}/#{@ricdisk_file}"
39
46
  @ricdisk_file_empty = ricdisk_file_empty?
40
47
  @label = path.split("/").last
41
48
  @name = path.split("/").last
42
49
  #@wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
50
+ #@wr = writeable?
43
51
  @tags = ['ricdisk', 'storazzo']
44
52
  @size = `du -s '#{path}'`.split(/\s/)[0] # self.size
45
- puts :beleza
53
+ @unique_hash = "MD5::" + Digest::MD5.hexdigest(File.expand_path(path)) # hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
54
+ @computation_hostname = Socket.gethostname
46
55
  # @config = RicDiskConfig.instance.get_config
47
56
  # #puts @config if @config
48
57
  # find_info_from_mount(path)
58
+ deb "RicDisk initialize. to_s: #{self}"
49
59
  # find_info_from_df()
50
60
  end
51
61
 
52
62
  def ricdisk_file_empty?()
53
- File.empty?( "#{local_mountpoint}/#.ricdisk.yaml")
63
+ # File.empty?("#{local_mountpoint}/.ricdisk.yaml")
64
+ File.empty?(compute_ricdisk_file) # was (get_ricdisk_file)
54
65
  end
55
66
 
56
67
  def ok_dir?
57
- not @ricdisk_file.nil?
68
+ not ricdisk_file.nil?
58
69
  end
59
70
 
60
71
 
61
72
  def analyze_local_system()
62
- puts :TODO
73
+ puts "TODO This should analyzze the WHOLE system. TODO(ricc): move to another object which has to do with the system/computer."
63
74
  puts "1. Interesting Mounts: #{green interesting_mount_points}"
64
75
  puts "2. Sbrodoling everything: :TODO"
65
76
  # find_info_from_mount(path)
@@ -71,7 +82,7 @@ module Storazzo
71
82
  end
72
83
 
73
84
  def to_s
74
- "RicDisk(paz=#{path}, writeable=#{writeable?}, size=#{size}B)"
85
+ "RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version})"
75
86
  end
76
87
 
77
88
  # could take long..
@@ -80,7 +91,13 @@ module Storazzo
80
91
  # end
81
92
 
82
93
  def writeable?()
83
- :boh
94
+ return @wr unless @wr.nil?
95
+ # Otherwise I can do an EXPENSIVE calculation
96
+ deb "TODO(ricc): Do expensive caluylation if this FS is writeable: #{path}"
97
+ wr = File.writable?(ricdisk_file)
98
+ wr
99
+ #:boh_todo_fix_me_and_compute
100
+ #false
84
101
  end
85
102
 
86
103
  ################################
@@ -90,19 +107,20 @@ module Storazzo
90
107
 
91
108
  # All places where to find for something :)
92
109
  def self.default_media_folders
93
- DEFAULT_MEDIA_FOLDERS
110
+ DefaultMediaFolders # was DEFAULT_MEDIA_FOLDERS
94
111
  end
95
112
 
96
113
 
97
114
  def self.test # _localgem_disks
98
- d = RicDisk.new( @@default_gemfile_test_disks_folder)
115
+ d = RicDisk.new( DefaultGemfileTestDiskFolder)
99
116
  puts (d)
100
117
  puts "do something with it: #{d}"
101
118
  #d.find_active_dirs()
102
119
  end
103
120
 
104
-
105
-
121
+ def absolute_path
122
+ @local_mountpoint + "/" + @ricdisk_file
123
+ end
106
124
 
107
125
 
108
126
  def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
@@ -139,12 +157,33 @@ module Storazzo
139
157
  end
140
158
  end
141
159
 
160
+ def compute_ricdisk_file()
161
+ unless @ricdisk_file.nil?
162
+ deb "[CACHE HIT] ricdisk_file (didnt have to recompute it - yay!)"
163
+ return @ricdisk_file
164
+ end
165
+ warn "RICC_WARNING This requires cmputation I wanna do it almost once"
166
+ ConfigFiles.each do |papable_config_filename|
167
+ #return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
168
+ #return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
169
+ return papable_config_filename if File.exist?("#{path}/#{papable_config_filename}") # and File.empty?( "#{path}/.ricdisk")
170
+ end
171
+ return nil
172
+ end
173
+
142
174
 
143
175
  # new
144
- def self.get_ricdisk_file(path)
145
- puts "RICC_WARNING TODO use @@config_files instead"
146
- return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
147
- return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
176
+ def self.get_ricdisk_file_obsolete(path)
177
+ if @ricdisk_file
178
+ puts "[CACHE HIT] ricdisk_file"
179
+ return @ricdisk_file
180
+ end
181
+ puts "RICC_WARNING This requires cmputation I wanna do it almost once"
182
+ ConfigFiles.each do |papable_config_filename|
183
+ #return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
184
+ #return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
185
+ return papable_config_filename if File.exist?("#{path}/#{papable_config_filename}") # and File.empty?( "#{path}/.ricdisk")
186
+ end
148
187
  return nil
149
188
  end
150
189
 
@@ -167,35 +206,51 @@ module Storazzo
167
206
 
168
207
 
169
208
  # FORMER SBRODOLA, now write_config_yaml_to_disk
170
- def self.write_config_yaml_to_disk(subdir) # sbrodola_ricdisk(subdir)
209
+ #def self.write_config_yaml_to_disk(subdir, opts={}) # sbrodola_ricdisk(subdir)
210
+ def write_config_yaml_to_disk(subdir, opts={}) # sbrodola_ricdisk(subdir)
171
211
  # given a path, if .ricdisk exists i do stuff with it..
172
212
  disk_info = nil
173
- unless self.ok_dir?(subdir)
174
- puts("Nothing for me here: '#{subdir}'. Existing")
213
+ unless ok_dir? # self.ok_dir?(subdir)
214
+ puts("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
175
215
  return
176
216
  end
177
- if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
178
- deb("Interesting1. Empty file! Now I write YAML with it.")
179
- disk_info = RicDisk.new(subdir, '.ricdisk')
180
- end
181
- if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
182
- deb("Interesting2. Empty file! TODO write YAML with it.")
183
- disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
184
- puts(yellow disk_info.to_yaml)
217
+ ConfigFiles.each do |papable_configfile_name|
218
+ if File.exists?( "#{subdir}/#{papable_configfile_name}") and File.empty?( "#{subdir}/#{papable_configfile_name}")
219
+ deb("Interesting. Empty file '#{papable_configfile_name}'! Now I write YAML with it.")
220
+ disk_info = RicDisk.new(subdir, papable_configfile_name)
221
+ end
185
222
  end
186
- if disk_info
187
- if File.empty?(disk_info.ricdisk_absolute_path) and (disk_info.wr)
188
- puts(green("yay, we can now write the file '#{disk_info.ricdisk_absolute_path}' (which is R/W, I just checked!) with proper YAML content.."))
189
- ret = File.write(disk_info.ricdisk_absolute_path, disk_info.to_yaml)
223
+ # if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
224
+ # deb("Interesting1. Empty file! Now I write YAML with it.")
225
+ # disk_info = RicDisk.new(subdir, '.ricdisk')
226
+ # end
227
+ # if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
228
+ # deb("Interesting2. Empty file! TODO write YAML with it.")
229
+ # disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
230
+ # puts(yellow disk_info.to_yaml)
231
+ # end
232
+ if disk_info.is_a?(RicDisk)
233
+ deb("disk_info.class: #{disk_info.class}")
234
+ if File.empty?(disk_info.absolute_path) and (disk_info.wr)
235
+ puts(green("yay, we can now write the file '#{disk_info.absolute_path}' (which is R/W, I just checked!) with proper YAML content.."))
236
+ ret = File.write(disk_info.absolute_path, disk_info.to_yaml)
190
237
  puts("Written file! ret=#{ret}")
191
238
  else
192
- puts(red("Nope, qualcosa non va.. #{File.empty?(disk_info.ricdisk_absolute_path)}"))
193
- puts("File size: #{File.size(disk_info.ricdisk_absolute_path)}")
239
+ puts(red("Something not right here: either file is NOT empty or disk is NOT writeable.. #{File.empty?(disk_info.absolute_path)}"))
240
+ puts("File size: #{File.size(disk_info.absolute_path)}")
241
+ puts(disk_info.to_s)
242
+ puts(disk_info.obj_to_hash)
243
+ puts(disk_info.obj_to_yaml)
194
244
  end
245
+ else
246
+ puts "[write_config_yaml_to_disk] No DiskInfo found across #{ConfigFiles}. I leave this function empty-handed."
195
247
  end
196
248
  if File.exists?( "#{subdir}/.ricdisk") and ! File.empty?( "#{subdir}/.ricdisk")
197
- puts("Config File found with old-style name: '#{subdir}/.ricdisk' !")
198
- #puts(white `cat "#{subdir}/.ricdisk"`)
249
+ puts("Config File found with old-style name: '#{subdir}/.ricdisk' ! Please move it to .ricdisk.yaml!")
250
+ puts(white `cat "#{subdir}/.ricdisk"`)
251
+ else
252
+ puts "WRITING NOW. disk_info.obj_to_yaml .. to #{compute_ricdisk_file}"
253
+ File.open(ricdisk_file_full, 'w').write(disk_info.obj_to_yaml)
199
254
  end
200
255
  end
201
256
 
@@ -12,23 +12,28 @@ require 'yaml'
12
12
  =end
13
13
 
14
14
  module Storazzo
15
- class Storazzo::RicDiskConfig
15
+ # class Storazzo::Blah
16
+ # end
17
+
18
+ class Storazzo::RicDiskConfig
16
19
  include Singleton
17
20
  include Storazzo::Common
18
21
  include Storazzo::Colors
19
22
 
20
- @@default_config_location = "~/.storazzo.yaml"
21
- @@default_config_locations = [
22
- "~/.storazzo.yaml" , # HOME
23
- "./.storazzo.yaml" , # LOCAL DIR
24
- ]
25
- DefaultConfigLocation = [
26
- "~/.storazzo.yaml" , # HOME
27
- "./.storazzo.yaml" , # LOCAL DIR
23
+ #@@default_config_location = "~/.storazzo.yaml"
24
+ DefaultConfigLocation = File.expand_path "~/.storazzo.yaml"
25
+ # @@default_config_locations = [
26
+ # "~/.storazzo.yaml" , # HOME
27
+ # "./.storazzo.yaml" , # LOCAL DIR
28
+ # ]
29
+ DefaultConfigLocations = [
30
+ File.expand_path("~/.storazzo.yaml") , # HOME
31
+ File.expand_path("./.storazzo.yaml") , # LOCAL DIR
28
32
  ]
29
- @@default_gem_location_for_tests = File.expand_path('../../../', __FILE__) + "/etc/storazzo_config.sample.yaml"
33
+ #@@default_gem_location_for_tests
34
+ DefaultGemLocationForTests = File.expand_path('../../../', __FILE__) + "/etc/storazzo_config.sample.yaml"
30
35
 
31
- attr_accessor :config, :config_file
36
+ attr_accessor :config, :config_file, :load_called
32
37
 
33
38
  public
34
39
  # Load from the first valid config.
@@ -37,8 +42,8 @@ public
37
42
 
38
43
  puts "[VERBOSE] Storazzo::RicDiskConfig.load(): BEGIN " if verbose
39
44
  # trying default location
40
- raise "@@default_config_location is not a string" unless @@default_config_location.is_a?(String)
41
- possible_locations = DefaultConfigLocation # [ @@default_config_location , "./.storazzo.yaml"]
45
+ raise "DefaultConfigLocation is not a string" unless DefaultConfigLocation.is_a?(String)
46
+ possible_locations = DefaultConfigLocations # [ @@default_config_location , "./.storazzo.yaml"]
42
47
  puts "DEB possible_locations: #{possible_locations}"
43
48
  if config_path.is_a?(String)
44
49
  #possible_locations = [config_path] + possible_locations # .append()
@@ -47,12 +52,12 @@ public
47
52
  puts "[LOAD] possible_locations: #{possible_locations}" if verbose
48
53
  end
49
54
  puts "[VERBOSE] Searching these paths in order: #{possible_locations}" if verbose
50
- puts "BUG: This is not always an array of sTRINGS."
55
+ bug "This is not always an array of sTRINGS."
51
56
  raise "possible_locations is not an array" unless possible_locations.is_a?(Array)
52
57
  possible_locations.each do |possible_path|
53
58
  # ASSERT is a string
54
59
  raise "possible_path is not a string" unless possible_path.is_a?(String)
55
- puts "DEB before buggy expand_path paz: '#{possible_path}''"
60
+ deb "before buggy expand_path paz: '#{possible_path}''"
56
61
  paz = File.expand_path(possible_path) rescue possible_path
57
62
  raise "Not a string: #{paz}" unless paz.is_a?(String)
58
63
  if File.exists?(paz)
@@ -68,23 +73,26 @@ public
68
73
  config_ver = @config["apiVersion"]
69
74
  #puts @config[:ConfigVersion]
70
75
  puts white("OK. Storazzo::RicDiskConfig v'#{config_ver}' parsed correctly")
71
- puts "RicDiskConfig.to_s: #{self}" if verbose
76
+ puts "[VERBOSE] RicDiskConfig.to_s: #{self}" if verbose
77
+ @load_called = true
72
78
  return self.config
73
79
  end
74
80
  end
81
+ @load_called = true
75
82
  # only get here if nothing is found
76
83
  raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}"
77
- # @config = 42
78
- # puts "[VERBOSE] Storazzo::RicDiskConfig.load(): END " if verbose
79
84
  end
80
85
 
86
+ # Obsolete, call another class instead.
81
87
  def load_sample_version
82
- puts("Warning! We're destroying the world here. We're taking a Singletong and changing the way it behaves by moving the config file by under her feet. Don't be mad at me if this misbehaves. You saw it coming, my friends. This is why I would NEVER hire you as a Software Developer in my Company.")
83
- load(@@default_gem_location_for_tests, :verbose => true )
88
+ # puts("Warning! We're destroying the world here. We're taking a Singletong and changing the way it behaves by moving the config file by under her feet. Don't be mad at me if this misbehaves. You saw it coming, my friends. This is why I would NEVER hire you as a Software Developer in my Company.")
89
+ raise "DEPRECATED! USE SampleRicDiskConfig.load() instead!"
90
+ # load(DefaultGemLocationForTests, :verbose => true )
84
91
  end
85
92
 
86
93
  def config_ver
87
- @config['apiVersion']
94
+ raise "I cant compute Version since I cant compute @config. Are you sure you didnt instance this Singleton without calling load?" unless @config
95
+ @config['apiVersion'] # rescue :StillUnknown
88
96
  #config['ConfigVersion']
89
97
  end
90
98
  def config_default_folder
@@ -93,9 +101,10 @@ public
93
101
  end
94
102
 
95
103
  def to_s
96
- size = File.size( @config_file )
104
+ size = File.size(@config_file) rescue -1
97
105
  #puts yellow "DEB: #{@config["apiVersion"]}"
98
- "RicDiskConfig(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
106
+ #"RicDiskConfig(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
107
+ "POLY_#{self.class}_(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
99
108
  end
100
109
 
101
110
  def get_config(opts={})
@@ -143,15 +152,19 @@ public
143
152
  # } # TODO refactor in option sbrodola_afterwards=true. :)
144
153
  # else
145
154
  deb "iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)"
146
- dirs = RicDisk.find_active_dirs()
155
+ #dirs = RicDisk.find_active_dirs()
147
156
  files_list.each do |dir|
148
157
  dir = File.expand_path(dir)
149
- if dirs.include?(dir)
150
- deb "Legit dir: #{green dir}"
151
- RicDisk.write_config_yaml_to_disk(dir)
158
+ if File.directory?(dir)
159
+ #if dirs.include?(dir)
160
+ deb "iterate_through_file_list_for_disks() Legit dir: #{green dir}"
161
+ rd = RicDisk.new(dir)
162
+ rd.write_config_yaml_to_disk(dir)
163
+ #RicDisk.write_config_yaml_to_disk(dir)
152
164
  RicDisk.calculate_stats_files(dir) # dir is inutile
153
165
  else
154
- deb "Figghiu ri buttana: doesnt exist #{red dir}"
166
+ deb red("Doesnt seem a legit dir to me: #{dir}")
167
+ # deb "Figghiu ri buttana: doesnt exist #{red dir}"
155
168
  end
156
169
  end
157
170
  #end
@@ -161,5 +174,41 @@ public
161
174
  def self.get_config
162
175
  self.instance.get_config
163
176
  end
177
+ end # class Storazzo::RicDiskConfig
178
+
179
+ # class Storazzo::SampleRicDiskConfig < Storazzo::RicDiskConfig
180
+ # include Singleton
181
+
182
+ # def load # _sample_version
183
+ # puts white("Wheew! We're NOT destroying the world here. We're actually instancing a second Singleton which is a child of the mother, and this time doing things nicely and Rubily.")
184
+ # super.load(DefaultGemLocationForTests, :verbose => true )
185
+ # end
186
+
187
+ # end
188
+
189
+ puts "[REMOVEME]1 Storazzo::RicDiskConfig was read"
190
+
191
+ #end # module Storazzo
192
+
193
+ puts "[REMOVEME]2 Storazzo::RicDiskConfig was read"
194
+
195
+
196
+
197
+ #module Storazzo
198
+
199
+ # ric_disk_sample_config
200
+ #class Pincopallo # Storazzo::Blah #RicDiskSampleConfig # < Storazzo::RicDiskConfig
201
+ class Storazzo::Pincopallo # RicDiskSampleConfig
202
+
203
+ #include Singleton
204
+ # public
205
+ # def load # _sample_version
206
+ # puts white("Wheew! We're NOT destroying the world here. We're actually instancing a second Singleton which is a child of the mother, and this time doing things nicely and Rubily.")
207
+ # super.load(DefaultGemLocationForTests, :verbose => true )
208
+ # end
164
209
  end
165
- end
210
+
211
+ puts "[REMOVEME]1 Storazzo::RicDiskSampleConfig was read"
212
+ end # module Storazzo
213
+
214
+ puts "[REMOVEME]2 Storazzo::RicDiskSampleConfig was read"
@@ -0,0 +1,9 @@
1
+
2
+ module Storazzo
3
+
4
+ class Storazzo::RicDiskConfigExample # < Storazzo::RicDiskConfig
5
+
6
+ end
7
+ end
8
+
9
+ puts "[REMOVEME]2 Storazzo::RicDiskSampleConfig was read"
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+
4
+ require_relative "./common"
5
+ require_relative "./ric_disk_config"
6
+
7
+ =begin
8
+ This is a singleton class. You call me this way..
9
+ You call me with:
10
+
11
+ Storazzo::RicDiskSampleConfig.instance()
12
+
13
+ =end
14
+
15
+ module Storazzo
16
+
17
+ class Storazzo::RicDiskSampleConfig < Storazzo::RicDiskConfig
18
+ #include Storazzo::Common
19
+
20
+ include Singleton
21
+ public
22
+ def load # _sample_version
23
+ puts white("Wheew! We're NOT destroying the world here. We're actually instancing a second Singleton which is a child of the mother, and this time doing things nicely and Rubily.")
24
+ super.load(DefaultGemLocationForTests, :verbose => true )
25
+ end
26
+ end
27
+
28
+ #puts "[REMOVEME]1 Storazzo::RicDiskSampleConfig was read"
29
+ end # module Storazzo
30
+
31
+ #puts "[REMOVEME]2 Storazzo::RicDiskSampleConfig was read"
@@ -11,7 +11,8 @@ module Storazzo
11
11
  class << self
12
12
  attr_accessor :default_name, :version
13
13
  end
14
-
14
+
15
+ public
15
16
  def self.default_name
16
17
  DefaultName
17
18
  end
@@ -1,4 +1,4 @@
1
-
1
+ # TODO remove this! Ugly code to just borrow and cleanup a bit,
2
2
 
3
3
  module Storazzo
4
4
  class Storazzo::RicDiskUgly
@@ -1,17 +1,17 @@
1
1
  # todo remove
2
- class Storazzo::Translator
2
+ # class Storazzo::Translator
3
3
 
4
- def initialize(language)
5
- @language = language
6
- end
4
+ # def initialize(language)
5
+ # @language = language
6
+ # end
7
7
 
8
- def hi
9
- case @language
10
- when "spanish"
11
- "hola mundo"
12
- else
13
- "hello world"
14
- end
15
- end
8
+ # def hi
9
+ # case @language
10
+ # when "spanish"
11
+ # "hola mundo"
12
+ # else
13
+ # "hello world"
14
+ # end
15
+ # end
16
16
 
17
- end
17
+ # end
@@ -3,5 +3,10 @@
3
3
  module Storazzo
4
4
  DHH_VERSION = "0.2.3_TODOFileRead" # TODO file.read ../../VERSION . chomp
5
5
  RICC_VERSION = File.read("../VERSION").chomp
6
+
7
+ public
8
+ def self.version
9
+ RICC_VERSION
10
+ end
6
11
  end
7
12
 
data/lib/storazzo.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # Inspired from https://guides.rubygems.org/make-your-own-gem/#introduction
2
2
 
3
-
4
3
  module Storazzo
5
4
  #VERSION = File.read('./VERSION').chomp # "10.0.0"
6
5
  #require 'storazzo/translator'
@@ -23,11 +22,16 @@ module Storazzo
23
22
  def self.VERSION
24
23
  version
25
24
  end
25
+
26
+ def self.storazzo_classes
27
+ [42, 43]
28
+ end
26
29
  end
27
30
 
28
31
  # nice to paste nice output
29
32
  require 'pp'
30
33
 
34
+ require 'storazzo'
31
35
  require 'storazzo/common'
32
36
  require 'storazzo/colors'
33
37
  require 'storazzo/hashify'
@@ -37,10 +41,11 @@ require 'storazzo/media/abstract_ric_disk'
37
41
  require 'storazzo/media/gcs_bucket'
38
42
  require 'storazzo/media/local_folder'
39
43
  require 'storazzo/ric_disk_ugly' # OLD and 90% working
40
- require 'storazzo/ric_disk_config'
44
+ require 'storazzo/ric_disk_config' # => RicDiskConfif
45
+ require 'storazzo/ric_disk_sample_config' # => NOTHING!!
46
+ require 'storazzo/ric_disk_config_example' # => NEW!!!
41
47
  require 'storazzo/ric_disk_statsfile'
42
48
  require 'storazzo/main'
43
49
  require 'storazzo/translator'
44
50
 
45
51
  #puts Storazzo::Main.say_hi
46
-
@@ -1,19 +1,34 @@
1
1
  require "minitest/autorun"
2
2
  require "storazzo"
3
3
  require "storazzo/ric_disk"
4
+ require "storazzo/ric_disk_config"
5
+ require 'storazzo/colors'
4
6
  require "storazzo/media/local_folder"
7
+ require "storazzo/ric_disk_config_example"
8
+
9
+ #require "storazzo/ric_disk_config"
10
+ #require "storazzo/ric_disk_sample_config"
11
+ #require 'storazzo/ric_disk_sample_config' # => NOTHING!!
12
+ #require 'storazzo/ric_disk_config_sample' # => NOTHING!!
13
+
14
+ #require "storazzo/ric_disk"
15
+ #require "lib/storazzo/ric_disk_sample_config"
16
+ #require "storazzo/media/local_folder"
5
17
  #require "storazzo/ric_disk/gcs_bucket"
6
18
  #require "storazzo/media/local_folder"
7
19
 
8
20
  class GcsBucketTest < Minitest::Test
9
21
 
10
- def setup # tear_up
11
- puts "GcsBucketTest TEAR_UP with sample Config"
12
- config_obj = Storazzo::RicDiskConfig.instance()
13
- config_obj.load_sample_version
22
+ include Storazzo::Common
23
+
24
+ def TODO_RENAME_MEsetup # tear_up
25
+ deb "[GcsBucketTest] TEAR_UP with sample Config"
26
+ removeme = Storazzo::RicDiskConfig.instance()
27
+ config_obj = Storazzo::RicDiskSampleConfig.instance()
28
+ deb "[GcsBucketTest] TEAR_UP config_obj: '''#{config_obj}'''"
14
29
  end
15
30
 
16
- def test_buckets_are_the_two_i_know
31
+ def TODO_RENAME_MEtest_buckets_are_the_two_i_know
17
32
  expected_list = %w{
18
33
  gs://my-local-backup/storazzo/backups/
19
34
  gs://my-other-bucket/
@@ -23,6 +38,19 @@ class GcsBucketTest < Minitest::Test
23
38
  "These are the two lists from Sample Storazzo Config")
24
39
  end
25
40
 
41
+ def test_import
42
+ require "storazzo/ric_disk_sample_config" rescue nil
43
+ require "storazzo/ric_disk_config"
44
+
45
+ #puts Storazzo.class
46
+ puts Storazzo.constants
47
+ #puts Storazzo::RicDiskSampleConfig
48
+ config_obj = Storazzo::RicDiskSampleConfig.instance()
49
+ puts config_obj
50
+ config_obj.load # _sample_version
51
+ end
52
+
53
+
26
54
  def teardown
27
55
  #puts :TEAR_DOWN_TODO
28
56
  end
@@ -1,22 +1,28 @@
1
1
  require "minitest/autorun"
2
2
  require "storazzo"
3
3
  require "storazzo/ric_disk"
4
+ require "storazzo/ric_disk_config"
5
+ require 'storazzo/colors'
4
6
  require "storazzo/media/local_folder"
5
7
 
6
8
  #require "storazzo/ric_disk/gcs_bucket"
7
9
  #require "storazzo/media/local_folder"
8
10
 
9
- extend Storazzo::Colors
10
11
 
11
12
  #puts yellow("DISABLING FOR NOW TODO restore")
12
13
 
13
14
  class LocalFolderTest < Minitest::Test
15
+ extend Storazzo::Colors
14
16
  # def test_fail_on_purpOSE # test_storazzo_hi_with_argument
15
17
  # assert_match 42, 42 , "change me when it failes from makefile"
16
18
  # #"Hello from Storazzo", Storazzo::Main.hi("ruby this should fail")
17
19
  # #assert_match "ruby this should fail", Storazzo::Main.hi("ruby this should fail")
18
20
  # end
19
21
  def tear_up
22
+ include Storazzo::Colors
23
+ puts yellow("LocalFolderTest: tear up")
24
+ #$config = Storazzo::RicDiskConfig.instance()
25
+ #$vediamo_se_funge = 42
20
26
  # my_class = Storazzo::RicDisk::LocalFolder
21
27
  # my_obj = Storazzo::RicDisk::LocalFolder
22
28
  end
@@ -37,19 +43,20 @@ class LocalFolderTest < Minitest::Test
37
43
 
38
44
  def test_first_directory_parsing_actually_works()
39
45
  # include module
40
- extend Storazzo::Colors
41
46
 
42
- puts yellow("(#{__FILE__}) WEIRD THING: This test is flaky. SKipping for now until I complete the LocalFolder.parse() code")
43
-
44
- # folders = Storazzo::Media::LocalFolder.list_all
45
-
46
- # test_dir = folders.first
47
+ #p $vediamo_se_funge
48
+ puts("(#{__FILE__}) WEIRD THING: This test is flaky. SKipping for now until I complete the LocalFolder.parse() code")
49
+ folders = Storazzo::Media::LocalFolder.list_all
50
+ config = Storazzo::RicDiskConfig.instance()
51
+ test_dir = folders.first
47
52
  # puts "test_first_directory_parsing_actually_works() TestDir: #{test_dir}"
48
- # puts "TEST S:M:LF methods: #{folders}" # methods
53
+ # puts yellow "TEST S:M:LF methods: #{folders}" # methods
49
54
  # disk = Storazzo::Media::LocalFolder.new(test_dir)
50
55
  # stats_file = disk.stats_filename_default_fullpath
51
56
  # puts "stats_file: #{stats_file}"
52
57
  # disk.parse()
58
+ puts "[DEB] config: ''#{config}''"
59
+ config.iterate_through_file_list_for_disks( [test_dir])
53
60
  # assert(
54
61
  # File.exists?(stats_file),
55
62
  # "parse on LocalFolder should create file '#{stats_file}'"
@@ -0,0 +1,40 @@
1
+ =begin
2
+ to just test this file, try:
3
+
4
+ `ruby -I test test/test_ric_disk_config.rb`
5
+
6
+ =end
7
+
8
+ require "minitest/autorun"
9
+ require "storazzo"
10
+ #require "storazzo/ric_disk_config"
11
+ #require "storazzo/ric_disk_sample_config"
12
+ #require "storazzo/ric_disk_config_example"
13
+
14
+ # require "storazzo/media/local_folder"
15
+ #require "storazzo/ric_disk/gcs_bucket"
16
+ #require "storazzo/media/local_folder"
17
+
18
+ puts :TODO
19
+
20
+ class RicDiskConfigTest < Minitest::Test
21
+
22
+ def test_load_sample_version # test_sample_config_is_within_gems_boundaries
23
+ #config_obj = Storazzo::RicDiskConfig.instance()
24
+ #puts :sofar_so_good
25
+ config_obj = Storazzo::RicDiskSampleConfig.instance()
26
+ puts "config_obj.class: #{config_obj.class}"
27
+ l = config_obj.load # _sample_version
28
+ puts l
29
+ #puts '[RicDiskConfigTest] TODO lets make sure the gem being imported is actually in /etc/storazz-config.smaple blah blah'
30
+ #puts "[RicDiskConfigTest] config_file: ", config_obj.config_file
31
+ assert_equal(
32
+ config_obj.config_file,
33
+ # Rails.root +
34
+ "etc/",
35
+ "Config file expected to be here.."
36
+ )
37
+ end
38
+
39
+
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riccardo Carlesso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple gem to manage your external hard drives and extract MD5 and
14
14
  common stuff from them.
@@ -39,6 +39,8 @@ files:
39
39
  - lib/storazzo/parser/parser.rb
40
40
  - lib/storazzo/ric_disk.rb
41
41
  - lib/storazzo/ric_disk_config.rb
42
+ - lib/storazzo/ric_disk_config_example.rb
43
+ - lib/storazzo/ric_disk_sample_config.rb
42
44
  - lib/storazzo/ric_disk_statsfile.rb
43
45
  - lib/storazzo/ric_disk_ugly.rb
44
46
  - lib/storazzo/translator.rb
@@ -46,6 +48,7 @@ files:
46
48
  - storazzo.gemspec
47
49
  - test/test_gcs_bucket.rb
48
50
  - test/test_local_folder.rb
51
+ - test/test_ric_disk_config.rb
49
52
  - test/test_ric_disk_stats_file.rb
50
53
  - test/test_storazzo.rb
51
54
  - var/test/README.md
@@ -77,6 +80,7 @@ summary: storazzo is an amazing gem. Code is in https://github.com/palladius/sto
77
80
  test_files:
78
81
  - test/test_storazzo.rb
79
82
  - test/test_ric_disk_stats_file.rb
83
+ - test/test_ric_disk_config.rb
80
84
  - test/test_gcs_bucket.rb
81
85
  - test/test_local_folder.rb
82
86
  - var/test/README.md