storazzo 0.6.1 → 0.7.0
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 +13 -1
- data/README.md +2 -1
- data/VERSION +1 -1
- data/bin/hello-storazzo +3 -1
- data/bin/storazzo +93 -141
- data/bin/storazzo-symlink.rb +1 -1
- data/bin/storazzo-util +1 -1
- data/lib/storazzo/main.rb +2 -5
- data/lib/storazzo/media/abstract_ric_disk.rb +162 -167
- data/lib/storazzo/media/gcs_bucket.rb +64 -69
- data/lib/storazzo/media/local_folder.rb +45 -49
- data/lib/storazzo/media/mount_point.rb +11 -15
- data/lib/storazzo/ric_disk.rb +6 -8
- data/lib/storazzo/ric_disk_config.rb +210 -214
- data/lib/storazzo/ric_disk_sample_config.rb +16 -18
- data/lib/storazzo/ric_disk_statsfile.rb +3 -5
- data/lib/storazzo/search_engine.rb +64 -0
- data/lib/storazzo/version.rb +1 -1
- data/lib/storazzo.rb +1 -7
- data/storazzo.gemspec +4 -3
- data/test/media/test_local_folder.rb +2 -10
- data/test/test_ric_disk.rb +3 -1
- data/var/test/disks/ricdisk_stats_v11.rds +19 -11
- metadata +58 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd4df2335167b54bd0c1ef58279131c00d554e75a04411bea14b3ebb80417b93
|
|
4
|
+
data.tar.gz: 1aa197bfff96028744fa4e3f1d1dc48998c0b970b1413bb8fbfcdb3912e71ec9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3aa715f7601839c5f1149b45932cbfc3fedddfbc664501ac8ed3a32f86f7a227a702a9a4825882b310772a20e4bf6503fddea9f6a47253a7906e91d2fa03773b
|
|
7
|
+
data.tar.gz: d4475efdfdb0f25e979d58140c573bf3bb347271d7df07d11a2cffe88a39d4dfda388532d03ef7d656d50a5b45418853c14c4ca80352b903149125cd6cd5e448
|
data/Gemfile
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
|
+
gemspec
|
|
6
|
+
|
|
5
7
|
# to troubleshoot/debug things
|
|
6
8
|
gem 'rake'
|
|
7
9
|
gem 'rubocop'
|
|
@@ -9,4 +11,14 @@ gem 'ruby-lsp', '~> 0.0.4', group: :development
|
|
|
9
11
|
|
|
10
12
|
# gem 'pry'
|
|
11
13
|
gem 'pry', group: :development
|
|
12
|
-
|
|
14
|
+
gem 'minitest', group: :development
|
|
15
|
+
|
|
16
|
+
gem 'sqlite3'
|
|
17
|
+
gem 'thor'
|
|
18
|
+
gem 'google-cloud-storage'
|
|
19
|
+
|
|
20
|
+
group :test do
|
|
21
|
+
gem 'minitest'
|
|
22
|
+
gem 'minitest-reporters'
|
|
23
|
+
gem 'mocha'
|
|
24
|
+
end
|
data/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Single test in single file:
|
|
|
22
22
|
|
|
23
23
|
* `rake test TEST="test/sum_test.rb" TESTOPTS="--name=test_returns_two"` (sample)
|
|
24
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
|
|
25
|
+
* `ruby -I test test/test_local_folder.rb -n test_first_directory_parsing_actually_works` (note this includes `storazzo` latest gem
|
|
26
26
|
and doesnt benefit from LATEST code so its NOT good for testing: use RAKE for that).
|
|
27
27
|
|
|
28
28
|
**Testing binary files** is hard: by default they 'require storazzo' and use the GEM INSTALLed version which is a few versions away, usually.
|
|
@@ -32,6 +32,7 @@ So while developing you might want to include the lib/ folder, like this:
|
|
|
32
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
33
|
|
|
34
34
|
Now to toggle verbosity I believe I need to go into Rakefile (bummer)
|
|
35
|
+
|
|
35
36
|
# Thanks
|
|
36
37
|
|
|
37
38
|
Inspiration from:
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.7.0
|
data/bin/hello-storazzo
CHANGED
data/bin/storazzo
CHANGED
|
@@ -2,157 +2,109 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'storazzo'
|
|
5
|
-
|
|
5
|
+
require 'thor'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
extend Storazzo::Colors
|
|
10
|
-
include Storazzo::Common # instead
|
|
11
|
-
|
|
12
|
-
if RUBY_VERSION.split('.')[0] == 1
|
|
13
|
-
puts 'Refusing to launch a script form Ruby 1. Sorry Ric, its 2020 damn it!'
|
|
7
|
+
if RUBY_VERSION.split('.')[0].to_i < 3
|
|
8
|
+
puts 'Refusing to launch a script form Ruby < 3.'
|
|
14
9
|
exit 2020
|
|
15
10
|
end
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
module Storazzo
|
|
13
|
+
class CLI < Thor
|
|
14
|
+
include ::Storazzo::Colors
|
|
15
|
+
include ::Storazzo::Common
|
|
16
|
+
|
|
17
|
+
class_option :verbose, type: :boolean, default: false, desc: 'Output more information'
|
|
18
|
+
class_option :debug, type: :boolean, default: false, desc: 'Enable debug mode'
|
|
19
|
+
|
|
20
|
+
desc "scan PATH", "Scan a removable disk or local folder and upload its metadata to GCS"
|
|
21
|
+
def scan(path)
|
|
22
|
+
setup_env
|
|
23
|
+
puts "Scanning path: #{path}"
|
|
24
|
+
|
|
25
|
+
dir = File.expand_path(path)
|
|
26
|
+
unless File.directory?(dir)
|
|
27
|
+
puts "Error: #{dir} is not a valid directory."
|
|
28
|
+
exit 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
config = Storazzo::RicDiskConfig.instance
|
|
32
|
+
config.load
|
|
33
|
+
|
|
34
|
+
rd = Storazzo::RicDisk.new(Storazzo::Media::AbstractRicDisk.DirFactory(dir))
|
|
35
|
+
rd.write_config_yaml_to_disk(dir)
|
|
36
|
+
rd.compute_stats_files(upload_to_gcs: true)
|
|
37
|
+
|
|
38
|
+
puts "Scan completed for #{dir}."
|
|
39
|
+
end
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# :mount_types => %w{vfat ntfs},
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
def usage(comment = nil)
|
|
55
|
-
puts white($optparse.banner)
|
|
56
|
-
puts($optparse.summarize)
|
|
57
|
-
# puts("Description: " + gray($myconf[:description]))
|
|
58
|
-
puts red("ERROR: #{comment}") if comment
|
|
59
|
-
# puts "Description: #{ $myconf[:description] }"
|
|
60
|
-
exit 13
|
|
61
|
-
end
|
|
41
|
+
desc "search QUERY", "Search for a keyword across all indexed disks via SQLite DB"
|
|
42
|
+
def search(query)
|
|
43
|
+
setup_env
|
|
44
|
+
require 'storazzo/search_engine'
|
|
45
|
+
|
|
46
|
+
puts "Searching for: #{query}"
|
|
47
|
+
engine = Storazzo::SearchEngine.new
|
|
48
|
+
engine.sync_from_gcs
|
|
49
|
+
results = engine.query(query)
|
|
50
|
+
|
|
51
|
+
if results.empty?
|
|
52
|
+
puts "No results found for '#{query}'."
|
|
53
|
+
else
|
|
54
|
+
puts "Found #{results.size} matches:"
|
|
55
|
+
results.each do |r|
|
|
56
|
+
puts "- [#{r[:disk]}] #{r[:path]} (size: #{r[:size]})"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
desc "backup SRC DEST", "Backup a local folder to GCS and update index"
|
|
62
|
+
def backup(src, dest)
|
|
63
|
+
setup_env
|
|
64
|
+
puts "Backing up #{src} to #{dest}"
|
|
65
|
+
|
|
66
|
+
src_dir = File.expand_path(src)
|
|
67
|
+
unless File.directory?(src_dir)
|
|
68
|
+
puts "Error: #{src_dir} is not a valid directory."
|
|
69
|
+
exit 1
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# 1. Run gsutil rsync
|
|
73
|
+
cmd = "gsutil -m rsync -r '#{src_dir}' '#{dest}'"
|
|
74
|
+
puts "Running: #{cmd}"
|
|
75
|
+
system(cmd)
|
|
76
|
+
unless $?.success?
|
|
77
|
+
puts "Failed to backup files to GCS."
|
|
78
|
+
exit 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# 2. Compute stats on the destination bucket
|
|
82
|
+
require 'storazzo/search_engine'
|
|
83
|
+
# We could run `stats-with-md5` for GCS here to generate the index
|
|
84
|
+
# and upload to metadata bucket
|
|
85
|
+
puts "Indexing GCS bucket: #{dest}"
|
|
86
|
+
cmd_stats = "stats-with-md5 --autowrite '#{dest}'"
|
|
87
|
+
system(cmd_stats)
|
|
88
|
+
|
|
89
|
+
puts "Backup and indexing completed."
|
|
82
90
|
end
|
|
83
|
-
opts.on('-f', '--force', 'force stuff (DFLT=false)') { $opts[:force] = true }
|
|
84
|
-
opts.on('-h', '--help', 'Display this screen') { usage }
|
|
85
|
-
# opts.on( '-j', '--jabba', 'Activates my Jabber powerful CLI' ) { $opts[:jabba] = true }
|
|
86
|
-
opts.on('-n', '--dryrun', "Don't really execute code") { $opts[:dryrun] = true }
|
|
87
|
-
opts.on('-l', '--logfile FILE', 'Write log to FILE') { |file| $opts[:logfile] = file }
|
|
88
|
-
opts.on('-v', '--verbose', 'Output more information') { $opts[:verbose] = true }
|
|
89
|
-
opts.separator("Description: #{gray($myconf[:description])}")
|
|
90
|
-
# opts.separator " -- "
|
|
91
|
-
end
|
|
92
|
-
$optparse.parse!
|
|
93
|
-
end
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
end
|
|
92
|
+
desc "show", "Show options and local folders"
|
|
93
|
+
def show
|
|
94
|
+
setup_env
|
|
95
|
+
puts("1. Mounts/Dirs")
|
|
96
|
+
require 'pp'
|
|
97
|
+
pp Storazzo::Media::GcsBucket.list_all_with_type
|
|
98
|
+
pp Storazzo::Media::AbstractRicDisk.super_duper_list_all_with_type
|
|
99
|
+
end
|
|
104
100
|
|
|
105
|
-
|
|
106
|
-
deb("Hello world from a templated '#{yellow $PROGRAM_NAME}'")
|
|
107
|
-
deb "+ Options are: #{gray $opts}"
|
|
108
|
-
deb "+ Depured args: #{azure ARGV}"
|
|
109
|
-
deb "+ Script-specifig super-cool conf: #{green $prog_conf_d}"
|
|
110
|
-
deb "+ Your configuration: #{purple $myconf.inspect}"
|
|
111
|
-
|
|
112
|
-
# Your code goes here...
|
|
113
|
-
puts white("Hello world from #{$myconf[:app_name]}!")
|
|
114
|
-
puts "Description: '''#{white $myconf[:description]}'''"
|
|
115
|
-
Storazzo::Main.say_hi("Note: if the version of this storazzo is behind local version youre probably using a old library.
|
|
116
|
-
I still need to learn how to call the binary with local/current lib/: bundle exec stiKazzi?")
|
|
117
|
-
|
|
118
|
-
$config = Storazzo::RicDiskConfig.instance
|
|
119
|
-
$config.load
|
|
120
|
-
deb "StorazzoConfig: #{$config}"
|
|
121
|
-
# config.load # auto_sbrodola(ARGV)
|
|
122
|
-
puts yellow("ARGV: #{ARGV}")
|
|
123
|
-
# config.iterate_through_file_list_for_disks(ARGV)
|
|
124
|
-
|
|
125
|
-
if_deb? { Storazzo::Main.say_hi("ARGV: #{ARGV}") }
|
|
126
|
-
|
|
127
|
-
usage('I need at least one argument (storazzo ACTION)') if ARGV == []
|
|
128
|
-
argv_action = ARGV[0]
|
|
129
|
-
case argv_action # first argment - action
|
|
130
|
-
when 'show', 'list'
|
|
131
|
-
show_action(ARGV.tail)
|
|
132
|
-
when 'auto'
|
|
133
|
-
auto_action(ARGV.tail)
|
|
134
|
-
when 'help'
|
|
135
|
-
usage("There you go, here's your HELP :)")
|
|
136
|
-
when String
|
|
137
|
-
usage("Unknown action1: #{argv_action}. Available actions: #{$actions}")
|
|
138
|
-
else
|
|
139
|
-
usage("Unknown action2, really strange!: '#{argv_action}'. Actions: #{$actions}")
|
|
140
|
-
end
|
|
141
|
-
end
|
|
101
|
+
private
|
|
142
102
|
|
|
143
|
-
def
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
puts white("$DEBUG is #{$DEBUG}. Tu turn on, call me with -d") unless $DEBUG
|
|
148
|
-
# warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
|
|
149
|
-
real_program
|
|
150
|
-
|
|
151
|
-
if_deb? do
|
|
152
|
-
puts 'First I need to figure out how to bring in all the libraries in here..'
|
|
153
|
-
Storazzo::Main.say_hi("ARGV is: #{ARGV.join ', '}")
|
|
154
|
-
puts Storazzo.version
|
|
103
|
+
def setup_env
|
|
104
|
+
$DEBUG = options[:debug]
|
|
105
|
+
$opts = { verbose: options[:verbose], debug: options[:debug] }
|
|
106
|
+
end
|
|
155
107
|
end
|
|
156
108
|
end
|
|
157
109
|
|
|
158
|
-
|
|
110
|
+
Storazzo::CLI.start(ARGV)
|
data/bin/storazzo-symlink.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
storazzo
|
data/bin/storazzo-util
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
storazzo
|
data/lib/storazzo/main.rb
CHANGED
|
@@ -15,11 +15,9 @@ module Storazzo
|
|
|
15
15
|
# Arguments:
|
|
16
16
|
# message: (String) - optional
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
module Storazzo
|
|
20
|
-
class Main
|
|
18
|
+
class Main
|
|
21
19
|
require 'storazzo/colors'
|
|
22
|
-
extend Storazzo::Colors
|
|
20
|
+
extend ::Storazzo::Colors
|
|
23
21
|
|
|
24
22
|
# version 1.2
|
|
25
23
|
def self.say_hi(message = nil)
|
|
@@ -78,6 +76,5 @@ module Storazzo
|
|
|
78
76
|
pwhite 'All tests END'
|
|
79
77
|
# puts "All tests END"
|
|
80
78
|
end
|
|
81
|
-
end
|
|
82
79
|
end
|
|
83
80
|
end
|