Class: Storazzo::RicDiskConfig
- Inherits:
-
Object
- Object
- Storazzo::RicDiskConfig
- Defined in:
- lib/storazzo/ric_disk_config.rb
Direct Known Subclasses
Constant Summary collapse
- DefaultConfigLocation =
File. '~/.storazzo.yaml'
- DEFAULT_CONFIG_LOCATIONS =
[ File.('~/.storazzo.yaml'), # HOME File.('./.storazzo.yaml') # LOCAL DIR ].freeze
- DefaultGemLocationForTests =
"#{File.('../..', __dir__)}/etc/storazzo_config.sample.yaml"
Constants included from Colors
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#load_called ⇒ Object
Returns the value of attribute load_called.
-
#project_id ⇒ Object
doesnt work :/ alias :project_id, :config_project_id.
Class Method Summary collapse
Instance Method Summary collapse
- #already_loaded? ⇒ Boolean
- #config_default_folder ⇒ Object
- #config_hash ⇒ Object
- #config_project_id ⇒ Object
- #config_ver ⇒ Object
-
#gcs_enabled? ⇒ Boolean
This should return true if and only if the user has configured the YAML to use GCS.
- #get_bucket_paths ⇒ Object
- #get_config(opts = {}) ⇒ Object
-
#get_local_folders ⇒ Object
returns all folders from file which are Directories This method is FLAKY! Sometimes gives error.
-
#iterate_through_file_list_for_disks(files_list = [], opts = {}) ⇒ Object
UGLY CODE, copipasted from binary for ARGV, ex autosbrodola.
-
#load(config_path = nil, opts = {}) ⇒ Object
Load from the first valid config.
-
#load_sample_version ⇒ Object
Obsolete, call another class instead.
- #to_s ⇒ Object
- #to_verbose_s ⇒ Object
Methods included from Colors
#azure, #blue, #deb2, #gray, #green, #orange, #pgreen, #pred, #purple, #pwhite, #pyellow, #red, #white, #yellow
Methods included from Common
#bug, #deb, #err, #fatal, #if_deb?, #linux?, #mac?, #ppp, #pverbose, #warn
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
40 41 42 |
# File 'lib/storazzo/ric_disk_config.rb', line 40 def config @config end |
#config_file ⇒ Object
Returns the value of attribute config_file.
40 41 42 |
# File 'lib/storazzo/ric_disk_config.rb', line 40 def config_file @config_file end |
#load_called ⇒ Object
Returns the value of attribute load_called.
40 41 42 |
# File 'lib/storazzo/ric_disk_config.rb', line 40 def load_called @load_called end |
#project_id ⇒ Object
doesnt work :/ alias :project_id, :config_project_id
131 132 133 |
# File 'lib/storazzo/ric_disk_config.rb', line 131 def project_id @project_id end |
Class Method Details
.gem_default_config_path ⇒ Object
181 182 183 |
# File 'lib/storazzo/ric_disk_config.rb', line 181 def self.gem_default_config_path "#{Storazzo.root}/etc/storazzo_config.sample.yaml" end |
.get_config ⇒ Object
261 262 263 264 |
# File 'lib/storazzo/ric_disk_config.rb', line 261 def self.get_config instance.load unless instance.load_called instance.get_config end |
.safe_instance ⇒ Object
254 255 256 257 258 259 |
# File 'lib/storazzo/ric_disk_config.rb', line 254 def self.safe_instance puts 'This is a safe instance :)' my_config = instance my_config.load my_config end |
Instance Method Details
#already_loaded? ⇒ Boolean
145 146 147 148 |
# File 'lib/storazzo/ric_disk_config.rb', line 145 def already_loaded? # return load_called == true end |
#config_default_folder ⇒ Object
121 122 123 124 |
# File 'lib/storazzo/ric_disk_config.rb', line 121 def config_default_folder # self. @config['Config']['DefaultFolder'] # rescue "Unknown config_default_folder: #{$!}" end |
#config_hash ⇒ Object
250 251 252 |
# File 'lib/storazzo/ric_disk_config.rb', line 250 def config_hash config['Config'] end |
#config_project_id ⇒ Object
126 127 128 |
# File 'lib/storazzo/ric_disk_config.rb', line 126 def config_project_id @config['Config']['Backends']['GoogleCloudStorage']['ProjectId'] end |
#config_ver ⇒ Object
114 115 116 117 118 119 |
# File 'lib/storazzo/ric_disk_config.rb', line 114 def config_ver raise 'I cant compute Version since I cant compute @config. Are you sure you didnt instance this Singleton without calling load?' if @config.nil? @config['apiVersion'] # rescue :StillUnknown # config['ConfigVersion'] end |
#gcs_enabled? ⇒ Boolean
This should return true if and only if the user has configured the YAML to use GCS. For now we can just say TRUE since gsutil ls returns without project_id. However, we might have a flag enabled in storazzo config in next versions.
138 139 140 141 142 143 |
# File 'lib/storazzo/ric_disk_config.rb', line 138 def gcs_enabled? # true defined?(get_config['Config']['Backends']['GoogleCloudStorage']) # get_config['Config']['Backends']['GoogleCloudStorage DOESNT EXIST'] # defined? Backends: GoogleCloudStorage end |
#get_bucket_paths ⇒ Object
207 208 209 210 211 |
# File 'lib/storazzo/ric_disk_config.rb', line 207 def get_bucket_paths get_config['Config']['Backends']['GoogleCloudStorage']['BucketPaths'].map do |complex_gcs_struct| complex_gcs_struct['path'] end end |
#get_config(opts = {}) ⇒ Object
175 176 177 178 179 |
# File 'lib/storazzo/ric_disk_config.rb', line 175 def get_config(opts = {}) return load(opts) if @config.nil? @config end |
#get_local_folders ⇒ Object
returns all folders from file which are Directories This method is FLAKY! Sometimes gives error.
LocalFolderTest#test_show_all_shouldnt_fail_and_should_return_a_non_empty_array:
TypeError: no implicit conversion of Hash into String
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `expand_path'
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `block in load'
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `each'
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `load'
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:83:in `get_config'
/Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:95:in `get_local_folders'
197 198 199 200 201 202 203 204 205 |
# File 'lib/storazzo/ric_disk_config.rb', line 197 def get_local_folders config = get_config # puts config['Config']['AdditionalMountDirs'] config['Config']['AdditionalMountDirs'].map do |folder| File.(folder) rescue StandardError folder end.filter { |f| File.directory?(f) } end |
#iterate_through_file_list_for_disks(files_list = [], opts = {}) ⇒ Object
UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/storazzo/ric_disk_config.rb', line 214 def iterate_through_file_list_for_disks(files_list = [], opts = {}) verbose = opts.fetch :verbose, false raise "[iterate_through_file_list_for_disks] Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array) # I decided i wont accept an emopty list, this is not how you use the gem, you lazy XXX! # if files_list == [] # or files_list.nil? # empty -> ALL # deb "iterate_through_file_list_for_disks(): no args provided" # dirs = RicDisk.find_active_dirs() # puts "DEB find_active_dirs: #{green dirs}" # dirs.each {|dir| # RicDisk.write_config_yaml_to_disk(dir) # RicDisk.calculate_stats_files(dir) # dir is inutile # } # TODO refactor in option sbrodola_afterwards=true. :) # else pverbose verbose, 'iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)' # dirs = RicDisk.find_active_dirs() files_list.each do |dir| dir = File.(dir) if File.directory?(dir) # if dirs.include?(dir) pverbose verbose, "iterate_through_file_list_for_disks() Legit dir: #{green dir}" rd = RicDisk.new(Storazzo::Media::AbstractRicDisk.DirFactory(dir)) pverbose verbose, "RicDisk from Factory (woohoo): #{rd}" rd.write_config_yaml_to_disk(dir) # RicDisk.write_config_yaml_to_disk(dir) # RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files rd.compute_stats_files # dir is inutile # TODO else raise("Doesnt seem a dir to me, quitting: #{dir}") end end # end end |
#load(config_path = nil, opts = {}) ⇒ Object
Load from the first valid config.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/storazzo/ric_disk_config.rb', line 43 def load(config_path = nil, opts = {}) verbose = opts.fetch :verbose, false if already_loaded? # and not self.config.nil? pverbose verbose, "[#{self.class}] Config.Load: already loaded" return config end pverbose verbose, 'Storazzo::RicDiskConfig.load(): BEGIN' # trying default location raise 'DefaultConfigLocation is not a string' unless DefaultConfigLocation.is_a?(String) possible_locations = DEFAULT_CONFIG_LOCATIONS.dup # [ default_config_locations .. , "./.storazzo.yaml"] deb "[Config.load] Possible Locations: #{possible_locations}" if config_path.is_a?(String) # possible_locations = [config_path] + possible_locations # .append() possible_locations.unshift(config_path) # append to front # OR: possible_locations.instert(0, config_path) pverbose verbose, "[LOAD] possible_locations: #{possible_locations}" end pverbose verbose, "Searching these paths in order: #{possible_locations}" # bug "This is not always an array of sTRINGS." raise 'possible_locations is not an array' unless possible_locations.is_a?(Array) possible_locations.each do |possible_path| # ASSERT is a string raise 'possible_path is not a string' unless possible_path.is_a?(String) deb "before buggy expand_path paz: '#{possible_path}''" paz = begin File.(possible_path) rescue StandardError possible_path end raise "Not a string: #{paz}" unless paz.is_a?(String) next unless File.exist?(paz) @config_file = paz @config = YAML.safe_load(File.read(paz)) # YAML.load(File.read("file_path")) unless begin @config['kind'] == 'StorazzoConfig' rescue StandardError false end puts white "RicDiskConfig.load(): Sorry this is wrong Config File. Kind=#{begin @config['kind'] rescue StandardError $ERROR_INFO end}" next end # # pp @config if verbose config_ver = @config['apiVersion'] # puts @config[:ConfigVersion] deb("OK. Storazzo::RicDiskConfig v'#{config_ver}' parsed correctly") @load_called = true return config end @load_called = true # only get here if nothing is found raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}" end |
#load_sample_version ⇒ Object
Obsolete, call another class instead.
110 111 112 |
# File 'lib/storazzo/ric_disk_config.rb', line 110 def load_sample_version raise 'DEPRECATED! USE SampleRicDiskConfig.load() instead!' end |
#to_s ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/storazzo/ric_disk_config.rb', line 150 def to_s size = begin File.size(@config_file) rescue StandardError -1 end # puts yellow "DEB: #{@config["apiVersion"]}" # "RicDiskConfig(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}" "POLY_#{self.class}_(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}" end |
#to_verbose_s ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/storazzo/ric_disk_config.rb', line 161 def to_verbose_s h = {} h[:description] = 'This is a Verbose Hash describing a RicDiskConfig or its child RicDiskSampleConfig to understand why it keeps failing..' h[:to_s] = to_s h[:class] = self.class h[:file] = __FILE__ h[:id] = object_id h[:get_bucket_paths] = get_bucket_paths h[:get_local_folders] = get_local_folders h[:config_project_id] = config_project_id h end |