storazzo 0.4.1 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -3
- data/Makefile +20 -1
- data/README.md +23 -0
- data/Rakefile +33 -3
- data/VERSION +1 -1
- data/bin/hello-storazzo +6 -0
- data/bin/ricdisk-magic +0 -1
- data/bin/stats-with-md5 +1 -35
- data/lib/storazzo/common.rb +62 -5
- data/lib/storazzo/main.rb +7 -2
- data/lib/storazzo/media/abstract_ric_disk.rb +58 -10
- data/lib/storazzo/media/gcs_bucket.rb +35 -0
- data/lib/storazzo/media/local_folder.rb +10 -12
- data/lib/storazzo/media/mount_point.rb +11 -0
- data/lib/storazzo/ric_disk.rb +99 -110
- data/lib/storazzo/ric_disk_config.rb +53 -21
- data/lib/storazzo/ric_disk_sample_config.rb +2 -6
- data/lib/storazzo/ric_disk_statsfile.rb +0 -1
- data/lib/storazzo/version.rb +1 -1
- data/lib/storazzo.rb +10 -5
- data/storazzo.gemspec +3 -2
- data/test/media/test_abstract_ric_disk.rb +23 -0
- data/test/{test_gcs_bucket.rb → media/test_gcs_bucket.rb} +4 -13
- data/test/{test_local_folder.rb → media/test_local_folder.rb} +46 -20
- data/test/media/test_mount_point.rb +26 -0
- data/test/test_ric_disk.rb +17 -0
- data/test/test_ric_disk_config.rb +3 -8
- data/var/dumps/file_stat.linux.yaml +15 -0
- data/var/dumps/file_stat.macosx.yaml +15 -0
- data/var/test/disks/disk02-full/Rakefile +13 -0
- data/var/test/disks/ricdisk_stats_v11.rds +22 -0
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 927e612eb67cd979a514fd123ad7c693ce89743f6c59b25c51ed71dfdf0a66f4
|
4
|
+
data.tar.gz: 0f10a5abd99ef8592a34fbc572f94b59828b453b80089838e4ba50bcfb5f5837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 413fc87ce3e29403cce9736dc22152d95ee07dbfe734795403c60a27df5dc5441f497c18a2c51ff49a8b5441cde3433002e741ede8df0cbf5820a44fe0947d33
|
7
|
+
data.tar.gz: 662d4f33d5638c85954808e9eb574596cc28cbbf6722d3d54bf4b44a08357f88a1780c407b450002c2d0d2d38a8f44bf805c490ec507a6262fd826b5c7b91864
|
data/Gemfile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
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
|
9
|
+
#gem 'after_do' # To allow AFTER calling instance to do LOAD() automagically. Naah I can do without :)
|
data/Makefile
CHANGED
@@ -51,4 +51,23 @@ watch-test:
|
|
51
51
|
watch -c make test
|
52
52
|
|
53
53
|
test-gcs-bucket:
|
54
|
-
|
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"
|
68
|
+
|
69
|
+
test-binary-with-local-gem:
|
70
|
+
ruby -Ilib bin/hello-storazzo
|
71
|
+
test-binary-with-system-gem:
|
72
|
+
bin/hello-storazzo
|
73
|
+
|
data/README.md
CHANGED
@@ -9,6 +9,29 @@
|
|
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
|
+
**Testing binary files** is hard: by default they 'require storazzo' and use the GEM INSTALLed version which is a few versions away, usually.
|
29
|
+
So while developing you might want to include the lib/ folder, like this:
|
30
|
+
|
31
|
+
* Use local gem (super latest) for checking latest code: `ruby -Ilib bin/hello-storazzo`
|
32
|
+
* This will use the gem installed a few days ago, likely so wont do you any good to test latest code: `bin/hello-storazzo`
|
33
|
+
|
34
|
+
Now to toggle verbosity I believe I need to go into Rakefile (bummer)
|
12
35
|
# Thanks
|
13
36
|
|
14
37
|
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
|
-
|
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.
|
1
|
+
0.4.9
|
data/bin/hello-storazzo
ADDED
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
|
|
data/lib/storazzo/common.rb
CHANGED
@@ -1,10 +1,34 @@
|
|
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
|
#
|
8
|
+
=begin
|
9
|
+
Emoji to copy:
|
10
|
+
👍 👎 👌 ✌ 👋 🤝 👏 🤘 🤟 🤙 🤏 🙌 🙏 🖖 🤞 ✋ 🤚 🖐 🖑 🤲 👐 👊 🤛 🤜 🖕
|
11
|
+
👈 👉 👆 👇
|
12
|
+
☺ ☻ 😃 😄 😅 😆 😊 😎 😇 😈 😏 🤣 🤩 🤪 🥳 😁 😀 😂 🤠 🤡 🤑 🤓 🤖 kiss
|
13
|
+
😗 😚 😘 😙 flirting
|
14
|
+
😉 🤗 😍 🥰 🤤 😋 😛 😜 😝 neutral
|
15
|
+
😶 🙃 😐 😑 🤔 🤨 🧐 hush
|
16
|
+
🤭 🤫 😯 🤐 😌 😖 😕 😳 😔 🤥 🥴 shocked
|
17
|
+
😮 😲 🤯 tired
|
18
|
+
😩 😫 🥱 😪 😴 😵 sad
|
19
|
+
☹ 😦 😞 😥 😟 cry
|
20
|
+
😢 😭 sick
|
21
|
+
🤢 🤮 😷 🤒 🤕 🥵 🥶 fear
|
22
|
+
🥺 😬 😓 😰 😨 😱 angry
|
23
|
+
😒 😠 😡 😤 😣 😧 🤬 😸 😹 😺 😻 😼 😽 😾 😿 🙀 🙈 🙉 🙊
|
24
|
+
[see Animal Emoji 🐰] gesture
|
25
|
+
🤦 🤷 🙅 🙆 🙋 🙌 🙍 🙎 🙇 🙏 activity
|
26
|
+
👯 💃 🕺 🤳 💇 💈 💆 🧖 🧘 🧍 🧎 👰 🤰 🤱 faces
|
27
|
+
👶 🧒 👦 👧 👩 👨 🧑 🧔 🧓 👴 👵 👤 👥 👪 👫 👬 👭 👱 👳 👲 🧕 👸 🤴 🎅 🤶 disabled
|
28
|
+
🧏 🦻 🦮 🦯 🦺 🦼 🦽 🦾 🦿 🤵 👮 👷 💁 💂 🕴 🕵 🦸 🦹 🧙 🧚 🧜 🧝 🧞 🧛 🧟 👼 👿 👻 👹 👺 👽 👾 🛸 💀 ☠ 🕱 🧠 🦴 👁 👀 👂 👃 👄 🗢 👅 🦷 🦵 🦶 💭 🗬 🗭 💬 🗨 🗩 🗪 🗫 🗰 🗱 🗮 🗯 🗣 🗤 🗥 🗦 🗧 💦 💧 💢 💫 💤 💨 💥 💪 🗲 🔥 💡 💩 💯 🔟 🔰 🕲
|
29
|
+
=end
|
7
30
|
require_relative 'colors'
|
31
|
+
require 'pry'
|
8
32
|
|
9
33
|
module Storazzo::Common
|
10
34
|
|
@@ -12,16 +36,49 @@ module Storazzo::Common
|
|
12
36
|
|
13
37
|
|
14
38
|
def deb(s)
|
15
|
-
puts "[DEB] #{yellow(s)}" if $DEBUG
|
39
|
+
puts "[DEB👀] #{yellow(s)}" if _debug_true # $DEBUG
|
40
|
+
end
|
41
|
+
# this has a yield
|
42
|
+
def if_deb?()
|
43
|
+
if _debug_true # $DEBUG
|
44
|
+
deb "== yield START =="
|
45
|
+
yield
|
46
|
+
deb "== yield END =="
|
47
|
+
end
|
16
48
|
end
|
17
49
|
def warn(s)
|
18
|
-
puts "[
|
50
|
+
puts "[W⚠️RN] #{azure(s)}"
|
19
51
|
end
|
20
52
|
def err(str)
|
21
|
-
puts "[ERR] #{red(s)}"
|
53
|
+
puts "[ERR👎] #{red(s)}" # ⛔
|
22
54
|
end
|
23
55
|
def bug(s)
|
24
56
|
puts "[🐛] #{gray s}"
|
25
57
|
end
|
58
|
+
def pverbose(is_verbose, str)
|
59
|
+
#puts "[V📚RB💀S📚] #{gray str}"
|
60
|
+
puts "[🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟] #{gray str}" # insects: http://xahlee.info/comp/unicode_insects.html
|
61
|
+
end
|
62
|
+
def ppp(complex_object_to_colorize)
|
63
|
+
# TODO i need to learn to return without printing..
|
64
|
+
Pry::ColorPrinter.pp(complex_object_to_colorize)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fatal(s)
|
68
|
+
raise "[F💀TAL] #{red s}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def mac?
|
72
|
+
`uname`.chomp == 'Darwin'
|
73
|
+
end
|
74
|
+
def linux?
|
75
|
+
`uname`.chomp == 'Linux'
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def _debug_true
|
80
|
+
$DEBUG or ENV["DEBUG"] == 'true'
|
81
|
+
end
|
26
82
|
|
83
|
+
# puts "[DEBUG ENABLED!]" if _debug_true
|
27
84
|
end
|
data/lib/storazzo/main.rb
CHANGED
@@ -20,11 +20,16 @@ module Storazzo
|
|
20
20
|
|
21
21
|
# version 1.2
|
22
22
|
def self.say_hi(message=nil)
|
23
|
-
str =
|
24
|
-
str += " Message: '#{yellow message.to_s}'" if message
|
23
|
+
str = get_hi(message)
|
25
24
|
puts str
|
26
25
|
str
|
27
26
|
end
|
27
|
+
# salutation
|
28
|
+
def self.get_hi(message=nil)
|
29
|
+
str = "Hello from Storazzo v#{white Storazzo::version rescue "Error: #{$!}"}!"
|
30
|
+
str += " Message: '#{yellow message.to_s}'" if message
|
31
|
+
str
|
32
|
+
end
|
28
33
|
|
29
34
|
def self.all_mounts(opts={})
|
30
35
|
opts_verbose = opts.fetch :verbose, true
|
@@ -1,23 +1,35 @@
|
|
1
1
|
module Storazzo::Media
|
2
2
|
class Storazzo::Media::AbstractRicDisk
|
3
|
+
#include Storazzo::Common
|
4
|
+
extend Storazzo::Common
|
3
5
|
|
4
|
-
|
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
|
+
attr_accessor :description
|
11
13
|
########################
|
12
14
|
# Abstract methods START
|
13
15
|
########################
|
14
16
|
def initialize(local_mount)
|
15
|
-
|
16
|
-
|
17
|
+
deb "[AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
|
18
|
+
@description ||= "Not provided"
|
19
|
+
#validate
|
17
20
|
end
|
18
21
|
def self.list_all
|
19
22
|
raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo"
|
20
23
|
end
|
24
|
+
def self.list_all_with_type
|
25
|
+
raise "[AbstractRicDiskc::self.list_all_with_type] You should override this, says StackOverflow and Riccardo"
|
26
|
+
end
|
27
|
+
def self.super_duper_list_all_with_type
|
28
|
+
deb "Would be cool to be able to enumerate them all.."
|
29
|
+
GcsBucket.list_all_with_type +
|
30
|
+
MountPoint.list_all_with_type +
|
31
|
+
LocalFolder.list_all_with_type
|
32
|
+
end
|
21
33
|
def parse(opts={})
|
22
34
|
raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo"
|
23
35
|
end
|
@@ -50,7 +62,7 @@ module Storazzo::Media
|
|
50
62
|
# if not writeable, I will:
|
51
63
|
# 1. create a dir based on its unique format.
|
52
64
|
# 2. create a file of same look and feel (alternative - used a DASH)
|
53
|
-
return "{get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
|
65
|
+
return "TODO FIXME {get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
|
54
66
|
#"{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
|
55
67
|
end
|
56
68
|
end
|
@@ -63,10 +75,30 @@ module Storazzo::Media
|
|
63
75
|
"MD5::v1::#{hash}"
|
64
76
|
end
|
65
77
|
|
78
|
+
def to_s(verbose=false)
|
79
|
+
return to_verbose_s() if verbose
|
80
|
+
readable_class = self.class.to_s.split('::').last # Storazzo::Media::LocalFolder => LocalFolder
|
81
|
+
my_keys = self.instance_variables # wow!
|
82
|
+
"S:M:#{readable_class}(path=#{path}, r/w=#{wr}, keys=#{my_keys})"
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_verbose_s
|
86
|
+
h = {}
|
87
|
+
h[:class] = self.class
|
88
|
+
h[:unique_id] = self.unique_id
|
89
|
+
h[:inspect] = self.inspect
|
90
|
+
h[:to_s] = self.to_s
|
91
|
+
h[:local_mountpoint] = local_mountpoint
|
92
|
+
h[:writeable] = self.writeable?
|
93
|
+
h[:stats_file_smart_fullpath] = stats_file_smart_fullpath
|
94
|
+
return h
|
95
|
+
end
|
96
|
+
|
66
97
|
# # Todo check on instances these 3 methods exist
|
67
98
|
def self.abstract_class_mandatory_methods
|
68
99
|
%W{
|
69
100
|
self.list_all
|
101
|
+
self.list_all_with_type
|
70
102
|
local_mountpoint
|
71
103
|
parse
|
72
104
|
writeable?
|
@@ -76,7 +108,9 @@ module Storazzo::Media
|
|
76
108
|
# Putting here since its same code for MountPoint or generic folder.
|
77
109
|
def parse_block_storage_folder(opts={})
|
78
110
|
#Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint)
|
79
|
-
Storazzo::RicDisk.
|
111
|
+
rd = Storazzo::RicDisk.new(self)
|
112
|
+
#Storazzo::RicDisk
|
113
|
+
rd.compute_stats_files(opts)
|
80
114
|
#return "42"
|
81
115
|
end
|
82
116
|
|
@@ -92,15 +126,29 @@ module Storazzo::Media
|
|
92
126
|
"#{local_mountpoint}/#{my_stats_filename}"
|
93
127
|
end
|
94
128
|
|
95
|
-
def validate
|
96
|
-
|
129
|
+
def validate(opts={})
|
130
|
+
verbose = opts.fetch(:verbose, true)
|
131
|
+
puts "[VERBOSE] validate(): We're trying to see if your object is valid, across 3 possible sub-classes." if verbose
|
97
132
|
#1. check for
|
98
133
|
raise "Unknown local mount " unless local_mount.is_a?(String)
|
99
134
|
#2. check thaty writeable? is true or false
|
100
135
|
my_writeable = wr
|
101
136
|
raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass )
|
102
137
|
end
|
138
|
+
|
139
|
+
# TODO use a proper Factory pattern.
|
140
|
+
def self.DirFactory(path)
|
141
|
+
raise "I need a path/directory string: #{path}" unless path.is_a?(String)
|
142
|
+
|
143
|
+
deb "TODO: if coincides with MountPoint, instance THAT"
|
144
|
+
# if path in Storazzo::Media::MountPoint.list_all_mount_points
|
145
|
+
# then return ...
|
146
|
+
if path =~ /^gs:\/\//
|
147
|
+
deb "Smells like GCS"
|
148
|
+
return GcsBucket.new(path)
|
149
|
+
end
|
150
|
+
deb "Smells like LocalFolder :)"
|
151
|
+
return LocalFolder.new(path)
|
152
|
+
end
|
103
153
|
end
|
104
|
-
#puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD inside module"
|
105
154
|
end
|
106
|
-
#puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD outside module"
|
@@ -2,6 +2,20 @@ module Storazzo::Media
|
|
2
2
|
|
3
3
|
class Storazzo::RicDisk::GcsBucket
|
4
4
|
|
5
|
+
extend Storazzo::Common
|
6
|
+
|
7
|
+
attr_accessor :project_id
|
8
|
+
|
9
|
+
def initialize(local_mount, project_id=nil)
|
10
|
+
deb "[Storazzo::Media::GcsBucket] initialize"
|
11
|
+
|
12
|
+
@local_mountpoint = File.expand_path(local_mount)
|
13
|
+
@description = "MountPoint in '#{local_mount}' pointing at TODO with mount options = TODO"
|
14
|
+
@project_id = project_id
|
15
|
+
raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
|
16
|
+
@wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
|
17
|
+
super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
|
18
|
+
end
|
5
19
|
|
6
20
|
def self.list_all(config=nil)
|
7
21
|
# get lisrts from Config singletone
|
@@ -13,8 +27,29 @@ module Storazzo::Media
|
|
13
27
|
#puts "TODO see config: #{config}"
|
14
28
|
#[42, 43]
|
15
29
|
#deb config.get_local_folders
|
30
|
+
# TODO
|
31
|
+
pverbose true, "TODO(ricc): also add gsutil ls. For that please use the new 'list_all_with_type' (Id refactor it but Im afraid of leaving bad code dangling so before a proper refactor lets implement both side by side"
|
16
32
|
config.get_bucket_paths
|
17
33
|
end
|
34
|
+
def self.list_all_with_type(config=nil)
|
35
|
+
config ||= Storazzo::RicDiskConfig.instance
|
36
|
+
config.load # in case I need to load it for the first time
|
37
|
+
deb "TODO(ricc): also add gsutil ls"
|
38
|
+
# getFromConfig
|
39
|
+
deb "I'm now returning a 'complex' array to tell the caller what kind of element they're getting, eg: GCS from Config Yaml, vs GCS from gsutil ls "
|
40
|
+
list_from_config_with_type = config.get_bucket_paths.map{|path| [:config_gcs_bucket, path] }
|
41
|
+
if (config.project_id)
|
42
|
+
# so I concatenate Apples with Bananas with names
|
43
|
+
return list_from_config_with_type + list_available_buckets(config.project_id).map{|path| [:gsutil_ls_gcs_bucket, path] }
|
44
|
+
end
|
45
|
+
return list_from_config_with_type
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.list_available_buckets(project_id, opts={})
|
49
|
+
list_of_buckets = `gsutil ls --project '#{project_id}'`.chomp.split("\n")
|
50
|
+
deb "list_of_buckets: #{list_of_buckets}"
|
51
|
+
list_of_buckets
|
52
|
+
end
|
18
53
|
|
19
54
|
|
20
55
|
end
|
@@ -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
|
-
|
12
|
+
deb "[Storazzo::Media::LocalFolder] initialize"
|
11
13
|
|
12
14
|
@local_mountpoint = File.expand_path(local_mount)
|
15
|
+
@description = "Local Folder originally in '#{local_mount}'"
|
13
16
|
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
|
-
|
17
|
+
@wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
|
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
|
22
|
-
|
23
|
-
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,15 @@
|
|
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
|
+
|
6
|
+
|
7
|
+
def self.list_local_mount_points()
|
8
|
+
deb "Maybe its abuot time you refactor that method here :)"
|
9
|
+
RicDisk.interesting_mount_points()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
2
13
|
|
3
14
|
# def writeable?
|
4
15
|
#File.writable?(@local_mountpoint)
|