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 +4 -4
- data/Gemfile +1 -0
- data/Makefile +10 -2
- data/VERSION +1 -1
- data/bin/ricdisk-magic +39 -12
- data/lib/storazzo/colors.rb +6 -1
- data/lib/storazzo/common.rb +19 -4
- data/lib/storazzo/hashify.rb +29 -16
- data/lib/storazzo/main.rb +3 -3
- data/lib/storazzo/media/README.md +14 -0
- data/lib/storazzo/media/abstract_ric_disk.rb +106 -0
- data/lib/storazzo/media/gcs_bucket.rb +20 -0
- data/lib/storazzo/media/local_folder.rb +51 -0
- data/lib/storazzo/media/mount_point.rb +5 -0
- data/lib/storazzo/ric_disk.rb +110 -50
- data/lib/storazzo/ric_disk_config.rb +143 -38
- data/lib/storazzo/ric_disk_sample_config.rb +35 -0
- data/lib/storazzo/ric_disk_statsfile.rb +15 -2
- data/lib/storazzo/ric_disk_ugly.rb +1 -1
- data/lib/storazzo/version.rb +6 -0
- data/lib/storazzo.rb +14 -5
- data/test/test_gcs_bucket.rb +59 -0
- data/test/test_local_folder.rb +69 -0
- data/test/test_ric_disk_config.rb +38 -0
- data/test/test_ric_disk_stats_file.rb +36 -0
- data/test/test_storazzo.rb +29 -29
- metadata +16 -3
- data/lib/storazzo/translator.rb +0 -17
data/lib/storazzo/ric_disk.rb
CHANGED
@@ -1,27 +1,34 @@
|
|
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
|
12
|
+
require 'socket'
|
9
13
|
|
10
14
|
|
11
15
|
## Instance variables
|
12
16
|
|
13
17
|
# in order of finding, so the first will be the one we actually READ and use. I could looknat the date but cmon...
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
# These are the files I do accept.
|
19
|
+
ConfigFiles = %W{ ricdisk.yaml .ricdisk }
|
20
|
+
RicdiskVersion = '2.0'
|
21
|
+
DefaultGemfileTestDiskFolder = Storazzo.root + "/var/test/disks/" # was: @@default_gemfile_test_disks_folder
|
17
22
|
# Immutable
|
18
|
-
|
23
|
+
DefaultMediaFolders = %w{
|
19
24
|
/Volumes/
|
20
25
|
/mnt/
|
21
|
-
}.append(
|
26
|
+
}.append(DefaultGemfileTestDiskFolder ).append("/media/#{ENV["USER"]}/" )
|
22
27
|
|
23
28
|
# # todo substitute with protobuf..
|
24
|
-
attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path,
|
29
|
+
attr_accessor :name, :description, :ricdisk_file,:ricdisk_file_full, :local_mountpoint, :wr, :path,
|
30
|
+
:ricdisk_file_empty, :size, :active_dirs, :ricdisk_version,
|
31
|
+
:unique_hash # new 202207
|
25
32
|
|
26
33
|
|
27
34
|
################################
|
@@ -30,36 +37,44 @@ module Storazzo
|
|
30
37
|
|
31
38
|
|
32
39
|
def initialize(path, opts={})
|
33
|
-
|
34
|
-
@local_mountpoint = path
|
35
|
-
@
|
36
|
-
@
|
37
|
-
|
38
|
-
@ricdisk_file = RicDisk.get_ricdisk_file(path)
|
39
|
-
@
|
40
|
+
deb "RicDisk initialize.. path=#{path}"
|
41
|
+
# @local_mountpoint = path
|
42
|
+
@local_mountpoint = File.expand_path(path)
|
43
|
+
@description = "This is an automated RicDisk description from v.#{RicdiskVersion}. Created on #{Time.now}'"
|
44
|
+
@ricdisk_version = RicdiskVersion
|
45
|
+
@ricdisk_file = compute_ricdisk_file() # Storazzo::RicDisk.get_ricdisk_file(path)
|
46
|
+
@ricdisk_file_full = "#{@local_mountpoint}/#{@ricdisk_file}"
|
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
|
-
|
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
|
55
|
+
|
56
|
+
@ricdisk_file_empty = ricdisk_file_empty?
|
57
|
+
|
46
58
|
# @config = RicDiskConfig.instance.get_config
|
47
59
|
# #puts @config if @config
|
48
60
|
# find_info_from_mount(path)
|
61
|
+
deb "RicDisk initialize. to_s: #{self}"
|
49
62
|
# find_info_from_df()
|
50
63
|
end
|
51
64
|
|
52
65
|
def ricdisk_file_empty?()
|
53
|
-
File.empty?(
|
66
|
+
# File.empty?("#{local_mountpoint}/.ricdisk.yaml")
|
67
|
+
puts "compute_ricdisk_file: #{compute_ricdisk_file}"
|
68
|
+
File.empty?(compute_ricdisk_file.to_s) # was (get_ricdisk_file)
|
54
69
|
end
|
55
70
|
|
56
71
|
def ok_dir?
|
57
|
-
not
|
72
|
+
not ricdisk_file.nil?
|
58
73
|
end
|
59
74
|
|
60
75
|
|
61
76
|
def analyze_local_system()
|
62
|
-
puts
|
77
|
+
puts "TODO This should analyzze the WHOLE system. TODO(ricc): move to another object which has to do with the system/computer."
|
63
78
|
puts "1. Interesting Mounts: #{green interesting_mount_points}"
|
64
79
|
puts "2. Sbrodoling everything: :TODO"
|
65
80
|
# find_info_from_mount(path)
|
@@ -71,7 +86,7 @@ module Storazzo
|
|
71
86
|
end
|
72
87
|
|
73
88
|
def to_s
|
74
|
-
"RicDisk(paz=#{path},
|
89
|
+
"RicDisk(paz=#{path}, r/w=#{writeable?}, size=#{size}B, f=#{ricdisk_file}, v#{ricdisk_version})"
|
75
90
|
end
|
76
91
|
|
77
92
|
# could take long..
|
@@ -80,7 +95,13 @@ module Storazzo
|
|
80
95
|
# end
|
81
96
|
|
82
97
|
def writeable?()
|
83
|
-
|
98
|
+
return @wr unless @wr.nil?
|
99
|
+
# Otherwise I can do an EXPENSIVE calculation
|
100
|
+
puts "TODO(ricc): Do expensive calculation if this FS is writeable: #{path}"
|
101
|
+
@wr = File.writable?(File.expand_path(@ricdisk_file)) # rescue false
|
102
|
+
return @wr
|
103
|
+
#:boh_todo_fix_me_and_compute
|
104
|
+
#false
|
84
105
|
end
|
85
106
|
|
86
107
|
################################
|
@@ -90,19 +111,20 @@ module Storazzo
|
|
90
111
|
|
91
112
|
# All places where to find for something :)
|
92
113
|
def self.default_media_folders
|
93
|
-
DEFAULT_MEDIA_FOLDERS
|
114
|
+
DefaultMediaFolders # was DEFAULT_MEDIA_FOLDERS
|
94
115
|
end
|
95
116
|
|
96
117
|
|
97
118
|
def self.test # _localgem_disks
|
98
|
-
d = RicDisk.new(
|
119
|
+
d = RicDisk.new( DefaultGemfileTestDiskFolder)
|
99
120
|
puts (d)
|
100
121
|
puts "do something with it: #{d}"
|
101
122
|
#d.find_active_dirs()
|
102
123
|
end
|
103
124
|
|
104
|
-
|
105
|
-
|
125
|
+
def absolute_path
|
126
|
+
@local_mountpoint + "/" + @ricdisk_file
|
127
|
+
end
|
106
128
|
|
107
129
|
|
108
130
|
def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
|
@@ -121,11 +143,12 @@ module Storazzo
|
|
121
143
|
deb "Dir doesnt exist, skipping: #{dir}"
|
122
144
|
next
|
123
145
|
end
|
124
|
-
Dir.chdir(dir)
|
146
|
+
Dir.chdir(dir)
|
125
147
|
x = Dir.glob('*').select {|f| File.directory? f}
|
126
148
|
subdirs = x.map{|subdir| "#{dir}#{subdir}"}
|
127
149
|
subdirs.each{|subdir|
|
128
|
-
|
150
|
+
puts "DEB Subdir: #{subdir}"
|
151
|
+
puts `ls -al "#{subdir}"`
|
129
152
|
active_dirs << subdir if ok_dir? # self.ok_dir?(subdir)
|
130
153
|
}
|
131
154
|
#puts(white x)
|
@@ -138,15 +161,36 @@ module Storazzo
|
|
138
161
|
end
|
139
162
|
end
|
140
163
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
164
|
+
def compute_ricdisk_file()
|
165
|
+
unless @ricdisk_file.nil?
|
166
|
+
deb "[CACHE HIT] ricdisk_file (didnt have to recompute it - yay!)"
|
167
|
+
return @ricdisk_file
|
168
|
+
end
|
169
|
+
warn "RICC_WARNING This requires cmputation I wanna do it almost once"
|
170
|
+
ConfigFiles.each do |papable_config_filename|
|
171
|
+
#return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
|
172
|
+
#return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
|
173
|
+
return papable_config_filename if File.exist?("#{path}/#{papable_config_filename}") # and File.empty?( "#{path}/.ricdisk")
|
174
|
+
end
|
147
175
|
return nil
|
148
176
|
end
|
149
177
|
|
178
|
+
|
179
|
+
# # new
|
180
|
+
# def self.get_ricdisk_file_obsolete(path)
|
181
|
+
# if @ricdisk_file
|
182
|
+
# puts "[CACHE HIT] ricdisk_file"
|
183
|
+
# return @ricdisk_file
|
184
|
+
# end
|
185
|
+
# puts "RICC_WARNING This requires cmputation I wanna do it almost once"
|
186
|
+
# ConfigFiles.each do |papable_config_filename|
|
187
|
+
# #return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
|
188
|
+
# #return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
|
189
|
+
# return papable_config_filename if File.exist?("#{path}/#{papable_config_filename}") # and File.empty?( "#{path}/.ricdisk")
|
190
|
+
# end
|
191
|
+
# return nil
|
192
|
+
# end
|
193
|
+
|
150
194
|
|
151
195
|
def self.interesting_mount_points(opts={})
|
152
196
|
#https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
|
@@ -166,35 +210,51 @@ module Storazzo
|
|
166
210
|
|
167
211
|
|
168
212
|
# FORMER SBRODOLA, now write_config_yaml_to_disk
|
169
|
-
def self.write_config_yaml_to_disk(subdir) # sbrodola_ricdisk(subdir)
|
213
|
+
#def self.write_config_yaml_to_disk(subdir, opts={}) # sbrodola_ricdisk(subdir)
|
214
|
+
def write_config_yaml_to_disk(subdir, opts={}) # sbrodola_ricdisk(subdir)
|
170
215
|
# given a path, if .ricdisk exists i do stuff with it..
|
171
216
|
disk_info = nil
|
172
|
-
unless self.ok_dir?(subdir)
|
173
|
-
puts("Nothing for me here: '#{subdir}'. Existing")
|
217
|
+
unless ok_dir? # self.ok_dir?(subdir)
|
218
|
+
puts("[write_config_yaml_to_disk] Nothing for me here: '#{subdir}'. Existing")
|
174
219
|
return
|
175
220
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
deb("Interesting2. Empty file! TODO write YAML with it.")
|
182
|
-
disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
|
183
|
-
puts(yellow disk_info.to_yaml)
|
221
|
+
ConfigFiles.each do |papable_configfile_name|
|
222
|
+
if File.exists?( "#{subdir}/#{papable_configfile_name}") and File.empty?( "#{subdir}/#{papable_configfile_name}")
|
223
|
+
deb("Interesting. Empty file '#{papable_configfile_name}'! Now I write YAML with it.")
|
224
|
+
disk_info = RicDisk.new(subdir, papable_configfile_name)
|
225
|
+
end
|
184
226
|
end
|
185
|
-
if
|
186
|
-
|
187
|
-
|
188
|
-
|
227
|
+
# if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
|
228
|
+
# deb("Interesting1. Empty file! Now I write YAML with it.")
|
229
|
+
# disk_info = RicDisk.new(subdir, '.ricdisk')
|
230
|
+
# end
|
231
|
+
# if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
|
232
|
+
# deb("Interesting2. Empty file! TODO write YAML with it.")
|
233
|
+
# disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
|
234
|
+
# puts(yellow disk_info.to_yaml)
|
235
|
+
# end
|
236
|
+
if disk_info.is_a?(RicDisk)
|
237
|
+
deb("disk_info.class: #{disk_info.class}")
|
238
|
+
if File.empty?(disk_info.absolute_path) and (disk_info.wr)
|
239
|
+
puts(green("yay, we can now write the file '#{disk_info.absolute_path}' (which is R/W, I just checked!) with proper YAML content.."))
|
240
|
+
ret = File.write(disk_info.absolute_path, disk_info.to_yaml)
|
189
241
|
puts("Written file! ret=#{ret}")
|
190
242
|
else
|
191
|
-
puts(red("
|
192
|
-
puts("File size: #{File.size(disk_info.
|
243
|
+
puts(red("Something not right here: either file is NOT empty or disk is NOT writeable.. #{File.empty?(disk_info.absolute_path)}"))
|
244
|
+
puts("File size: #{File.size(disk_info.absolute_path)}")
|
245
|
+
puts(disk_info.to_s)
|
246
|
+
puts(disk_info.obj_to_hash)
|
247
|
+
puts(disk_info.obj_to_yaml)
|
193
248
|
end
|
249
|
+
else
|
250
|
+
puts "[write_config_yaml_to_disk] No DiskInfo found across #{ConfigFiles}. I leave this function empty-handed."
|
194
251
|
end
|
195
252
|
if File.exists?( "#{subdir}/.ricdisk") and ! File.empty?( "#{subdir}/.ricdisk")
|
196
|
-
puts("Config File found with old-style name: '#{subdir}/.ricdisk' !")
|
197
|
-
|
253
|
+
puts("Config File found with old-style name: '#{subdir}/.ricdisk' ! Please move it to .ricdisk.yaml!")
|
254
|
+
puts(white `cat "#{subdir}/.ricdisk"`)
|
255
|
+
else
|
256
|
+
puts "WRITING NOW. disk_info.obj_to_yaml .. to #{compute_ricdisk_file}"
|
257
|
+
File.open(ricdisk_file_full, 'w').write(disk_info.obj_to_yaml)
|
198
258
|
end
|
199
259
|
end
|
200
260
|
|
@@ -1,58 +1,119 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
+
=begin
|
5
|
+
This is a singleton class. You call me this way..
|
6
|
+
You call me with:
|
7
|
+
|
8
|
+
Storazzo::RicDiskConfig.instance()
|
9
|
+
|
10
|
+
Note that being a Singleton, in Unit Tests it's hard to use the /etc/storazzo_config.sample.yaml instead
|
11
|
+
of the real one - yiikes. How do I fix it? Do I unsingleton it? :) Or do I create TWO singletons? :)
|
12
|
+
=end
|
13
|
+
|
4
14
|
module Storazzo
|
5
|
-
class Storazzo::
|
15
|
+
# class Storazzo::Blah
|
16
|
+
# end
|
17
|
+
|
18
|
+
class Storazzo::RicDiskConfig
|
6
19
|
include Singleton
|
7
20
|
include Storazzo::Common
|
8
21
|
include Storazzo::Colors
|
9
22
|
|
10
|
-
|
11
|
-
|
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
|
32
|
+
]
|
33
|
+
#@@default_gem_location_for_tests
|
34
|
+
DefaultGemLocationForTests = File.expand_path('../../../', __FILE__) + "/etc/storazzo_config.sample.yaml"
|
35
|
+
|
36
|
+
attr_accessor :config, :config_file, :load_called
|
12
37
|
|
13
38
|
public
|
39
|
+
# Load from the first valid config.
|
14
40
|
def load(config_path=nil, opts={})
|
15
41
|
verbose = opts.fetch :verbose, false
|
16
42
|
|
43
|
+
if already_loaded? # and not self.config.nil?
|
44
|
+
puts "[#{self.class}] load: already loaded"
|
45
|
+
return self.config
|
46
|
+
end
|
47
|
+
|
17
48
|
puts "[VERBOSE] Storazzo::RicDiskConfig.load(): BEGIN " if verbose
|
18
49
|
# trying default location
|
19
|
-
|
20
|
-
|
21
|
-
|
50
|
+
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)
|
54
|
+
#possible_locations = [config_path] + possible_locations # .append()
|
55
|
+
possible_locations = possible_locations.unshift(config_path) # append to front
|
56
|
+
#OR: possible_locations.instert(0, config_path)
|
57
|
+
puts "[LOAD] possible_locations: #{possible_locations}" if verbose
|
22
58
|
end
|
23
59
|
puts "[VERBOSE] Searching these paths in order: #{possible_locations}" if verbose
|
60
|
+
bug "This is not always an array of sTRINGS."
|
61
|
+
raise "possible_locations is not an array" unless possible_locations.is_a?(Array)
|
24
62
|
possible_locations.each do |possible_path|
|
25
|
-
|
26
|
-
|
27
|
-
|
63
|
+
# ASSERT is a string
|
64
|
+
raise "possible_path is not a string" unless possible_path.is_a?(String)
|
65
|
+
deb "before buggy expand_path paz: '#{possible_path}''"
|
66
|
+
paz = File.expand_path(possible_path) rescue possible_path
|
67
|
+
raise "Not a string: #{paz}" unless paz.is_a?(String)
|
68
|
+
if File.exists?(paz)
|
28
69
|
@config_file = paz
|
29
70
|
@config = YAML.load(File.read paz) # YAML.load(File.read("file_path"))
|
71
|
+
|
72
|
+
unless (@config["kind"] == 'StorazzoConfig' rescue false)
|
73
|
+
puts white "RicDiskConfig.load(): Sorry this is wrong Config File. Kind=#{@config["kind"] rescue $!}"
|
74
|
+
next
|
75
|
+
end
|
76
|
+
#
|
30
77
|
#pp @config if verbose
|
31
|
-
|
78
|
+
config_ver = @config["apiVersion"]
|
32
79
|
#puts @config[:ConfigVersion]
|
33
|
-
|
34
|
-
puts "RicDiskConfig.to_s: #{self}" if verbose
|
80
|
+
deb("OK. Storazzo::RicDiskConfig v'#{config_ver}' parsed correctly")
|
81
|
+
#puts "[VERBOSE] RicDiskConfig.to_s: #{self}" if verbose
|
82
|
+
@load_called = true
|
35
83
|
return self.config
|
36
84
|
end
|
37
85
|
end
|
86
|
+
@load_called = true
|
38
87
|
# only get here if nothing is found
|
39
88
|
raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}"
|
40
|
-
|
41
|
-
|
89
|
+
end
|
90
|
+
|
91
|
+
# Obsolete, call another class instead.
|
92
|
+
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
|
+
raise "DEPRECATED! USE SampleRicDiskConfig.load() instead!"
|
95
|
+
# load(DefaultGemLocationForTests, :verbose => true )
|
42
96
|
end
|
43
97
|
|
44
98
|
def config_ver
|
45
|
-
|
46
|
-
@config['
|
99
|
+
raise "I cant compute Version since I cant compute @config. Are you sure you didnt instance this Singleton without calling load?" if @config.nil?
|
100
|
+
@config['apiVersion'] # rescue :StillUnknown
|
101
|
+
#config['ConfigVersion']
|
47
102
|
end
|
48
103
|
def config_default_folder
|
49
104
|
#self.
|
50
105
|
@config['Config']['DefaultFolder'] #rescue "Unknown config_default_folder: #{$!}"
|
51
106
|
end
|
107
|
+
def already_loaded?
|
108
|
+
#return
|
109
|
+
load_called == true
|
110
|
+
end
|
52
111
|
|
53
112
|
def to_s
|
54
|
-
size =
|
55
|
-
|
113
|
+
size = File.size(@config_file) rescue -1
|
114
|
+
#puts yellow "DEB: #{@config["apiVersion"]}"
|
115
|
+
#"RicDiskConfig(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
|
116
|
+
"POLY_#{self.class}_(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
|
56
117
|
end
|
57
118
|
|
58
119
|
def get_config(opts={})
|
@@ -64,31 +125,75 @@ public
|
|
64
125
|
Storazzo.root + "/etc/storazzo_config.sample.yaml"
|
65
126
|
end
|
66
127
|
|
128
|
+
|
129
|
+
# returns all folders from file which are Directories
|
130
|
+
# This method is FLAKY! Sometimes gives error.
|
131
|
+
# LocalFolderTest#test_show_all_shouldnt_fail_and_should_return_a_non_empty_array:
|
132
|
+
# TypeError: no implicit conversion of Hash into String
|
133
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `expand_path'
|
134
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `block in load'
|
135
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `each'
|
136
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `load'
|
137
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:83:in `get_config'
|
138
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:95:in `get_local_folders'
|
139
|
+
def get_local_folders
|
140
|
+
config = get_config
|
141
|
+
#puts config['Config']['AdditionalMountDirs']
|
142
|
+
config['Config']['AdditionalMountDirs'].map{|folder|
|
143
|
+
File.expand_path(folder) rescue folder # TypeError: no implicit conversion of Hash into String
|
144
|
+
}.filter{|f| File.directory?(f)}
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_bucket_paths
|
148
|
+
get_config['Config']['Backends']['GoogleCloudStorage']['BucketPaths'].map{|complex_gcs_struct| complex_gcs_struct['path']}
|
149
|
+
end
|
150
|
+
|
67
151
|
# UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
|
68
|
-
def iterate_through_file_list_for_disks(files_list=[])
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
152
|
+
def iterate_through_file_list_for_disks(files_list=[], opts={})
|
153
|
+
verbose = opts.fetch :verbose, true
|
154
|
+
# I decided i wont accept an emopty list, this is not how you use the gem, you lazy XXX!
|
155
|
+
# if files_list == [] # or files_list.nil? # empty -> ALL
|
156
|
+
# deb "iterate_through_file_list_for_disks(): no args provided"
|
157
|
+
# dirs = RicDisk.find_active_dirs()
|
158
|
+
# puts "DEB find_active_dirs: #{green dirs}"
|
159
|
+
# dirs.each {|dir|
|
160
|
+
# RicDisk.write_config_yaml_to_disk(dir)
|
161
|
+
# RicDisk.calculate_stats_files(dir) # dir is inutile
|
162
|
+
# } # TODO refactor in option sbrodola_afterwards=true. :)
|
163
|
+
# else
|
164
|
+
raise "Wrong input: #{files_list} " unless files_list.is_a?(Array)
|
165
|
+
|
166
|
+
puts "iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)" if verbose
|
167
|
+
|
168
|
+
#dirs = RicDisk.find_active_dirs()
|
80
169
|
files_list.each do |dir|
|
81
170
|
dir = File.expand_path(dir)
|
82
|
-
if
|
83
|
-
|
84
|
-
|
85
|
-
RicDisk.
|
171
|
+
if File.directory?(dir)
|
172
|
+
#if dirs.include?(dir)
|
173
|
+
puts "iterate_through_file_list_for_disks() Legit dir: #{green dir}" if verbose
|
174
|
+
rd = RicDisk.new(dir)
|
175
|
+
rd.write_config_yaml_to_disk(dir)
|
176
|
+
#RicDisk.write_config_yaml_to_disk(dir)
|
177
|
+
#RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files
|
178
|
+
compute_stats_files(dir) # dir is inutile # TODO
|
86
179
|
else
|
87
|
-
deb "
|
180
|
+
deb red("Doesnt seem a legit dir to me: #{dir}")
|
181
|
+
# deb "Figghiu ri buttana: doesnt exist #{red dir}"
|
88
182
|
end
|
89
183
|
end
|
90
|
-
end
|
184
|
+
#end
|
91
185
|
end #/iterate_through_file_list_for_disks
|
186
|
+
|
187
|
+
def config_hash
|
188
|
+
config['Config']
|
189
|
+
end
|
92
190
|
|
93
|
-
|
94
|
-
|
191
|
+
|
192
|
+
def self.get_config
|
193
|
+
self.instance.load unless self.instance.load_called
|
194
|
+
self.instance.get_config
|
195
|
+
end
|
196
|
+
end # class Storazzo::RicDiskConfig
|
197
|
+
|
198
|
+
end # module Storazzo
|
199
|
+
|
@@ -0,0 +1,35 @@
|
|
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
|
+
|
22
|
+
public
|
23
|
+
def load # _sample_version
|
24
|
+
puts white("[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
|
+
super(DefaultGemLocationForTests, :verbose => false )
|
27
|
+
end
|
28
|
+
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.")
|
30
|
+
super(DefaultGemLocationForTests, :verbose => false )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # module Storazzo
|
35
|
+
|
@@ -2,9 +2,22 @@
|
|
2
2
|
# directly in the disk: /mount/
|
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
|
+
DefaultName = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
|
8
|
+
Version = "1.1" # @@version
|
6
9
|
|
10
|
+
# AttrAccessor for class - thanks StackOverflow from Android since Im in roaming :)
|
11
|
+
class << self
|
12
|
+
attr_accessor :default_name, :version
|
13
|
+
end
|
7
14
|
|
8
|
-
|
15
|
+
public
|
16
|
+
def self.default_name
|
17
|
+
DefaultName
|
18
|
+
end
|
19
|
+
def self.version
|
20
|
+
Version
|
21
|
+
end
|
9
22
|
end
|
10
23
|
end
|
data/lib/storazzo/version.rb
CHANGED
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,20 +22,30 @@ 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'
|
34
38
|
require 'storazzo/ric_disk' # NEW and will build from ground up using multiple files..
|
39
|
+
#require 'storazzo/ric_disk/asbtract_ric_disk'
|
40
|
+
require 'storazzo/media/abstract_ric_disk'
|
41
|
+
require 'storazzo/media/gcs_bucket'
|
42
|
+
require 'storazzo/media/local_folder'
|
35
43
|
require 'storazzo/ric_disk_ugly' # OLD and 90% working
|
36
|
-
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!!!
|
37
47
|
require 'storazzo/ric_disk_statsfile'
|
38
48
|
require 'storazzo/main'
|
39
|
-
require 'storazzo/translator'
|
40
|
-
|
41
|
-
puts Storazzo::Main.hi
|
49
|
+
#require 'storazzo/translator'
|
42
50
|
|
51
|
+
#puts Storazzo::Main.say_hi
|