storazzo 0.4.2 → 0.4.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: 6a489f7c8e545a123a224850369894e939e8bc541ca2b00ce4f2306493144ec2
4
- data.tar.gz: 35f76e4a92849cb0547910ac8f240b38dda4cecaf70ceec0b6d665d6d5d3ce5f
3
+ metadata.gz: 474eb4be081a7edac52377a5269a24e7c826ed0afbf200ac6b315a220bece1f4
4
+ data.tar.gz: 9d6bbb34885de5bf25ef075dd4bcce0e2a0aaba6714d5a34bee1b220096be140
5
5
  SHA512:
6
- metadata.gz: 3d69dbf50b340e06833ba28cf4219ee6aca33b5466e442377597c825ae0c2adaef2d8be3b4330adee8dde52d693e84f3f69c5208df767e988268f45359e36f27
7
- data.tar.gz: ef9ce00d9af13c84aa2db03996ea383af7494007a2bdd94f799d4720d2cc2aae63106e7bbf74db555c6574180f3948305712d115f757f07a196d96958da74ef5
6
+ metadata.gz: 37ce7a58b0ab2f36dcc681579bb55dfa147c195d37016d1fff9ac5ea390fa469d363e2a0df70a614d0c7acf97fd5db9c6d9eb9275f2926155910d9d8e15d9d6f
7
+ data.tar.gz: 0d6f2863ee75c3a1e653100c7904371028f0838d627c83a286d4bdd0ccfdc699190f4a331c942b6bb4834f4218e50a37853c73827c69d69868294f71dd1172f6
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
- # useless now
2
-
1
+ source "https://rubygems.org"
3
2
 
4
3
  # to troubleshoot/debug things
5
4
  #gem 'rubocop'
6
5
  gem 'rake'
7
- gem 'pry'
6
+ #gem 'pry'
7
+ gem 'pry', :group => :development
8
+ #gem 'require_all' # yup I'm lazy: https://stackoverflow.com/questions/735073/best-way-to-require-all-files-from-a-directory-in-ruby
data/Makefile CHANGED
@@ -51,4 +51,17 @@ watch-test:
51
51
  watch -c make test
52
52
 
53
53
  test-gcs-bucket:
54
- ruby -I test test/test_gcs_bucket.rb
54
+ #echo "Warning this uses the INCLUDED gem not the latest one in development'
55
+ #ruby -I test test/media/test_gcs_bucket.rb
56
+ rake test TEST=test/media/test_gcs_bucket.rb
57
+
58
+ test-local-folder:
59
+ echo "Warning this uses the INCLUDED gem not the latest one in development'
60
+ ruby -I test test/media/test_local_folder.rb
61
+ # https://medium.com/@tegon/quick-guide-to-minitest-arguments-745bf9fe4b3
62
+ test-media-subfolder:
63
+ rake test TEST="test/media/*.rb"
64
+ test-verbose:
65
+ rake test:verbose --verbose
66
+ test-single-file-continuously:
67
+ \watch -n 5 --color rake test TEST="test/media/test_local_folder.rb"
data/README.md CHANGED
@@ -9,6 +9,24 @@
9
9
 
10
10
  (Latest version is hosted in https://rubygems.org/gems/storazzo)
11
11
 
12
+ # Tests
13
+
14
+ I still struggle to enforce the include of LOCAL unchecked code rather than latest required system gem (cmon Ruby!)
15
+ but I found loads of interesting ways to test my code by googling and StoackOverflowing:
16
+
17
+ * `rake test TEST="test/sum_test.rb"`
18
+ * test-gcs-bucket: `ruby -I test test/test_gcs_bucket.rb` (meh - see below)
19
+ * test-media-subfolder: `rake test TEST="test/media/*.rb"`
20
+
21
+ Single test in single file:
22
+
23
+ * `rake test TEST="test/sum_test.rb" TESTOPTS="--name=test_returns_two"` (sample)
24
+ * `rake test TEST="test/media/test_local_folder.rb" TESTOPTS="--name=test_1_first_directory_parsing_actually_works"`
25
+ * `ruby -I test test/test_local_folder.rb -n test_first_directory_parsing_actually_works` (note this includes `storazzo` latest gem
26
+ and doesnt benefit from LATEST code so its NOT good for testing: use RAKE for that).
27
+
28
+
29
+ Now to toggle verbosity I believe I need to go into Rakefile (bummer)
12
30
  # Thanks
13
31
 
14
32
  Inspiration from:
data/Rakefile CHANGED
@@ -3,15 +3,42 @@
3
3
  # from hola: https://guides.rubygems.org/make-your-own-gem/#adding-an-executable
4
4
  require "rake/testtask"
5
5
 
6
- Rake::TestTask.new do |t|
6
+ desc "Run Unit tests"
7
+ Rake::TestTask.new(:test) do |t|
7
8
  t.libs << "test"
9
+ t.libs << "test/media"
10
+ # note this is only useful for this: https://chriskottom.com/articles/command-line-flags-for-minitest-in-the-raw/
8
11
  t.verbose = false
9
12
  t.warning = false
13
+ #puts "[RiccardoOnly]: t.pattern: #{t.pattern}"
14
+ t.pattern = 'test/**/test_*.rb'
10
15
  end
11
16
 
12
- desc "Run tests"
17
+ desc "By default, Run Unit tests"
13
18
  task default: :test
14
19
 
20
+ # Adding test/media directory to rake test.
21
+ desc "Test tests/media/* code sobenem"
22
+ namespace :test do
23
+ desc "Test Verbosely by default since I'm too stupid to toggle via ENV var dammit"
24
+ Rake::TestTask.new(:verbose) do |t|
25
+ t.libs << "test"
26
+ t.libs << "test/media"
27
+ t.verbose = true
28
+ t.warning = true
29
+ t.pattern = 'test/**/test_*.rb'
30
+ $DEBUG = true
31
+ end
32
+ end
33
+ # namespace :verbose_test do
34
+ # desc "Test tests/media/* code"
35
+ # Rake::TestTask.new do |t|
36
+ # t.libs << "test/media"
37
+ # # Rails::TestTask.new(media: 'test:prepare') do |t|
38
+ # t.pattern = 'test/**/test_*.rb'
39
+ # end
40
+ # end
41
+ #Rake::Task['test:run'].enhance ["test:media"]
15
42
 
16
43
  # begin
17
44
  # require 'bundler/setup'
@@ -29,4 +56,7 @@ task default: :test
29
56
  # RuboCop::RakeTask.new do |task|
30
57
  # task.requires << 'rubocop-performance'
31
58
  # task.requires << 'rubocop-rspec'
32
- # end
59
+ # end
60
+
61
+
62
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.5
data/bin/ricdisk-magic CHANGED
@@ -168,7 +168,6 @@ end
168
168
  def main(filename)
169
169
  deb "I'm called by #{white filename}"
170
170
  deb "HISTORY: #{gray HISTORY}"
171
- #deb "To remove this shit, just set $DEBUG=false :)"
172
171
  init # Enable this to have command line parsing capabilities!
173
172
  puts white("$DEBUG is #{$DEBUG }. Tu turn on, call me with -d") unless $DEBUG
174
173
  #warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
data/bin/stats-with-md5 CHANGED
@@ -111,42 +111,9 @@ def compute_stats_and_md5(file)
111
111
  stats = File.stat(file)
112
112
  ret[:stats_object] = stats # TODO deprecate
113
113
  deb("Stats methods: #{stats.methods.sort.join(', ')}")
114
- #deb(stats.ftype)
115
- #puts(stats.methods)
116
114
  deb(stats.ctime)
117
115
  #puts(stats.birthtime rescue (stats.ctime))
118
-
119
- # On Mac:
120
- #<File::Stat
121
- # dev=0x100000f,
122
- # ino=1247768,
123
- # mode=0100644 (file rw-r--r--),
124
- # nlink=1,
125
- # uid=164825 (ricc),
126
- # gid=89939 (primarygroup),
127
- # rdev=0x0 (0, 0),
128
- # size=564,
129
- # blksize=4096,
130
- # blocks=8,
131
- # atime=2022-03-05 22:36:48.373362127 +0100 (1646516208),
132
- # mtime=2022-03-05 22:36:48.176789949 +0100 (1646516208),
133
- # ctime=2022-03-05 22:36:48.176789949 +0100 (1646516208)>
134
-
135
- # On LInux:
136
- #<File::Stat
137
- # dev=0xfe01,
138
- # ino=6293055,
139
- # mode=0100644 (file rw-r--r--),
140
- # nlink=1,
141
- # uid=164825 (ricc),
142
- # gid=89939 (primarygroup),
143
- # rdev=0x0 (0, 0),
144
- # size=7,
145
- # blksize=4096,
146
- # blocks=8,
147
- # atime=2022-06-27 08:49:38.586706861 +0200 (1656312578),
148
- # mtime=2022-03-23 14:28:45 +0100 (1648042125),
149
- # ctime=2022-05-30 10:12:10.381629305 +0200 (1653898330)>
116
+ # On Mac/Linux: see test/dumps/***.yaml
150
117
  ret[:size] = stats.size
151
118
  ret[:mode] = stats.mode
152
119
  # datetimes
@@ -235,7 +202,6 @@ def print_stats_and_md5_for_gcs(mybucket_with_subdir, opts={})
235
202
  puts "print_stats_and_md5_for_gcs(): Generic Error: #{$!}"
236
203
  exit 1
237
204
  end
238
-
239
205
  autowrite_to_dir_or_gcs(:gcs, mybucket_with_subdir) if opts_autowrite
240
206
  end
241
207
 
@@ -1,10 +1,12 @@
1
1
  # Ric common stuff! :)
2
2
  #
3
- #
4
3
  # Usage:
5
- # include Storazzo::Common
4
+ # include Storazzo::Common (def to def)
5
+ # or
6
+ # extend Storazzo::Common (def to def self.XX)
6
7
  #
7
8
  require_relative 'colors'
9
+ require 'pry'
8
10
 
9
11
  module Storazzo::Common
10
12
 
@@ -12,16 +14,37 @@ module Storazzo::Common
12
14
 
13
15
 
14
16
  def deb(s)
15
- puts "[DEB] #{yellow(s)}" if $DEBUG
17
+ puts "[DEB🐞] #{yellow(s)}" if _debug_true # $DEBUG
18
+ end
19
+ # this has a yield
20
+ def if_deb?()
21
+ if _debug_true # $DEBUG
22
+ deb "== yield START =="
23
+ yield
24
+ deb "== yield END =="
25
+ end
16
26
  end
17
27
  def warn(s)
18
- puts "[WRN] #{azure(s)}"
28
+ puts "[W⚠️RN] #{azure(s)}"
19
29
  end
20
30
  def err(str)
21
- puts "[ERR] #{red(s)}"
31
+ puts "[ERR] #{red(s)}"
22
32
  end
23
33
  def bug(s)
24
34
  puts "[🐛] #{gray s}"
25
35
  end
36
+ def pverbose(is_verbose, str)
37
+ puts "[V📚RB💀S📚] #{gray str}"
38
+ end
39
+ def ppp(complex_object_to_colorize)
40
+ # TODO i need to learn to return without printing..
41
+ Pry::ColorPrinter.pp(complex_object_to_colorize)
42
+ end
43
+
44
+ private
45
+ def _debug_true
46
+ $DEBUG or ENV["DEBUG"] == 'true'
47
+ end
26
48
 
49
+ # puts "[DEBUG ENABLED!]" if _debug_true
27
50
  end
@@ -1,18 +1,21 @@
1
1
  module Storazzo::Media
2
2
  class Storazzo::Media::AbstractRicDisk
3
+ #include Storazzo::Common
4
+ extend Storazzo::Common
3
5
 
4
- #@@default_stats_filename = Storazzo::RicDiskStatsFile.default_name
6
+ #DefaultStatsFilename = Storazzo::RicDiskStatsFile.default_name
5
7
 
6
8
  # looks like there's not Abstract Class in Ruby, but also SO says he best
7
9
  # way to do this is this:
8
10
 
9
11
  # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
10
12
 
13
+
11
14
  ########################
12
15
  # Abstract methods START
13
16
  ########################
14
17
  def initialize(local_mount)
15
- puts "[DEB] [AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
18
+ pverbose true, "[AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
16
19
  validate
17
20
  end
18
21
  def self.list_all
@@ -50,7 +53,7 @@ module Storazzo::Media
50
53
  # if not writeable, I will:
51
54
  # 1. create a dir based on its unique format.
52
55
  # 2. create a file of same look and feel (alternative - used a DASH)
53
- return "{get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
56
+ return "TODO FIXME {get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
54
57
  #"{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
55
58
  end
56
59
  end
@@ -63,6 +66,18 @@ module Storazzo::Media
63
66
  "MD5::v1::#{hash}"
64
67
  end
65
68
 
69
+ def to_verbose_s
70
+ h = {}
71
+ h[:class] = self.class
72
+ h[:unique_id] = self.unique_id
73
+ h[:inspect] = self.inspect
74
+ h[:to_s] = self.to_s
75
+ h[:local_mountpoint] = local_mountpoint
76
+ h[:writeable] = self.writeable?
77
+ h[:stats_file_smart_fullpath] = stats_file_smart_fullpath
78
+ return h
79
+ end
80
+
66
81
  # # Todo check on instances these 3 methods exist
67
82
  def self.abstract_class_mandatory_methods
68
83
  %W{
@@ -92,15 +107,27 @@ module Storazzo::Media
92
107
  "#{local_mountpoint}/#{my_stats_filename}"
93
108
  end
94
109
 
95
- def validate
96
- puts "DEB We're trying to see if your object is valid, across 3 possible sub-classes."
110
+ def validate(opts={})
111
+ verbose = opts.fetch(:verbose, true)
112
+ puts "[VERBOSE] validate(): We're trying to see if your object is valid, across 3 possible sub-classes." if verbose
97
113
  #1. check for
98
114
  raise "Unknown local mount " unless local_mount.is_a?(String)
99
115
  #2. check thaty writeable? is true or false
100
116
  my_writeable = wr
101
117
  raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass )
102
118
  end
119
+
120
+ # TODO use a proper Factory pattern.
121
+ def self.DirFactory(path)
122
+ raise "I need a path/directory string: #{path}" unless path.is_a?(String)
123
+
124
+ deb "TODO: if coincides with MountPoint, instance THAT"
125
+ if path =~ /^gs:\/\//
126
+ deb "Smells like GCS"
127
+ return GcsBucket.new(path)
128
+ end
129
+ deb "Smells like LocalFolder :)"
130
+ return LocalFolder.new(path)
131
+ end
103
132
  end
104
- #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD inside module"
105
133
  end
106
- #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD outside module"
@@ -3,28 +3,26 @@
3
3
 
4
4
  module Storazzo::Media
5
5
  class Storazzo::Media::LocalFolder < Storazzo::Media::AbstractRicDisk
6
+ #extend Storazzo::Common
7
+ include Storazzo::Common
6
8
 
7
9
  attr_accessor :local_mountpoint, :wr
8
10
 
9
11
  def initialize(local_mount)
10
- puts "[Storazzo::Media::LocalFolder] initialize"
12
+ deb "[Storazzo::Media::LocalFolder] initialize"
11
13
 
12
14
  @local_mountpoint = File.expand_path(local_mount)
13
15
  raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
14
16
  @wr = File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
15
17
 
16
18
  #super.initialize(local_mount) rescue "SUPER_ERROR: #{$!}"
17
- super(local_mount) rescue "SUPER_ERROR: #{$!}"
19
+ super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
18
20
  end
19
21
 
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
22
+ def self.list_all(config=nil)
23
+ # get lists from Config singleton
24
+ config ||= Storazzo::RicDiskConfig.instance # # ).get_config
25
+ config.load
28
26
  config.get_local_folders
29
27
  end
30
28
 
@@ -1,4 +1,9 @@
1
1
  # TODO
2
+ module Storazzo::Media
3
+ class Storazzo::Media::MountPoint < Storazzo::Media::AbstractRicDisk
4
+ puts "[REMOVEME] Storazzo::Media::MountPoint being read. REMOVEME when you see this :)"
5
+ end
6
+ end
2
7
 
3
8
  # def writeable?
4
9
  #File.writable?(@local_mountpoint)
@@ -40,10 +40,21 @@ module Storazzo
40
40
  ## INSTANCE methods
41
41
  ################################
42
42
 
43
+ def initialize_old_way(path, opts={})
44
+ raise "Now I dont want a string in input, I want an OBJECT < Storazzo::Media::AbstractRicDisk"
45
+ end
46
+
43
47
 
44
- def initialize(path, opts={})
48
+ def initialize(ric_disk_object, opts={})
49
+ verbose = opts.fetch :verbose, true
50
+ pverbose verbose, "This needs an object of type Storazzo::Media::AbstractRicDisk now (this case: #{ric_disk_object.class})"
51
+ raise "Woopsie, not a Storazzo::Media::AbstractRicDisk! Intead its a #{ric_disk_object.class}" unless ric_disk_object.class.superclass == Storazzo::Media::AbstractRicDisk
52
+ # ok back to business, now path is a String :)
53
+ path = ric_disk_object.path
54
+ deb "RicDisk initialize.. path=#{path}"
45
55
  deb "RicDisk initialize.. path=#{path}"
46
56
  @local_mountpoint = File.expand_path(path)
57
+ @ard = ric_disk_object # AbstractRicDiskObject
47
58
  @description = "This is an automated RicDisk description from v.#{RicdiskVersion}. Created on #{Time.now}'"
48
59
  @ricdisk_version = RicdiskVersion
49
60
  @ricdisk_file = compute_ricdisk_file() # Storazzo::RicDisk.get_ricdisk_file(path)
@@ -53,7 +64,7 @@ module Storazzo
53
64
  #@wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
54
65
  #@wr = writeable?
55
66
  @tags = ['ricdisk', 'storazzo']
56
- @size = `du -s '#{path}'`.split(/\s/)[0] # self.size
67
+ @size = _compute_size_could_take_long(path)
57
68
  @unique_hash = "MD5::" + Digest::MD5.hexdigest(File.expand_path(path)) # hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
58
69
  @computation_hostname = Socket.gethostname
59
70
  @created_at = Time.now
@@ -91,18 +102,31 @@ module Storazzo
91
102
  end
92
103
 
93
104
  def to_s
94
- "RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version})"
105
+ "RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version}, ard=#{@ard})"
95
106
  end
96
107
 
97
108
  # could take long..
98
109
  # def size
99
110
  # `du -s '#{path}'`.split(/\s/)[0]
100
111
  # end
112
+ def self._compute_size_could_take_long(my_path)
113
+ deb "Could take long. TODO(ricc): add some sort of cutoff/timeout to 5 seconds."
114
+ puts azure('could take long')
115
+ `du -s '#{my_path}' 2>/dev/null`.chomp.split(/\s/)[0] # self.size
116
+ end
101
117
 
102
118
  def writeable?()
119
+ #memoize
103
120
  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}")
121
+ # NOW: CALCULATE it
122
+ # Now I can do ONCE an EXPENSIVE calculation
123
+ 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")
124
+ 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}")
125
+ puts("Dir: #{ azure path}")
126
+ puts("absolute_path: #{azure absolute_path}")
127
+ puts("File.writable?(absolute_path): #{azure File.writable?(absolute_path)}")
128
+ bash_output = `if [ -w "#{absolute_path}" ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi`
129
+ puts("bash_output: #{azure bash_output}")
106
130
  #@wr = File.writable?(File.expand_path(@ricdisk_file)) # rescue false
107
131
  raise "for some reason an important info (ricdisk_file='#{absolute_path}') is missing!" if ricdisk_file.nil?
108
132
  @wr = File.writable?(absolute_path) # rescue false
@@ -111,6 +135,16 @@ module Storazzo
111
135
  #false
112
136
  end
113
137
 
138
+ def to_verbose_s
139
+ h = {}
140
+ h[:to_s] = self.to_s
141
+ h[:wr] = self.wr
142
+ h[:inspect] = self.inspect
143
+ h[:writeable] = self.writeable?
144
+ h[:ard] = @ard
145
+ return h
146
+ end
147
+
114
148
  ################################
115
149
  ## CLASS methods
116
150
  ################################
@@ -154,8 +188,8 @@ module Storazzo
154
188
  x = Dir.glob('*').select {|f| File.directory? f}
155
189
  subdirs = x.map{|subdir| "#{dir}#{subdir}"}
156
190
  subdirs.each{|subdir|
157
- puts "DEB Subdir: #{subdir}"
158
- puts `ls -al "#{subdir}"`
191
+ deb "Subdir: #{subdir}"
192
+ puts `ls -al "#{subdir}"` # TODO refactor in exec
159
193
  active_dirs << subdir if ok_dir? # self.ok_dir?(subdir)
160
194
  }
161
195
  #puts(white x)
@@ -239,7 +273,7 @@ module Storazzo
239
273
  # given a path, if .ricdisk exists i do stuff with it..
240
274
  disk_info = nil
241
275
  unless ok_dir? # self.ok_dir?(subdir)
242
- puts("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
276
+ warn("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
243
277
  return
244
278
  end
245
279
  ConfigFiles.each do |papable_configfile_name|
@@ -258,7 +292,7 @@ module Storazzo
258
292
  # puts(yellow disk_info.to_yaml)
259
293
  # end
260
294
  if disk_info.is_a?(RicDisk)
261
- puts yellow("DEB disk_info.class: #{disk_info.class}")
295
+ deb yellow("disk_info.class: #{disk_info.class}")
262
296
  if File.empty?(disk_info.absolute_path) # and (disk_info.wr)
263
297
  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
298
  if disk_info.wr
@@ -1,6 +1,13 @@
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:
@@ -20,18 +27,16 @@ module Storazzo
20
27
  include Storazzo::Common
21
28
  include Storazzo::Colors
22
29
 
23
- #@@default_config_location = "~/.storazzo.yaml"
24
30
  DefaultConfigLocation = File.expand_path "~/.storazzo.yaml"
25
- # @@default_config_locations = [
26
- # "~/.storazzo.yaml" , # HOME
27
- # "./.storazzo.yaml" , # LOCAL DIR
28
- # ]
31
+
29
32
  DefaultConfigLocations = [
30
33
  File.expand_path("~/.storazzo.yaml") , # HOME
31
34
  File.expand_path("./.storazzo.yaml") , # LOCAL DIR
32
35
  ]
33
- #@@default_gem_location_for_tests
34
- DefaultGemLocationForTests = File.expand_path('../../../', __FILE__) + "/etc/storazzo_config.sample.yaml"
36
+
37
+ DefaultGemLocationForTests =
38
+ File.expand_path('../../../', __FILE__) +
39
+ "/etc/storazzo_config.sample.yaml"
35
40
 
36
41
  attr_accessor :config, :config_file, :load_called
37
42
 
@@ -41,23 +46,22 @@ public
41
46
  verbose = opts.fetch :verbose, false
42
47
 
43
48
  if already_loaded? # and not self.config.nil?
44
- puts "[#{self.class}] VERBOSE load: already loaded" if verbose
49
+ pverbose verbose, "[#{self.class}] VERBOSE load: already loaded"
45
50
  return self.config
46
51
  end
47
-
48
- puts "[VERBOSE] Storazzo::RicDiskConfig.load(): BEGIN " if verbose
52
+ pverbose verbose, "Storazzo::RicDiskConfig.load(): BEGIN"
49
53
  # trying default location
50
54
  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)
55
+ possible_locations = DefaultConfigLocations # [ default_config_locations .. , "./.storazzo.yaml"]
56
+ deb "[Config.load] Possible Locations: #{possible_locations}"
57
+ if config_path.is_a?(String)
54
58
  #possible_locations = [config_path] + possible_locations # .append()
55
59
  possible_locations = possible_locations.unshift(config_path) # append to front
56
60
  #OR: possible_locations.instert(0, config_path)
57
- puts "[LOAD] possible_locations: #{possible_locations}" if verbose
61
+ pverbose verbose, "[LOAD] possible_locations: #{possible_locations}"
58
62
  end
59
63
  puts "[VERBOSE] Searching these paths in order: #{possible_locations}" if verbose
60
- bug "This is not always an array of sTRINGS."
64
+ #bug "This is not always an array of sTRINGS."
61
65
  raise "possible_locations is not an array" unless possible_locations.is_a?(Array)
62
66
  possible_locations.each do |possible_path|
63
67
  # ASSERT is a string
@@ -90,9 +94,7 @@ public
90
94
 
91
95
  # Obsolete, call another class instead.
92
96
  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
97
  raise "DEPRECATED! USE SampleRicDiskConfig.load() instead!"
95
- # load(DefaultGemLocationForTests, :verbose => true )
96
98
  end
97
99
 
98
100
  def config_ver
@@ -162,7 +164,9 @@ public
162
164
 
163
165
  # UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
164
166
  def iterate_through_file_list_for_disks(files_list=[], opts={})
165
- verbose = opts.fetch :verbose, true
167
+ verbose = opts.fetch :verbose, false
168
+ raise "[iterate_through_file_list_for_disks] Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array)
169
+
166
170
  # I decided i wont accept an emopty list, this is not how you use the gem, you lazy XXX!
167
171
  # if files_list == [] # or files_list.nil? # empty -> ALL
168
172
  # deb "iterate_through_file_list_for_disks(): no args provided"
@@ -173,7 +177,6 @@ public
173
177
  # RicDisk.calculate_stats_files(dir) # dir is inutile
174
178
  # } # TODO refactor in option sbrodola_afterwards=true. :)
175
179
  # else
176
- raise "Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array)
177
180
  puts "iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)" if verbose
178
181
 
179
182
  #dirs = RicDisk.find_active_dirs()
@@ -182,8 +185,8 @@ public
182
185
  if File.directory?(dir)
183
186
  #if dirs.include?(dir)
184
187
  puts "iterate_through_file_list_for_disks() Legit dir: #{green dir}" if verbose
185
- rd = RicDisk.new(dir)
186
- puts "RicDisk: #{rd}"
188
+ rd = RicDisk.new(Storazzo::Media::AbstractRicDisk.DirFactory(dir))
189
+ pverbose true, "RicDisk from Factory (woohoo): #{rd}"
187
190
  rd.write_config_yaml_to_disk(dir)
188
191
  #RicDisk.write_config_yaml_to_disk(dir)
189
192
  #RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files
@@ -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
 
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
@@ -13,9 +13,8 @@ Gem::Specification.new do |s|
13
13
  "ricdisk-magic",
14
14
  "stats-with-md5",
15
15
  ]
16
-
17
16
  s.homepage = "https://rubygems.org/gems/storazzo" # maybe https://github.com/palladius/storazzo
18
17
  s.license = "MIT"
19
-
20
18
  #s.add_dependency "activesupport", "~> 3.0"
19
+ s.add_dependency "pry" # , "~> 3.0"
21
20
  end
@@ -0,0 +1,3 @@
1
+ # TODO
2
+ require "minitest/autorun"
3
+ require "storazzo"
@@ -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
@@ -1,18 +1,16 @@
1
1
  require "minitest/autorun"
2
2
  require "storazzo"
3
+ require 'storazzo/common'
3
4
  require "storazzo/ric_disk"
4
5
  require "storazzo/ric_disk_config"
5
6
  require 'storazzo/colors'
6
7
  require "storazzo/media/local_folder"
7
8
 
8
- #require "storazzo/ric_disk/gcs_bucket"
9
- #require "storazzo/media/local_folder"
10
-
11
-
12
- #puts yellow("DISABLING FOR NOW TODO restore")
13
-
14
9
  class LocalFolderTest < Minitest::Test
15
- include Storazzo::Colors
10
+ # include Storazzo::Colors
11
+ # include Storazzo::Common
12
+ include Storazzo::Common
13
+
16
14
  # def test_fail_on_purpOSE # test_storazzo_hi_with_argument
17
15
  # assert_match 42, 42 , "change me when it failes from makefile"
18
16
  # #"Hello from Storazzo", Storazzo::Main.hi("ruby this should fail")
@@ -65,7 +63,7 @@ class LocalFolderTest < Minitest::Test
65
63
  stats_file = disk.stats_filename_default_fullpath
66
64
  puts "stats_file: #{stats_file}"
67
65
  disk.parse()
68
- puts "[DEB] config: ''#{config}''"
66
+ deb "config: ''#{config}''"
69
67
  # config.iterate_through_file_list_for_disks([test_dir])
70
68
  # assert(
71
69
  # File.exists?(stats_file),
@@ -105,7 +103,7 @@ class LocalFolderTest < Minitest::Test
105
103
  )
106
104
  end
107
105
 
108
- def test_readonly_folder
106
+ def TODO_test_readonly_directory_creates_configfile_outside_of_dir
109
107
  test_dir = "/etc/"
110
108
  disk = Storazzo::Media::LocalFolder.new(test_dir)
111
109
  stats_file = disk.stats_filename_default_fullpath
@@ -118,4 +116,40 @@ class LocalFolderTest < Minitest::Test
118
116
  )
119
117
  # ...
120
118
  end
119
+
120
+ def test_readonly_directory_is_indeed_readonly
121
+ test_dir = "/etc/"
122
+ readonly_rdisk = Storazzo::Media::LocalFolder.new(test_dir)
123
+ # stats_file = disk.stats_filename_default_fullpath
124
+ # config = Storazzo::RicDiskSampleConfig.instance()
125
+ # config.load
126
+ # config.iterate_through_file_list_for_disks([test_dir])
127
+ # assert(
128
+ # not(File.exists?(stats_file)),
129
+ # "parse on LocalFolder should NOT create file '#{stats_file}' but another in another TODO place"
130
+ # )
131
+ #readonly_rdisk = Storazzo::RicDisk.new(test_dir)
132
+ ppp(readonly_rdisk.to_verbose_s)
133
+ assert_equal(
134
+ readonly_rdisk.wr,
135
+ false,
136
+ "Folder #{test_dir} is NOT writeble to the author's knowledge."
137
+ )
138
+ # ...
139
+ end
140
+
141
+
142
+ def test_writeable_directory_is_indeed_writeable
143
+ test_dir = '/tmp/'
144
+ writeable_rdisk = Storazzo::Media::LocalFolder.new(test_dir)
145
+ #writeable_rdisk = Storazzo::RicDisk.new(test_dir)
146
+ assert_equal(
147
+ writeable_rdisk.wr,
148
+ true,
149
+ "Folder #{test_dir} is INDEED writeble to the author's knowledge, although triggers lot of noise."
150
+ )
151
+
152
+ end
153
+
154
+
121
155
  end
@@ -0,0 +1,26 @@
1
+ require "minitest/autorun"
2
+ require "storazzo"
3
+
4
+ #require 'pry' # must install the gem... but you ALWAYS want pry installed anyways
5
+
6
+ class MediaMountPointTest < Minitest::Test
7
+
8
+ def test_test_in_subfolder
9
+ #raise "Does this even work?!?"
10
+ puts "Looks like this only works if you run this: ruby -I test test/media/test_media_mount_point.rb"
11
+ end
12
+
13
+ def test_mount_point_creation
14
+ #x = Storazzo::Media::MountPoint.new
15
+ #assert class inherits from ...
16
+ skip "TODO Code is still missing but TODO implement that this class inherits from **ther class"
17
+ # assert(
18
+ # false,
19
+ # "TODO Code is still missing but TODO implement that this class inherits from **ther class"
20
+ # )
21
+ end
22
+
23
+ def test_what_skip_means
24
+ skip 'Check for affiliate link, credit card details, pledge history. Foujnd example online. Please Riccardo fix'
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require "minitest/autorun"
2
+ require "storazzo"
3
+
4
+ class RicDiskTest < Minitest::Test
5
+
6
+ def test_factory_works_for_gcs
7
+ rd1 = RicDisk.new('/tmp')
8
+ hash = rd1.to_verbose_s()
9
+ pp hash
10
+ assert_equal(
11
+ hash.class,
12
+ Hash,
13
+ "rd1.to_verbose_s should return a Hash"
14
+ )
15
+ end
16
+
17
+
18
+
19
+ end
@@ -7,13 +7,6 @@
7
7
 
8
8
  require "minitest/autorun"
9
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
10
 
18
11
 
19
12
  class RicDiskConfigTest < Minitest::Test
@@ -24,7 +17,7 @@ class RicDiskConfigTest < Minitest::Test
24
17
  config_obj = Storazzo::RicDiskSampleConfig.instance()
25
18
  puts "config_obj.class: #{config_obj.class}"
26
19
  config = config_obj.load # _sample_version
27
- puts "Config: #{config}"
20
+ pverbose true, "[test_load_sample_version] Config: #{pp config}"
28
21
  #puts '[RicDiskConfigTest] TODO lets make sure the gem being imported is actually in /etc/storazz-config.smaple blah blah'
29
22
  #puts "[RicDiskConfigTest] config_file: ", config_obj.config_file
30
23
  assert_equal(
@@ -0,0 +1,15 @@
1
+ # On Linux:
2
+ <File::Stat
3
+ dev=0xfe01,
4
+ ino=6293055,
5
+ mode=0100644 (file rw-r--r--),
6
+ nlink=1,
7
+ uid=164825 (ricc),
8
+ gid=89939 (primarygroup),
9
+ rdev=0x0 (0, 0),
10
+ size=7,
11
+ blksize=4096,
12
+ blocks=8,
13
+ atime=2022-06-27 08:49:38.586706861 +0200 (1656312578),
14
+ mtime=2022-03-23 14:28:45 +0100 (1648042125),
15
+ ctime=2022-05-30 10:12:10.381629305 +0200 (1653898330)>
@@ -0,0 +1,15 @@
1
+ # On Mac:
2
+ <File::Stat
3
+ dev=0x100000f,
4
+ ino=1247768,
5
+ mode=0100644 (file rw-r--r--),
6
+ nlink=1,
7
+ uid=164825 (ricc),
8
+ gid=89939 (primarygroup),
9
+ rdev=0x0 (0, 0),
10
+ size=564,
11
+ blksize=4096,
12
+ blocks=8,
13
+ atime=2022-03-05 22:36:48.373362127 +0100 (1646516208),
14
+ mtime=2022-03-05 22:36:48.176789949 +0100 (1646516208),
15
+ ctime=2022-03-05 22:36:48.176789949 +0100 (1646516208)>
@@ -0,0 +1,13 @@
1
+ # I fell in love with this: https://stackoverflow.com/questions/9274205/rake-watch-for-changes
2
+
3
+ file 'main.o' => ["main.c", "greet.h"] do
4
+ sh "cc -c -o main.o main.c"
5
+ end
6
+
7
+ file 'greet.o' => ['greet.c'] do
8
+ sh "cc -c -o greet.o greet.c"
9
+ end
10
+
11
+ file "hello" => ["main.o", "greet.o"] do
12
+ sh "cc -o hello main.o greet.o"
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riccardo Carlesso
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-07-29 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A simple gem to manage your external hard drives and extract MD5 and
14
28
  common stuff from them.
15
29
  email: name dot surname at popular Google-owned Mail
@@ -46,12 +60,18 @@ files:
46
60
  - lib/storazzo/ric_disk_ugly.rb
47
61
  - lib/storazzo/version.rb
48
62
  - storazzo.gemspec
49
- - test/test_gcs_bucket.rb
50
- - test/test_local_folder.rb
63
+ - test/media/test_abstract_ric_disk.rb
64
+ - test/media/test_gcs_bucket.rb
65
+ - test/media/test_local_folder.rb
66
+ - test/media/test_mount_point.rb
67
+ - test/test_ric_disk.rb
51
68
  - test/test_ric_disk_config.rb
52
69
  - test/test_ric_disk_stats_file.rb
53
70
  - test/test_storazzo.rb
71
+ - var/dumps/file_stat.linux.yaml
72
+ - var/dumps/file_stat.macosx.yaml
54
73
  - var/test/README.md
74
+ - var/test/disks/disk02-full/Rakefile
55
75
  - var/test/disks/disk02-full/fake file.touch
56
76
  - var/test/disks/disk02-full/ls.txt
57
77
  homepage: https://rubygems.org/gems/storazzo
@@ -80,9 +100,13 @@ summary: storazzo is an amazing gem. Code is in https://github.com/palladius/sto
80
100
  test_files:
81
101
  - test/test_storazzo.rb
82
102
  - test/test_ric_disk_stats_file.rb
103
+ - test/test_ric_disk.rb
83
104
  - test/test_ric_disk_config.rb
84
- - test/test_gcs_bucket.rb
85
- - test/test_local_folder.rb
105
+ - test/media/test_gcs_bucket.rb
106
+ - test/media/test_mount_point.rb
107
+ - test/media/test_abstract_ric_disk.rb
108
+ - test/media/test_local_folder.rb
86
109
  - var/test/README.md
87
110
  - var/test/disks/disk02-full/fake file.touch
88
111
  - var/test/disks/disk02-full/ls.txt
112
+ - var/test/disks/disk02-full/Rakefile