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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e82c96fbdff7b8d2f78556899257b431ec1e58ec255321bae2afb4ba3b1ac309
4
- data.tar.gz: f343d195bce5121d18f456b3fd90f8032a41427ae41e4248f5b8628aca1b0a3e
3
+ metadata.gz: cd4df2335167b54bd0c1ef58279131c00d554e75a04411bea14b3ebb80417b93
4
+ data.tar.gz: 1aa197bfff96028744fa4e3f1d1dc48998c0b970b1413bb8fbfcdb3912e71ec9
5
5
  SHA512:
6
- metadata.gz: d9aa08e7fcc62e0d8a3510db4d26f27e227aa778f8e9d8e6d7831676936c282e97f72f57f08febdc7383dec2f1e4c66beb42eb94dae3638f422fc6073292f204
7
- data.tar.gz: e75cb487f55943dbae3d23242909ca61a83c39aaf5ef793225c074181f6914290d7f11aa3fa537f43010db4feab239efb14e88c5f30d91f737465081ad825309
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
- # gem 'after_do' # To allow AFTER calling instance to do LOAD() automagically. Naah I can do without :)
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.6.1
1
+ 0.7.0
data/bin/hello-storazzo CHANGED
@@ -3,4 +3,6 @@
3
3
 
4
4
  require 'storazzo'
5
5
 
6
- Storazzo::Main.say_hi(ARGV[0])
6
+ msg = ARGV.empty? ? 'HelloStorazzo' : ARGV.join(' ')
7
+
8
+ Storazzo::Main.say_hi(msg)
data/bin/storazzo CHANGED
@@ -2,157 +2,109 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'storazzo'
5
- # gem 'storazzo', :path => File.expand_path("../lib", __FILE__)
5
+ require 'thor'
6
6
 
7
- require 'optparse'
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
- $PROG_VER = '0.1'
18
- $DEBUG = ENV['DEBUG'] == 'true' # (true/false)
19
-
20
- $actions = %w[
21
- show auto help
22
- ].sort
23
-
24
- # you can't but love Ruby monkey-patching ability..
25
- class Array
26
- # puts "array drop"
27
- def tail
28
- drop(1) # https://stackoverflow.com/questions/3615700/ruby-what-is-the-easiest-way-to-remove-the-first-element-from-an-array
29
- end
30
- end
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
- HISTORY = <<-BIG_LONG_MULTILINE
33
- 2022-0806 v0.1 First stesure
34
- BIG_LONG_MULTILINE
35
-
36
- $description = <<DESCRIPTION_HEREFILE.gsub(/\s+/, ' ').strip
37
- This util shall expose all Storazzo aPIs via CLI: show-local-dirs, ...
38
- show GCS buckets, ...
39
-
40
- It's also my dream to add some nice icons which are joy to the eye, like
41
- some [ ] [x] before the list to show if its agood or bad directory and type also#{' '}
42
- DESCRIPTION_HEREFILE
43
- # >> "SELECT * FROM users ORDER BY users.id DESC"
44
-
45
- $myconf = {
46
- app_name: "Storazzo CLI: #{$PROGRAM_NAME}",
47
- description: $description
48
- # TODO: move to some class default
49
- # :media_dirs => %w{/media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/
50
- # /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/},
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
- # include it in main if you want a custome one
64
- # see lib_autoinit in lib/util.rb
65
- def init
66
- $opts = {}
67
- # setting defaults
68
- $opts[:verbose] = false
69
- $opts[:dryrun] = false
70
- $opts[:debug] = false
71
- $opts[:force] = false
72
-
73
- $optparse = OptionParser.new do |opts|
74
- opts.banner = "#{$PROGRAM_NAME} v.#{$PROG_VER}\n Usage: #{File.basename $PROGRAM_NAME} [options] ACTION [file1] [file2] ..."
75
- opts.separator "Actions: #{$actions.join ', '}"
76
- opts.separator ' $0 show # show options and local folders '
77
- opts.separator ' $0 auto # takes automated actions based on config and local disk. For lazy users'
78
- opts.separator 'Options: '
79
- opts.on('-d', '--debug', 'enables debug (DFLT=false)') do
80
- $opts[:debug] = true
81
- $DEBUG = true
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
- def show_action(argv)
96
- deb "ARGV remaning is: #{argv}"
97
- deb('TODO show_action')
98
- # puts(white("1. Config"))
99
- # Pry::ColorPrinter.pp $config.to_verbose_s
100
- puts(white('2. Mounts/Dirs'))
101
- Pry::ColorPrinter.pp Storazzo::Media::GcsBucket.list_all_with_type
102
- pp Storazzo::Media::AbstractRicDisk.super_duper_list_all_with_type
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
- def real_program
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 main(filename)
144
- deb "I'm called by #{white filename}"
145
- deb "HISTORY: #{gray HISTORY}"
146
- init # Enable this to have command line parsing capabilities!
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
- main(__FILE__)
110
+ Storazzo::CLI.start(ARGV)
@@ -1 +1 @@
1
- bin/storazzo
1
+ storazzo
data/bin/storazzo-util CHANGED
@@ -1 +1 @@
1
- bin/storazzo
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
- # Can be same name as Module: https://stackoverflow.com/questions/13261474/ruby-modules-and-classes-same-name-in-structure
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