storazzo 0.2.2 → 0.3.7

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: 75b835462aa0c27cc1ba757bbd80eedda8922fa24dce607ce47a191e242ab384
4
- data.tar.gz: c7b3124551abc5da4378411b7dd1cd8e79fcf298973ad5f18b55b5fe5742afe0
3
+ metadata.gz: 6478359f1db5708d42ebe8251f985481629d4255a119ce5a52952572863c94e5
4
+ data.tar.gz: 8832a4178e0ed56687e6f494898f1902069c195c20f6474d20fd0981ad0bd3e7
5
5
  SHA512:
6
- metadata.gz: 5be4a025c291a432ae9f07ab75f84c405e77562c3a7c673d2581c19b693294385265ecababb96521ec16a605233d825fd4042511914df8b0adae298a01217a0a
7
- data.tar.gz: b853906799fea55cbf8579b546603e7297fcaf57a488ff49ae714cf07efde40eefc1749666757209764723c2208809ace495ff8dba9a0323442acaa377c81e51
6
+ metadata.gz: df7a71868983eef6299a94dc4af98e232519d79414c15321c6548411ee8590b9bcb2b8c1418a94aae46993093850156bd595b1293396d55e1e0c0db891085095
7
+ data.tar.gz: a69cc8ffc1ab17409df2635ff7aa58af329d7572498ecef00d215dca31d3c92314ae2e0c975c74eddbd5f2e69e34807b91b4ecd2bed4519e1a9dbddb31bfacaf
data/Gemfile CHANGED
@@ -3,3 +3,4 @@
3
3
 
4
4
  # to troubleshoot/debug things
5
5
  #gem 'rubocop'
6
+ gem 'rake'
data/Makefile CHANGED
@@ -17,11 +17,13 @@ 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
23
25
 
24
- test:
26
+ test-all:
25
27
  echo 1. Testing the library end to end by requiring it..
26
28
  echo "Storazzo::Main.all_tests " | irb -Ilib -rstorazzo
27
29
  make mounts
@@ -33,6 +35,9 @@ test:
33
35
  make irb-test
34
36
  @echo 'OK: ALL TESTS PASSED. #STIKA'
35
37
 
38
+ test:
39
+ RUBYOPT="-W0" rake test
40
+
36
41
  # RicDisk test
37
42
  mounts:
38
43
  echo "Storazzo::Main.all_mounts ; nil" | irb -Ilib -rstorazzo
@@ -43,4 +48,7 @@ irb-test:
43
48
  ./irb-test.sh
44
49
 
45
50
  watch-test:
46
- 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.2.2
1
+ 0.3.7
data/bin/ricdisk-magic CHANGED
@@ -5,19 +5,27 @@
5
5
  ############# ############# ############# ############# ############# ############# ############# #############
6
6
  # placeholder until i make it work..
7
7
  # https://guides.rubygems.org/make-your-own-gem/#adding-an-executable
8
- require 'storazzo'
8
+ #require 'storazzo'
9
+ #require_relative '../lib/storazzo'
10
+ require 'fileutils'
9
11
  require 'yaml'
10
12
  require 'socket'
11
13
  require 'optparse' # http://ruby.about.com/od/advancedruby/a/optionparser.htm
12
14
 
13
- include Storazzo
14
- include Storazzo::Colors
15
+ # Including local gem.
16
+ #puts File.expand_path(FileUtils.pwd, "/../")
17
+ #local_gem_path = File.expand_path(FileUtils.pwd, "/../")
18
+ #gem 'storazzo', path: local_gem_path
19
+ require 'storazzo'
20
+ #include Storazzo
21
+ #include Storazzo::Colors
22
+ extend Storazzo::Colors
23
+ include Storazzo::Common #instead
15
24
 
16
- #require_relative '../lib/storazzo'
17
25
 
18
- puts "First I need to figure out how to bring in all the libraries in here.."
19
- puts Storazzo::Main.hi(ARGV.join '::')
20
- #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
21
29
  ############# ############# ############# ############# ############# ############# ############# #############
22
30
 
23
31
 
@@ -33,7 +41,9 @@ if RUBY_VERSION.split('.')[0] == 1
33
41
  end
34
42
 
35
43
  $PROG_VER = '0.4'
36
- $DEBUG = true
44
+ $DEBUG = ENV['DEBUG'] == 'true' # (true/false)
45
+ # p ENV['DEBUG']
46
+ # p $DEBUG
37
47
 
38
48
  HISTORY = <<-BIG_LONG_MULTILINE
39
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 :)
@@ -60,8 +70,15 @@ $myconf = {
60
70
  :app_name => "RicDisk Magic should be sth like #{$0}",
61
71
  :description => "
62
72
  This program is loosely inspired to ricdisk-magic.sh but its much better.
63
- Idea di base: trovare tutti le directory con file ricdisk e da esso estrarre info e magari METTERE info.
64
- 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
65
82
  ".strip.gsub(/^\s+/, "").gsub(/\s+$/, ""),
66
83
  # TODO move to some class default
67
84
  :media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
@@ -118,8 +135,11 @@ def real_program
118
135
  puts white("Hello world from #{$myconf[:app_name]}!")
119
136
  puts "Description: '''#{white $myconf[:description] }'''"
120
137
 
121
-
122
- config = RicDiskConfig.load # auto_sbrodola(ARGV)
138
+ config = Storazzo::RicDiskConfig.instance()
139
+ config.load
140
+ puts "StorazzoConfig: #{config}"
141
+ #config.load # auto_sbrodola(ARGV)
142
+ puts yellow("ARGV: #{ARGV}")
123
143
  config.iterate_through_file_list_for_disks(ARGV)
124
144
 
125
145
  # if ARGV == [] # empty -> ALL
@@ -150,8 +170,15 @@ def main(filename)
150
170
  deb "HISTORY: #{gray HISTORY}"
151
171
  #deb "To remove this shit, just set $DEBUG=false :)"
152
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
153
174
  #warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
154
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
155
182
  end
156
183
 
157
184
  main(__FILE__)
@@ -1,5 +1,9 @@
1
1
  # Use EXTEND vs INCLUDE and magically the Class will inherit instead of instance. Magical! :)
2
2
  # http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
3
+ #
4
+ # include Storazzo::Colors
5
+ # extend Storazzo::Colors
6
+ #
3
7
 
4
8
  module Storazzo
5
9
  # needs to be defined before
@@ -9,7 +13,8 @@ module Storazzo::Colors
9
13
 
10
14
  PREPEND_ME = "[Storazzo::Colors] "
11
15
 
12
- 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
13
18
 
14
19
  # colors 16
15
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
data/lib/storazzo/main.rb CHANGED
@@ -19,7 +19,7 @@ module Storazzo
19
19
  extend Storazzo::Colors
20
20
 
21
21
  # version 1.2
22
- def self.hi(message=nil)
22
+ def self.say_hi(message=nil)
23
23
  str = "Hello from Storazzo v#{white Storazzo::version rescue "Error: #{$!}"}!"
24
24
  str += " Message: '#{yellow message.to_s}'" if message
25
25
  puts str
@@ -29,7 +29,7 @@ module Storazzo
29
29
  def self.all_mounts(opts={})
30
30
  opts_verbose = opts.fetch :verbose, true
31
31
 
32
- self.hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDiskUgly::RICDISK_VERSION}"
32
+ self.say_hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDiskUgly::RICDISK_VERSION}"
33
33
 
34
34
  pwhite("1. First I load the config in verbose mode..")
35
35
  config = Storazzo::RicDiskConfig.instance
@@ -55,7 +55,7 @@ module Storazzo
55
55
 
56
56
  pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
57
57
  deb "Maybe debug is enabled?"
58
- hi
58
+ say_hi
59
59
  # This works with EXTEND..
60
60
  puts(yellow "Just YELLOW 0")
61
61
  # This reqwuires a INCLUDE.
@@ -0,0 +1,14 @@
1
+
2
+ Here I put all generic Media::Something classes. I can think of a few:
3
+
4
+ * `LocalFolder`: the simplest and uselesser thing ever. Done mostly for troubleshooting
5
+ * `MountFolder`: comes from mount, can get listed by mount, and usually has long latency
6
+ * `GcsBucket`. From Google Cloud Storage. Why? Spoiler alert: It's my employer :) But happy to support more in the unlikely event this gem goes viral like *Corsivoe*.
7
+
8
+ They all implement a few methods like:
9
+
10
+ * `list_all`: shows all available objects in local system, leveraging the storazzo config file.
11
+ * `parse`: parse the disk in initialized file. Then if system is writeable, writes in it the listing. If not, puts in a apposite folder defined by Storazzo.config.
12
+ * `writeable?`:
13
+ * `local_mountpoint`: local path or mountpoint. The local variable shjould be
14
+ @local_mountpoint explicitly. TODO check this in abtsract class.
@@ -0,0 +1,106 @@
1
+ module Storazzo::Media
2
+ class Storazzo::Media::AbstractRicDisk
3
+
4
+ #@@default_stats_filename = Storazzo::RicDiskStatsFile.default_name
5
+
6
+ # looks like there's not Abstract Class in Ruby, but also SO says he best
7
+ # way to do this is this:
8
+
9
+ # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
10
+
11
+ ########################
12
+ # Abstract methods START
13
+ ########################
14
+ def initialize(local_mount)
15
+ puts "[DEB] [AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
16
+ validate
17
+ end
18
+ def self.list_all
19
+ raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo"
20
+ end
21
+ def parse(opts={})
22
+ raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo"
23
+ end
24
+ def writeable?
25
+ raise "[AbstractRicDiskc::writeable] You should override this in #{self.class}, says StackOverflow and Riccardo"
26
+ end
27
+ def get_local_mountpoint
28
+ #raise "[AbstractRicDiskc::get_local_mountpoint] You should override this, says StackOverflow and Riccardo"
29
+ raise "You forgot to set local_mountpoint in the constructor for your class, you cheeky little one!" if local_mountpoint.nil?
30
+ local_mountpoint
31
+ end
32
+ def check_implemented_correctly
33
+ # raise "[AbstractRicDiskc] You should override this, says StackOverflow and Riccardo"
34
+ raise "no @local_mountpoint" unless exists?(@local_mountpoint)
35
+ end
36
+ ########################
37
+ # Abstract methods END
38
+ ########################
39
+
40
+
41
+
42
+ ########################
43
+ # Automated methods now...
44
+ ########################
45
+ def stats_file_smart_fullpath # stats_file_default_location()
46
+ # if its writeable... if not we'll think about it later.
47
+ if writeable?
48
+ return "#{get_local_mountpoint}/#{self.default_stats_filename}"
49
+ else
50
+ # if not writeable, I will:
51
+ # 1. create a dir based on its unique format.
52
+ # 2. create a file of same look and feel (alternative - used a DASH)
53
+ return "{get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
54
+ #"{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
55
+ end
56
+ end
57
+ # Needs to be some unique id based on its thingy, but might change in the future:
58
+ # Solutions:
59
+ # {PHILOSOPHY}::{ID}
60
+ def unique_id
61
+ # Expand path to make it as unique as possible...
62
+ hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
63
+ "MD5::v1::#{hash}"
64
+ end
65
+
66
+ # # Todo check on instances these 3 methods exist
67
+ def self.abstract_class_mandatory_methods
68
+ %W{
69
+ self.list_all
70
+ local_mountpoint
71
+ parse
72
+ writeable?
73
+ }
74
+ end
75
+
76
+ # Putting here since its same code for MountPoint or generic folder.
77
+ def parse_block_storage_folder(opts={})
78
+ #Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint)
79
+ Storazzo::RicDisk.calculate_stats_files(get_local_mountpoint, opts)
80
+ #return "42"
81
+ end
82
+
83
+ def self.default_stats_filename
84
+ raise "Unknown Storazzo::RicDiskStatsFile.default_name 1!!" if Storazzo::RicDiskStatsFile.default_name.nil?
85
+ Storazzo::RicDiskStatsFile.default_name
86
+ end
87
+
88
+ def stats_filename_default_fullpath # if not writeable we need to pick another from stats_file_smart_fullpath()
89
+ # REDUNDANT, should use stats_file_smart_fullpath instead except on the writeable? part since it would go recursive otherwise.
90
+ my_stats_filename = self.default_stats_filename
91
+ #raise "Unknown Storazzo::RicDiskStatsFile.default_name 2 !!" if Storazzo::RicDiskStatsFile.default_name.nil?
92
+ "#{local_mountpoint}/#{my_stats_filename}"
93
+ end
94
+
95
+ def validate
96
+ puts "DEB We're trying to see if your object is valid, across 3 possible sub-classes."
97
+ #1. check for
98
+ raise "Unknown local mount " unless local_mount.is_a?(String)
99
+ #2. check thaty writeable? is true or false
100
+ my_writeable = wr
101
+ raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass )
102
+ end
103
+ end
104
+ #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD inside module"
105
+ end
106
+ #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD outside module"
@@ -0,0 +1,20 @@
1
+ module Storazzo::Media
2
+
3
+ class Storazzo::RicDisk::GcsBucket
4
+
5
+
6
+ def self.list_all
7
+ # get lisrts from Config singletone
8
+ #puts " self.list_all: loading config "
9
+ config = Storazzo::RicDiskConfig.instance # # ).get_config
10
+ #puts config['Config']['AdditionalMountDirs']
11
+ #puts "TODO see config: #{config}"
12
+ #[42, 43]
13
+ #deb config.get_local_folders
14
+ config.get_bucket_paths
15
+ end
16
+
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,51 @@
1
+ #require "storazzo/ric_disk/abstract_ric_disk"
2
+ #require "abstract_ric_disk"
3
+
4
+ module Storazzo::Media
5
+ class Storazzo::Media::LocalFolder < Storazzo::Media::AbstractRicDisk
6
+
7
+ attr_accessor :local_mountpoint, :wr
8
+
9
+ def initialize(local_mount)
10
+ puts "[Storazzo::Media::LocalFolder] initialize"
11
+
12
+ @local_mountpoint = File.expand_path(local_mount)
13
+ raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
14
+ @wr = File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
15
+
16
+ #super.initialize(local_mount) rescue "SUPER_ERROR: #{$!}"
17
+ super(local_mount) rescue "SUPER_ERROR: #{$!}"
18
+ end
19
+
20
+ def self.list_all
21
+ # get lisrts from Config singletone
22
+ #puts " self.list_all: loading config "
23
+ config = Storazzo::RicDiskConfig.instance # # ).get_config
24
+ #puts config['Config']['AdditionalMountDirs']
25
+ #puts "TODO see config: #{config}"
26
+ #[42, 43]
27
+ #deb config.get_local_folders
28
+ config.get_local_folders
29
+ end
30
+
31
+ def parse(opts={})
32
+ puts "LF.parse(#{opts}): TODO Sbrodola inside the dir: #{local_mountpoint}"
33
+ parse_block_storage_folder()
34
+ end
35
+
36
+ def path
37
+ @local_mountpoint
38
+ end
39
+
40
+ def writeable?
41
+ File.writable?(@local_mountpoint)
42
+ end
43
+
44
+ def default_stats_filename
45
+ #'42'
46
+ Storazzo::RicDiskStatsFile.default_name
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,5 @@
1
+ # TODO
2
+
3
+ # def writeable?
4
+ #File.writable?(@local_mountpoint)
5
+ #end