storazzo 0.4.1 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ module Storazzo
8
8
 
9
9
  include Hashify
10
10
  include Storazzo::Common
11
+ extend Storazzo::Common
11
12
  extend Storazzo::Colors
12
13
  require 'socket'
13
14
 
@@ -40,10 +41,21 @@ module Storazzo
40
41
  ## INSTANCE methods
41
42
  ################################
42
43
 
44
+ def initialize_old_way(path, opts={})
45
+ raise "Now I dont want a string in input, I want an OBJECT < Storazzo::Media::AbstractRicDisk"
46
+ end
47
+
43
48
 
44
- def initialize(path, opts={})
49
+ def initialize(ric_disk_object, opts={})
50
+ verbose = opts.fetch :verbose, true
51
+ pverbose verbose, "This needs an object of type Storazzo::Media::AbstractRicDisk now (this case: #{ric_disk_object.class})"
52
+ raise "Woopsie, not a Storazzo::Media::AbstractRicDisk! Intead its a #{ric_disk_object.class}" unless ric_disk_object.class.superclass == Storazzo::Media::AbstractRicDisk
53
+ # ok back to business, now path is a String :)
54
+ path = ric_disk_object.path
55
+ deb "RicDisk initialize.. path=#{path}"
45
56
  deb "RicDisk initialize.. path=#{path}"
46
57
  @local_mountpoint = File.expand_path(path)
58
+ @ard = ric_disk_object # AbstractRicDiskObject
47
59
  @description = "This is an automated RicDisk description from v.#{RicdiskVersion}. Created on #{Time.now}'"
48
60
  @ricdisk_version = RicdiskVersion
49
61
  @ricdisk_file = compute_ricdisk_file() # Storazzo::RicDisk.get_ricdisk_file(path)
@@ -53,7 +65,7 @@ module Storazzo
53
65
  #@wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
54
66
  #@wr = writeable?
55
67
  @tags = ['ricdisk', 'storazzo']
56
- @size = `du -s '#{path}'`.split(/\s/)[0] # self.size
68
+ @size = RicDisk._compute_size_could_take_long(path)
57
69
  @unique_hash = "MD5::" + Digest::MD5.hexdigest(File.expand_path(path)) # hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
58
70
  @computation_hostname = Socket.gethostname
59
71
  @created_at = Time.now
@@ -91,18 +103,31 @@ module Storazzo
91
103
  end
92
104
 
93
105
  def to_s
94
- "RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version})"
106
+ "RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version}, ard=#{@ard})"
95
107
  end
96
108
 
97
109
  # could take long..
98
110
  # def size
99
111
  # `du -s '#{path}'`.split(/\s/)[0]
100
112
  # end
113
+ def self._compute_size_could_take_long(my_path)
114
+ deb "Could take long. TODO(ricc): add some sort of cutoff/timeout to 5 seconds."
115
+ puts azure('could take long. Please take precautions like forking with timeout of 5sec')
116
+ `du -s '#{my_path}' 2>/dev/null`.chomp.split(/\s/)[0] # self.size
117
+ end
101
118
 
102
119
  def writeable?()
120
+ #memoize
103
121
  return @wr unless @wr.nil?
104
- # Otherwise I can do an EXPENSIVE calculation
105
- puts yellow("TODO(ricc): Do expensive calculation if this FS is writeable: #{path}")
122
+ # NOW: CALCULATE it
123
+ # Now I can do ONCE an EXPENSIVE calculation
124
+ puts yellow("[RicDisk.writeable] TODO(ricc): Do expensive calculation if this FS is writeable: #{path} and write/memoize it on @wr once and for all")
125
+ puts yellow("[RicDisk.writeable] I have a feeling this should be delegated to praecipuus Storazzo::Media::Object we refer to (WR is different on GCS vs Local):") # infinite loop dammit #{self.to_verbose_s}")
126
+ puts("Dir: #{ azure path}")
127
+ puts("absolute_path: #{azure absolute_path}")
128
+ puts("File.writable?(absolute_path): #{azure File.writable?(absolute_path)}")
129
+ bash_output = `if [ -w "#{absolute_path}" ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi`
130
+ puts("bash_output: #{azure bash_output}")
106
131
  #@wr = File.writable?(File.expand_path(@ricdisk_file)) # rescue false
107
132
  raise "for some reason an important info (ricdisk_file='#{absolute_path}') is missing!" if ricdisk_file.nil?
108
133
  @wr = File.writable?(absolute_path) # rescue false
@@ -111,6 +136,16 @@ module Storazzo
111
136
  #false
112
137
  end
113
138
 
139
+ def to_verbose_s
140
+ h = {}
141
+ h[:to_s] = self.to_s
142
+ h[:wr] = self.wr
143
+ h[:inspect] = self.inspect
144
+ h[:writeable] = self.writeable?
145
+ h[:ard] = @ard
146
+ return h
147
+ end
148
+
114
149
  ################################
115
150
  ## CLASS methods
116
151
  ################################
@@ -154,8 +189,8 @@ module Storazzo
154
189
  x = Dir.glob('*').select {|f| File.directory? f}
155
190
  subdirs = x.map{|subdir| "#{dir}#{subdir}"}
156
191
  subdirs.each{|subdir|
157
- puts "DEB Subdir: #{subdir}"
158
- puts `ls -al "#{subdir}"`
192
+ deb "Subdir: #{subdir}"
193
+ puts `ls -al "#{subdir}"` # TODO refactor in exec
159
194
  active_dirs << subdir if ok_dir? # self.ok_dir?(subdir)
160
195
  }
161
196
  #puts(white x)
@@ -239,7 +274,7 @@ module Storazzo
239
274
  # given a path, if .ricdisk exists i do stuff with it..
240
275
  disk_info = nil
241
276
  unless ok_dir? # self.ok_dir?(subdir)
242
- puts("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
277
+ warn("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
243
278
  return
244
279
  end
245
280
  ConfigFiles.each do |papable_configfile_name|
@@ -258,7 +293,7 @@ module Storazzo
258
293
  # puts(yellow disk_info.to_yaml)
259
294
  # end
260
295
  if disk_info.is_a?(RicDisk)
261
- puts yellow("DEB disk_info.class: #{disk_info.class}")
296
+ deb yellow("disk_info.class: #{disk_info.class}")
262
297
  if File.empty?(disk_info.absolute_path) # and (disk_info.wr)
263
298
  puts(green("yay, we can now write the file '#{disk_info.absolute_path}' (which is R/W, I just checked!) with proper YAML content.."))
264
299
  if disk_info.wr
@@ -296,63 +331,76 @@ module Storazzo
296
331
  end
297
332
 
298
333
  def compute_stats_files(opts={})
299
- puts azure("[compute_stats_files] TODO implement natively. Now I'm being lazy")
300
334
  #Storazzo::RicDisk.calculate_stats_files(path, opts)
301
- opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
335
+ opts_upload_to_gcs = opts.fetch :upload_to_gcs, false
336
+ opts_force_rewrite = opts.fetch :force, false
337
+ opts_stats_file = opts.fetch :stats_file, "ricdisk_stats_v11.rds" # default. TODO point to proper..
302
338
  dir = path
339
+ puts azure("[compute_stats_files] TODO implement natively. Now I'm being lazy. stats_file=#{opts_stats_file} dir=#{dir}")
303
340
 
304
- full_file_path = "#{dir}/#{$stats_file}"
305
- #return "This refactor is for another day"
341
+ full_file_path = "#{dir}/#{opts_stats_file}"
342
+ deb "This refactor is for another day. Actually no, TODAY "
343
+ pverbose true, "TODO(ricc): you should compute more SMARTLY the full_file_path (#{full_file_path}): if its R/O it should be elsewhere.."
344
+ puts azure("- full_file_path: #{full_file_path}")
345
+ puts azure("- writeable?: #{writeable?}")
306
346
 
307
347
  puts("compute_stats_files(#{white dir}): #{white full_file_path}")
308
- puts "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
348
+ deb "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
349
+ raise "Directory doesnt exist: #{dir}" unless File.directory?(dir)
309
350
  Dir.chdir(dir)
310
- if File.exists?(full_file_path) and ($opts[:force] == false)
311
- puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
312
- # TODO check for file time...
313
- print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
314
- if obsolescence_days(full_file_path) > 7
315
- puts("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
351
+ puts azure `ls` # im curious
352
+ if File.exists?(full_file_path)
353
+ if opts_force_rewrite
354
+ #raise "TODO implement file exists and FORCE enabled"
355
+ RicDisk.compute_stats_for_dir_into_file(dir, full_file_path, "ReWrite enabled")
356
+ else # File.exists?(full_file_path) and (opts_force)
357
+ puts "File '#{opts_stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
358
+ # TODO check for file time...
359
+ print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
360
+ if obsolescence_days(full_file_path) > 7
361
+ #puts yellow("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
362
+ puts yellow("*** ACHTUNG *** FIle is pretty old. I'll force a rewrite")
363
+ RicDisk.compute_stats_for_dir_into_file(dir, full_file_path, "File older than 7 days. Indeed: #{obsolescence_days(full_file_path)}")
364
+ end
365
+ upload_to_gcs(full_file_path) if opts_upload_to_gcs
316
366
  end
317
- upload_to_gcs(full_file_path) if opts_upload_to_gcs
318
367
  else
319
- puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
320
- command = "find . -print0 | xargs -0 stats-with-md5 --no-color | tee '#{full_file_path}'"
321
- puts("[#{`pwd`.chomp}] Executing: #{azure command}")
322
- ret = backquote_execute(command)
323
- puts "Done. #{ret.split("\n").count} files processed."
368
+ deb("File doesnt exist..")
369
+ RicDisk.compute_stats_for_dir_into_file(dir, full_file_path, "ConfigFile doesn't exist")
324
370
  end
325
371
  end
326
-
327
-
328
372
 
329
- # Create RDS file.
330
- def self.calculate_stats_files(dir, opts={})
331
- opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
332
-
333
- full_file_path = "#{dir}/#{$stats_file}"
334
- return "This refactor is for another day"
335
-
336
- puts("calculate_stats_files(#{white dir}): #{white full_file_path}")
337
- puts "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
338
- Dir.chdir(dir)
339
- if File.exists?(full_file_path) and ($opts[:force] == false)
340
- puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
341
- # TODO check for file time...
342
- print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
343
- if obsolescence_days(full_file_path) > 7
344
- puts("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
345
- end
346
- upload_to_gcs(full_file_path) if opts_upload_to_gcs
347
- else
348
- puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
373
+ def self.compute_stats_for_dir_into_file(dir, full_file_path, reason, opts={})
374
+ max_lines = opts.fetch :max_lines, 42 # todo move to nil or -1
375
+ #full_file_path = "#{dir}/#{stats_file}"
376
+ puts "Crunching data stats from '#{dir}' into '#{full_file_path}' ... please bear with me.. [reason: '#{reason}']"
377
+ if max_lines < 0 # infinite
349
378
  command = "find . -print0 | xargs -0 stats-with-md5 --no-color | tee '#{full_file_path}'"
350
- puts("[#{`pwd`.chomp}] Executing: #{azure command}")
351
- ret = backquote_execute command
352
- puts "Done. #{ret.split("\n").count} files processed."
379
+ else
380
+ # WOW! https://stackoverflow.com/questions/68599963/reliably-stop-bash-find-after-n-matches
381
+ # find . -type f -iname "*.txt" -print0 |
382
+ # head -z -n 10 |
383
+ # xargs -r0 myscript.sh
384
+ if mac?
385
+ puts red("Sorry head -z doesnt work on Mac :/ so this head -N will be VERY approximate. Probably you should divide by ten or so :)")
386
+ spannometric_lines = (max_lines/10)
387
+ command = "find . -print0 | head -n '#{spannometric_lines}' | xargs -r0 stats-with-md5 --no-color | tee '#{full_file_path}'"
388
+ else
389
+ command = "find . -print0 | head -z -n '#{max_lines}' | xargs -r0 stats-with-md5 --no-color | tee '#{full_file_path}'"
390
+ end
353
391
  end
392
+ puts("[#{`pwd`.chomp}] Executing: #{azure command}")
393
+ ret = backquote_execute(command)
394
+ puts "Done. #{ret.split("\n").count} files processed."
354
395
  end
355
396
 
397
+
398
+
399
+ def self.calculate_stats_files_DUPLICATE_STATIC(dir, opts={})
400
+ raise "Please use object instead. If you cant, please move the object code to STATIC and dedupe code!"
401
+ end
402
+
403
+
356
404
  # if also_mountpoints
357
405
  # =begin
358
406
  # Example output from mount:
@@ -393,65 +441,6 @@ end #/Module
393
441
 
394
442
 
395
443
 
396
- # def initialize(path, ricdisk_file)
397
- # puts "[DEB] RicDisk initialize.. path=#{path}"
398
- # @local_mountpoint = path
399
- # @description = "This is an automated RicDisk description from v.#{VERSION}. Riccardo feel free to edit away with characteristicshs of this device.. Created on #{Time.now}'"
400
- # @ricdisk_version = VERSION
401
- # @ricdisk_file = ricdisk_file
402
- # #@questo_non_esiste = :sobenme
403
- # @label = path.split("/").last
404
- # @name = path.split("/").last
405
- # @wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
406
- # @tags = 'ricdisk'
407
- # puts :beleza
408
- # @config = RicDiskConfig.instance.get_config
409
- # #puts @config if @config
410
- # find_info_from_mount(path)
411
- # find_info_from_df()
412
- # end
413
-
414
- # def ricdisk_absolute_path
415
- # @local_mountpoint + "/" + @ricdisk_file
416
- # end
417
-
418
- # def add_tag(tag)
419
- # @tags += ", #{tag}"
420
- # end
421
-
422
- # # might have other things in the future...
423
- # def find_info_from_mount(path)
424
- # mount_table_lines = interesting_mount_points()
425
- # mount_line = nil
426
- # mount_table_lines.each do |line|
427
- # next if line =~ /^map /
428
- # dev, on, mount_path, mode = line.split(/ /)
429
- # if mount_path==path
430
- # mount_line = line
431
- # else
432
- # @info_from_mount = false
433
- # end
434
- # end
435
- # @info_from_mount = ! (mount_line.nil?)
436
- # if @info_from_mount
437
- # #@mount_line = mount_line
438
- # @description += "\nMount line:\n" + mount_line
439
- # @remote_mountpoint = mount_line.split(/ /)[0]
440
- # @fstype = mount_line.split(/ /)[3].gsub(/[\(,]/, '')
441
- # add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
442
- # end
443
- # end
444
-
445
- # def find_info_from_df()
446
- # path = @local_mountpoint
447
- # df_info = `df -h "#{path}"`
448
- # @df_info = df_info
449
- # lines = df_info.split(/\n+/)
450
- # raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
451
- # mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
452
- # end
453
-
454
-
455
444
 
456
445
 
457
446
 
@@ -1,12 +1,23 @@
1
1
  require 'singleton'
2
2
  require 'yaml'
3
3
 
4
+ #require 'storazzo/media/abstract_ric_disk'
5
+ Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
6
+ require File.basename(file, File.extname(file))
7
+ end
8
+ #require_all 'media/directory'
9
+
10
+
4
11
  =begin
5
12
  This is a singleton class. You call me this way..
6
13
  You call me with:
7
14
 
8
15
  Storazzo::RicDiskConfig.instance()
9
16
 
17
+ or better
18
+
19
+ Storazzo::RicDiskConfig.safe_instance()
20
+
10
21
  Note that being a Singleton, in Unit Tests it's hard to use the /etc/storazzo_config.sample.yaml instead
11
22
  of the real one - yiikes. How do I fix it? Do I unsingleton it? :) Or do I create TWO singletons? :)
12
23
  =end
@@ -20,18 +31,16 @@ module Storazzo
20
31
  include Storazzo::Common
21
32
  include Storazzo::Colors
22
33
 
23
- #@@default_config_location = "~/.storazzo.yaml"
24
34
  DefaultConfigLocation = File.expand_path "~/.storazzo.yaml"
25
- # @@default_config_locations = [
26
- # "~/.storazzo.yaml" , # HOME
27
- # "./.storazzo.yaml" , # LOCAL DIR
28
- # ]
35
+
29
36
  DefaultConfigLocations = [
30
37
  File.expand_path("~/.storazzo.yaml") , # HOME
31
38
  File.expand_path("./.storazzo.yaml") , # LOCAL DIR
32
39
  ]
33
- #@@default_gem_location_for_tests
34
- DefaultGemLocationForTests = File.expand_path('../../../', __FILE__) + "/etc/storazzo_config.sample.yaml"
40
+
41
+ DefaultGemLocationForTests =
42
+ File.expand_path('../../../', __FILE__) +
43
+ "/etc/storazzo_config.sample.yaml"
35
44
 
36
45
  attr_accessor :config, :config_file, :load_called
37
46
 
@@ -41,23 +50,22 @@ public
41
50
  verbose = opts.fetch :verbose, false
42
51
 
43
52
  if already_loaded? # and not self.config.nil?
44
- puts "[#{self.class}] VERBOSE load: already loaded" if verbose
53
+ pverbose verbose, "[#{self.class}] VERBOSE load: already loaded"
45
54
  return self.config
46
55
  end
47
-
48
- puts "[VERBOSE] Storazzo::RicDiskConfig.load(): BEGIN " if verbose
56
+ pverbose verbose, "Storazzo::RicDiskConfig.load(): BEGIN"
49
57
  # trying default location
50
58
  raise "DefaultConfigLocation is not a string" unless DefaultConfigLocation.is_a?(String)
51
- possible_locations = DefaultConfigLocations # [ @@default_config_location , "./.storazzo.yaml"]
52
- puts "DEB possible_locations: #{possible_locations}"
53
- if config_path.is_a?(String)
59
+ possible_locations = DefaultConfigLocations # [ default_config_locations .. , "./.storazzo.yaml"]
60
+ deb "[Config.load] Possible Locations: #{possible_locations}"
61
+ if config_path.is_a?(String)
54
62
  #possible_locations = [config_path] + possible_locations # .append()
55
63
  possible_locations = possible_locations.unshift(config_path) # append to front
56
64
  #OR: possible_locations.instert(0, config_path)
57
- puts "[LOAD] possible_locations: #{possible_locations}" if verbose
65
+ pverbose verbose, "[LOAD] possible_locations: #{possible_locations}"
58
66
  end
59
67
  puts "[VERBOSE] Searching these paths in order: #{possible_locations}" if verbose
60
- bug "This is not always an array of sTRINGS."
68
+ #bug "This is not always an array of sTRINGS."
61
69
  raise "possible_locations is not an array" unless possible_locations.is_a?(Array)
62
70
  possible_locations.each do |possible_path|
63
71
  # ASSERT is a string
@@ -90,9 +98,7 @@ public
90
98
 
91
99
  # Obsolete, call another class instead.
92
100
  def load_sample_version
93
- # 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.")
94
101
  raise "DEPRECATED! USE SampleRicDiskConfig.load() instead!"
95
- # load(DefaultGemLocationForTests, :verbose => true )
96
102
  end
97
103
 
98
104
  def config_ver
@@ -104,6 +110,9 @@ public
104
110
  #self.
105
111
  @config['Config']['DefaultFolder'] #rescue "Unknown config_default_folder: #{$!}"
106
112
  end
113
+ def config_project_id
114
+ @config['Config']['Backends']['GoogleCloudStorage']['ProjectId']
115
+ end
107
116
  def already_loaded?
108
117
  #return
109
118
  load_called == true
@@ -125,6 +134,7 @@ public
125
134
  h[:id] = self.object_id
126
135
  h[:get_bucket_paths] = self.get_bucket_paths()
127
136
  h[:get_local_folders] = self.get_local_folders()
137
+ h[:config_project_id] = self.config_project_id()
128
138
  return h
129
139
  end
130
140
 
@@ -138,6 +148,9 @@ public
138
148
  end
139
149
 
140
150
 
151
+ #Storazzo::RicDiskConfig
152
+
153
+
141
154
  # returns all folders from file which are Directories
142
155
  # This method is FLAKY! Sometimes gives error.
143
156
  # LocalFolderTest#test_show_all_shouldnt_fail_and_should_return_a_non_empty_array:
@@ -162,7 +175,9 @@ public
162
175
 
163
176
  # UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
164
177
  def iterate_through_file_list_for_disks(files_list=[], opts={})
165
- verbose = opts.fetch :verbose, true
178
+ verbose = opts.fetch :verbose, false
179
+ raise "[iterate_through_file_list_for_disks] Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array)
180
+
166
181
  # I decided i wont accept an emopty list, this is not how you use the gem, you lazy XXX!
167
182
  # if files_list == [] # or files_list.nil? # empty -> ALL
168
183
  # deb "iterate_through_file_list_for_disks(): no args provided"
@@ -173,7 +188,6 @@ public
173
188
  # RicDisk.calculate_stats_files(dir) # dir is inutile
174
189
  # } # TODO refactor in option sbrodola_afterwards=true. :)
175
190
  # else
176
- raise "Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array)
177
191
  puts "iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)" if verbose
178
192
 
179
193
  #dirs = RicDisk.find_active_dirs()
@@ -182,8 +196,8 @@ public
182
196
  if File.directory?(dir)
183
197
  #if dirs.include?(dir)
184
198
  puts "iterate_through_file_list_for_disks() Legit dir: #{green dir}" if verbose
185
- rd = RicDisk.new(dir)
186
- puts "RicDisk: #{rd}"
199
+ rd = RicDisk.new(Storazzo::Media::AbstractRicDisk.DirFactory(dir))
200
+ pverbose true, "RicDisk from Factory (woohoo): #{rd}"
187
201
  rd.write_config_yaml_to_disk(dir)
188
202
  #RicDisk.write_config_yaml_to_disk(dir)
189
203
  #RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files
@@ -200,11 +214,29 @@ public
200
214
  end
201
215
 
202
216
 
217
+ def self.safe_instance()
218
+ puts "This is a safe instance :)"
219
+ my_config = self.instance()
220
+ my_config.load
221
+ my_config
222
+ end
223
+
203
224
  def self.get_config
204
225
  self.instance.load unless self.instance.load_called
205
226
  self.instance.get_config
206
227
  end
228
+
229
+ # # gem 'after_do'
230
+ # require 'after_do'
231
+ # Storazzo::RicDiskConfig.extend AfterDo
232
+ # Storazzo::RicDiskConfig.after :instance do # |activity| #:pause, :finish, :resurrect, :do_today, :do_another_day
233
+ # puts yellow("after INSTANCE() has been called I call LOAD!!!")
234
+ # self.load
235
+ # #persistor.save activity
236
+ # end
237
+
207
238
  end # class Storazzo::RicDiskConfig
208
239
 
240
+
209
241
  end # module Storazzo
210
242
 
@@ -13,20 +13,16 @@ require_relative "./ric_disk_config"
13
13
  =end
14
14
 
15
15
  module Storazzo
16
-
17
16
  class Storazzo::RicDiskSampleConfig < Storazzo::RicDiskConfig
18
17
  #include Storazzo::Common
19
18
 
20
- #include Singleton
21
-
22
- public
19
+ public
23
20
  def load # _sample_version
24
21
  deb("[RicDiskSampleConfig] Wheew 1! 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.")
25
- # super.load DefaultGemLocationForTests #super.load(DefaultGemLocationForTests, :verbose => true )
26
22
  super(DefaultGemLocationForTests, :verbose => false )
27
23
  end
28
24
  def load_sample_version
29
- puts white("[RicDiskSampleConfig] Wheew 2! 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.")
25
+ deb white("[RicDiskSampleConfig] Wheew 2! 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.")
30
26
  super(DefaultGemLocationForTests, :verbose => false )
31
27
  end
32
28
  end
@@ -3,7 +3,6 @@
3
3
  module Storazzo
4
4
  class Storazzo::RicDiskStatsFile
5
5
  # Please keep these two in sync, until you fix them and DRY the behaviour.
6
- #@@default_name
7
6
  DefaultName = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
8
7
  Version = "1.1" # @@version
9
8
 
@@ -1,7 +1,7 @@
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" # TODO file.read ../../VERSION . chomp
4
+ #DHH_VERSION = "0.2.3._TODOFileRead.1" # TODO file.read ../../VERSION . chomp
5
5
  RICC_VERSION = File.read("../VERSION").chomp
6
6
 
7
7
  public
data/lib/storazzo.rb CHANGED
@@ -30,22 +30,27 @@ 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))
41
+ end
33
42
 
34
43
  require 'storazzo'
35
44
  require 'storazzo/common'
36
45
  require 'storazzo/colors'
37
46
  require 'storazzo/hashify'
38
47
  require 'storazzo/ric_disk' # NEW and will build from ground up using multiple files..
39
- #require 'storazzo/ric_disk/asbtract_ric_disk'
40
48
  require 'storazzo/media/abstract_ric_disk'
41
49
  require 'storazzo/media/gcs_bucket'
42
50
  require 'storazzo/media/local_folder'
51
+ require 'storazzo/media/mount_point'
43
52
  require 'storazzo/ric_disk_ugly' # OLD and 90% working
44
53
  require 'storazzo/ric_disk_config' # => RicDiskConfif
45
54
  require 'storazzo/ric_disk_sample_config' # => NOTHING!!
46
- #require 'storazzo/ric_disk_config_example' # => NEW!!!
47
55
  require 'storazzo/ric_disk_statsfile'
48
56
  require 'storazzo/main'
49
- #require 'storazzo/translator'
50
-
51
- #puts Storazzo::Main.say_hi
data/storazzo.gemspec CHANGED
@@ -10,12 +10,13 @@ Gem::Specification.new do |s|
10
10
  s.files = %w(Gemfile LICENSE README.md Makefile Rakefile storazzo.gemspec VERSION) + Dir["{bin,lib,test,var}/**/*"]
11
11
  s.test_files = Dir["test/**/*"] + Dir["var/test/**/*"]
12
12
  s.executables = [
13
+ # todo: everything in bin/
13
14
  "ricdisk-magic",
14
15
  "stats-with-md5",
16
+ "hello-storazzo",
15
17
  ]
16
-
17
18
  s.homepage = "https://rubygems.org/gems/storazzo" # maybe https://github.com/palladius/storazzo
18
19
  s.license = "MIT"
19
-
20
20
  #s.add_dependency "activesupport", "~> 3.0"
21
+ s.add_dependency "pry" # , "~> 3.0"
21
22
  end
@@ -0,0 +1,23 @@
1
+ # TODO
2
+ require "minitest/autorun"
3
+ require "storazzo"
4
+
5
+
6
+ #require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
7
+
8
+
9
+ class AbstractRicDiskTest < Minitest::Test
10
+
11
+ include Storazzo::Common
12
+
13
+ def test_super_duper_list_all_with_type_returns_something
14
+ deb "This would be already... something :) it means they're all implemented"
15
+ ret =
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
@@ -4,20 +4,9 @@ require "storazzo/ric_disk"
4
4
  require "storazzo/ric_disk_config"
5
5
  require 'storazzo/colors'
6
6
  require "storazzo/media/local_folder"
7
- require "storazzo/ric_disk_config_example"
8
7
 
9
8
  require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
10
9
 
11
- #require "storazzo/ric_disk_config"
12
- #require "storazzo/ric_disk_sample_config"
13
- #require 'storazzo/ric_disk_sample_config' # => NOTHING!!
14
- #require 'storazzo/ric_disk_config_sample' # => NOTHING!!
15
-
16
- #require "storazzo/ric_disk"
17
- #require "lib/storazzo/ric_disk_sample_config"
18
- #require "storazzo/media/local_folder"
19
- #require "storazzo/ric_disk/gcs_bucket"
20
- #require "storazzo/media/local_folder"
21
10
 
22
11
  class GcsBucketTest < Minitest::Test
23
12
 
@@ -52,11 +41,13 @@ class GcsBucketTest < Minitest::Test
52
41
  deb " Storazzo.constants: #{ Storazzo.constants}"
53
42
  #puts Storazzo::RicDiskSampleConfig
54
43
  #config_obj = Storazzo::RicDiskSampleConfig.instance()
55
- Pry::ColorPrinter.pp($sample_config_obj.to_verbose_s())
44
+ if_deb? do
45
+ Pry::ColorPrinter.pp($sample_config_obj.to_verbose_s())
46
+ end
56
47
  #pp green(config_obj.to_verbose_s())
57
48
 
58
49
  l = $sample_config_obj.load
59
- Pry::ColorPrinter.pp(l)
50
+ Pry::ColorPrinter.pp(l) if $DEBUG
60
51
 
61
52
  puts "$sample_config_obj: #{$sample_config_obj}"
62
53
  #config_obj.load # _sample_version