storazzo 0.0.5 โ†’ 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b6f11122ebdc242a695b25dee97fc6d09d2059df95f7318b42679a66ccfd9c3
4
- data.tar.gz: '045047399e27b7b9bf55ae5230babb9443dd5903adbabcdf562f16eec1e1b258'
3
+ metadata.gz: f27732afb2b636a54136fdd1db2270c163addc37dc85d35585cee8c4c946b090
4
+ data.tar.gz: a7fe6fbc15aedbef4578662418f1b8d67073d45865d7485efa6816ae14421611
5
5
  SHA512:
6
- metadata.gz: 618bfb7e3664ae8fe0f8429e1c8527aec76bdfd5c37f4cc1693ebfbc41ba94bd0235c13738479f3f2ea31da593d1483ca2c25881edd3be1a8757f2cf3b892fbf
7
- data.tar.gz: 37e515b93523cc8b0b31791152edff586d3a8dfd5490b7b889b0595dbea31ac2a69a2b4b7cdd2c37187fbe545b133921333185ea1a1e48136aead9fc073df49a
6
+ metadata.gz: 7cb68f6675345a08f6a619b3ff0ef0dadc2455c5bc10aecc9f9e8b245f2d271b72a0b0531f4c6149f41cde81bfeb154345a7bc2388d1beca7ac41db25018dd7b
7
+ data.tar.gz: 610059ea7c57e7d303c945104a106935310b141e5322f9096683bc6bbf2dd7f4ec4257ed02c6ebfa1acf24fdb891a6eceb886d6225565424a43fb7087e90a955
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ # useless now
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ # todo
data/Makefile ADDED
@@ -0,0 +1,42 @@
1
+
2
+ VER = $(shell cat VERSION)
3
+
4
+ .PHONY: test clean
5
+
6
+
7
+ help:
8
+ cat Makefile
9
+
10
+ build-local:
11
+ gem build storazzo.gemspec
12
+
13
+ build: build-local
14
+
15
+ install:
16
+ gem install ./storazzo-$(VER).gem
17
+
18
+ push-to-rubygems: build-local test
19
+ gem push ./storazzo-$(VER).gem
20
+
21
+ list:
22
+ gem list -r storazzo
23
+
24
+ test:
25
+ echo 1. Testing the library end to end by requiring it..
26
+ echo "Storazzo::Main.all_tests " | irb -Ilib -rstorazzo
27
+ make mounts
28
+ #echo 2. Testing ricdisk-magic
29
+ #bin/ricdisk-magic Ciao-da-Makefile
30
+ echo 3. run rake test.. ont configured yet just a memo for the future.
31
+ RUBYOPT="-W0" rake test
32
+ @echo 'OK: ALL TESTS PASSED. #STIKA'
33
+
34
+ mounts:
35
+ echo "Storazzo::Main.all_mounts " | irb -Ilib -rstorazzo
36
+
37
+
38
+ irb:
39
+ irb -Ilib -rstorazzo
40
+
41
+ watch-test:
42
+ watch -c make test
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+
2
+ # storazzo Gem
3
+
4
+ ๐Ÿ“ฆ Storazzo ๐Ÿ’Ž gem - a Gem to automatically parse your FS for mounts (๐Ÿ’ฝ ๐Ÿ’พ ๐Ÿ’ฟ ) and compute MD5 (๐Ÿค) of all files therein and then collect in central DB ๐Ÿ”‹ through ๐Ÿ“ฆ StorazzoApp๐Ÿ“ฆ (TM).
5
+
6
+ # INSTALL
7
+
8
+ `gem install storazzo`
9
+
10
+ (Latest version is hosted in https://rubygems.org/gems/storazzo)
11
+
12
+ # Thanks
13
+
14
+ Inspiration from:
15
+
16
+ * hola gem awesome guide: https://guides.rubygems.org/make-your-own-gem/
17
+ * RubyGem from DHH: https://github.com/rails/strong_parameters/tree/master/lib for how to trustucre lib/ and gemspec.
18
+ * Stackoverflow and Google for the rest.
19
+ * Elio e le Storie Tese: _Sai chi ti scandisce il disco un casino? Storazzo!_
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ #require 'rake'
2
+
3
+ # from hola: https://guides.rubygems.org/make-your-own-gem/#adding-an-executable
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.verbose = false
9
+ t.warning = false
10
+ end
11
+
12
+ desc "Run tests"
13
+ task default: :test
14
+
15
+
16
+ # begin
17
+ # require 'bundler/setup'
18
+ # Bundler::GemHelper.install_tasks
19
+ # rescue LoadError
20
+ # puts 'although not required, bundler is recommended for running the tests'
21
+ # end
22
+
23
+ # task default: :spec
24
+
25
+ # require 'rspec/core/rake_task'
26
+ # RSpec::Core::RakeTask.new(:spec)
27
+
28
+ # require 'rubocop/rake_task'
29
+ # RuboCop::RakeTask.new do |task|
30
+ # task.requires << 'rubocop-performance'
31
+ # task.requires << 'rubocop-rspec'
32
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/bin/ricdisk-magic ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+
5
+ ############# ############# ############# ############# ############# ############# ############# #############
6
+ # placeholder until i make it work..
7
+ # https://guides.rubygems.org/make-your-own-gem/#adding-an-executable
8
+ require 'storazzo'
9
+ #require 'lib/storazzo'
10
+ puts "First I need to figure out how to bring in all the libraries in here.."
11
+ puts Storazzo::Main.hi(ARGV[0])
12
+ exit(0)
13
+ ############# ############# ############# ############# ############# ############# ############# #############
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ #require 'google/protobuf'
44
+ #require_relative '../etc/protos/out/ricdisk_pb'
45
+ require 'yaml'
46
+ require 'socket'
47
+ require 'optparse' # http://ruby.about.com/od/advancedruby/a/optionparser.htm
48
+
49
+ # I believe this is wrong
50
+ #require 'storazzo'
51
+ # required to have methods wiothout self.
52
+ #include 'lib/ric_disk'
53
+ #extend Storazzo::Colors
54
+
55
+ if RUBY_VERSION.split('.')[0] == 1
56
+ puts "Refusing to launch a script form Ruby 1. Sorry Ric, its 2020 damn it!"
57
+ exit 2020
58
+ end
59
+
60
+ $PROG_VER = '0.3'
61
+ $DEBUG = false
62
+
63
+ HISTORY = <<-BIG_LONG_MULTILINE
64
+ 2022-07-11 v0.3 Ported from private files in GIC into storazzo (open source on gitHub) and cleaned up italian and libs
65
+ 2022-07-DD v0.2 Some private stuff on GIC
66
+ BIG_LONG_MULTILINE
67
+
68
+ =begin
69
+
70
+ ############################################################
71
+ @author: Riccardo Carlesso
72
+ @email: riccardo.carlesso@gmail.com
73
+ @maturity: development
74
+ @language: Ruby
75
+ @synopsis: Brief Description here
76
+ @tags: development, rcarlesso, test
77
+ @description: See description
78
+ ############################################################
79
+
80
+ =end
81
+
82
+
83
+ $myconf = {
84
+ :app_name => "RicDisk Magic should be sth like #{$0}",
85
+ :description => "
86
+ This program is loosely inspired to ricdisk-magic.sh but its much better.
87
+ Idea di base: trovare tutti le directory con file ricdisk e da esso estrarre info e magari METTERE info.
88
+ Il tutto condito con un bel protobuf e un'entita che metto in Lib.
89
+ ".strip.gsub(/^\s+/, "").gsub(/\s+$/, ""),
90
+ # TODO move to some class default
91
+ :media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
92
+ :mount_types => %w{ vfat ntfs },
93
+ }
94
+ $stats_file = "ricdisk_stats_v11.rds"
95
+ $gcs_bucket = 'palladius'
96
+
97
+ # This template from scripta.rb. from 2.1.0 removed aby ric gem dependency.
98
+ # 2022-04-26 2.1.1 Added more colors
99
+ # 2022-04-26 2.1.0 Historical momemnt: removed gem 'ric' dependency
100
+ $TEMPLATE_VER = '2.1.1'
101
+
102
+
103
+ def usage(comment=nil)
104
+ puts white($optparse.banner)
105
+ puts($optparse.summarize)
106
+ puts("Description: " + gray($myconf[:description]))
107
+ puts red(comment) if comment
108
+ #puts "Description: #{ $myconf[:description] }"
109
+ exit 13
110
+ end
111
+
112
+ # include it in main if you want a custome one
113
+ def init() # see lib_autoinit in lib/util.rb
114
+ $opts = {}
115
+ # setting defaults
116
+ $opts[:verbose] = false
117
+ $opts[:dryrun] = false
118
+ $opts[:debug] = false
119
+ $opts[:force] = false
120
+
121
+ $optparse = OptionParser.new do |opts|
122
+ opts.banner = "#{$0} v.#{$PROG_VER}\n Usage: #{File.basename $0} [options] file1 file2 ..."
123
+ opts.on( '-d', '--debug', 'enables debug (DFLT=false)' ) { $opts[:debug] = true ; $DEBUG = true }
124
+ opts.on( '-f', '--force', 'force stuff (DFLT=false)' ) { $opts[:force] = true }
125
+ opts.on( '-h', '--help', 'Display this screen' ) { usage }
126
+ #opts.on( '-j', '--jabba', 'Activates my Jabber powerful CLI' ) { $opts[:jabba] = true }
127
+ opts.on( '-n', '--dryrun', "Don't really execute code" ) { $opts[:dryrun] = true }
128
+ opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) {|file| $opts[:logfile] = file }
129
+ opts.on( '-v', '--verbose', 'Output more information' ) { $opts[:verbose] = true}
130
+ end
131
+ $optparse.parse!
132
+ end
133
+
134
+ def real_program
135
+ deb("Hello world from a templated '#{yellow $0 }'")
136
+ deb "+ Options are: #{gray $opts}"
137
+ deb "+ Depured args: #{azure ARGV}"
138
+ deb "+ Script-specifig super-cool conf: #{green $prog_conf_d}"
139
+ deb "+ Your configuration: #{purple $myconf.inspect}"
140
+
141
+ # Your code goes here...
142
+ puts white("Hello world from #{$myconf[:app_name]}!")
143
+ puts "Description: '''#{white $myconf[:description] }'''"
144
+
145
+ if ARGV == [] # empty -> ALL
146
+ dirs = RicDisk.find_active_dirs()
147
+ dirs.each {|dir|
148
+ RicDisk.sbrodola_ricdisk(dir)
149
+ RicDisk.calculate_stats_files(dir) # dir is inutile
150
+ } # TODO refactor in option sbrodola_afterwards=true. :)
151
+ else
152
+ deb "I consider ARGV come la lista di directories da parsare :)"
153
+ dirs = RicDisk.find_active_dirs()
154
+ ARGV.each{ |dir|
155
+ dir = File.expand_path(dir)
156
+ if dirs.include?(dir)
157
+ deb "Legit dir: #{green dir}"
158
+ RicDisk.sbrodola_ricdisk(dir)
159
+ RicDisk.calculate_stats_files(dir) # dir is inutile
160
+ else
161
+ deb "Figghiu ri buttana: doesnt exist #{red dir}"
162
+ end
163
+ }
164
+ end
165
+ end
166
+
167
+ def main(filename)
168
+ deb "I'm called by #{white filename}"
169
+ deb "HISTORY: #{gray HISTORY}"
170
+ #deb "To remove this shit, just set $DEBUG=false :)"
171
+ init # Enable this to have command line parsing capabilities!
172
+ #warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
173
+ real_program
174
+ end
175
+
176
+ main(__FILE__)
@@ -1,8 +1,12 @@
1
1
  # Use EXTEND vs INCLUDE and magically the Class will inherit instead of instance. Magical! :)
2
2
  # http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
3
3
 
4
+ module Storazzo
5
+ # needs to be defined before
6
+ end
7
+
4
8
  module Storazzo::Colors
5
- # class Storazzo::Colors
9
+ #class Storazzo::Colors1
6
10
  PREPEND_ME = "[Storazzo::Colors] "
7
11
 
8
12
  def deb(s); puts "#DEB #{gray(s)}" if $DEBUG; end
@@ -38,5 +42,5 @@ module Storazzo::Colors
38
42
  def pred(s) puts(red(s)); end
39
43
  def pyellow(s) puts(yellow(s)); end
40
44
 
41
-
42
- end
45
+ end
46
+ #end
@@ -0,0 +1,10 @@
1
+
2
+ # idea from https://medium.com/@leo_hetsch/ruby-modules-include-vs-prepend-vs-extend-f09837a5b073
3
+ module Debug
4
+
5
+ def log(message)
6
+ # debug output
7
+ puts "TODO(ricc): LOG '#{message}' on GCP :)"
8
+ end
9
+
10
+ end
@@ -0,0 +1,33 @@
1
+ # copied from https://dev.to/ayushn21/how-to-generate-yaml-from-ruby-objects-without-type-annotations-4fli
2
+ module Storazzo
3
+ module Hashify
4
+ # Classes that include this module can exclude certain
5
+ # instance variable from its hash representation by overriding
6
+ # this method
7
+ def ivars_excluded_from_hash
8
+ [ 'this_doesnt_exist' ]
9
+ end
10
+
11
+ def to_hash
12
+ hash = {}
13
+ excluded_ivars = ivars_excluded_from_hash
14
+
15
+ # Iterate over all the instance variables and store their
16
+ # names and values in a hash
17
+ instance_variables.each do |var|
18
+ next if excluded_ivars.include? var.to_s
19
+
20
+ value = instance_variable_get(var)
21
+ value = value.map(&:to_hash) if value.is_a? Array
22
+
23
+ hash[var.to_s.delete("@")] = value
24
+ end
25
+
26
+ return hash
27
+ end
28
+
29
+ def to_yaml
30
+ to_hash.to_yaml
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,61 @@
1
+ # main entrypoint for tests and silly stuff from Makefile..
2
+ # This Class externalizes all relevant things from other libs while I learn how to do it from there
3
+ # eg from RicDisk.
4
+
5
+ module Storazzo
6
+
7
+ # This is the Main Class - an entrypoint to call the meravilles hidden therein.
8
+ #
9
+ # Example:
10
+ # >> Storazzo.hi("ciao bello")
11
+ # => Hello from Storazzo v0.1.1!
12
+ #
13
+ # Arguments:
14
+ # message: (String) - optional
15
+
16
+
17
+ class Storazzo::Main # Can be same name as Module: https://stackoverflow.com/questions/13261474/ruby-modules-and-classes-same-name-in-structure
18
+ require 'storazzo/colors'
19
+ extend Storazzo::Colors
20
+
21
+ # version 1.2
22
+ def self.hi(message=nil)
23
+ str = "Hello from Storazzo v#{white Storazzo::version rescue "Error: #{$!}"}!"
24
+ str += " Message: '#{yellow message.to_s}'" if message
25
+ puts str
26
+ str
27
+ end
28
+
29
+ def self.all_mounts(opts={})
30
+ opts_verbose = opts.fetch :verbose, true
31
+
32
+ self.hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDisk::RICDISK_VERSION}"
33
+
34
+ pwhite "TODO(ricc): show a list of all RicDisk relevant mounts" if opts_verbose
35
+ #sbrodola_ricdisk("/Volumes/")
36
+ Storazzo::RicDisk.find_active_dirs
37
+ #Storazzo::RicDisk.sbrodola_ricdisk StorazzoMod::root + "./var/disks/"
38
+ #sbrodola_ricdisk(StorazzoMod::root + "./var/disks/") rescue "[Storazzo::AllMount] SomeError: #{$!}"
39
+ self.hi 'Storazzo::Main.all_mounts(): END'
40
+ end
41
+
42
+ def self.all_tests
43
+ # include vs extend: https://stackoverflow.com/questions/15097929/ruby-module-require-and-include
44
+ # => http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
45
+ #include Storazzo::Colors
46
+ extend Storazzo::Colors
47
+
48
+ pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
49
+ deb "Maybe debug is enabled?"
50
+ hi
51
+ # This works with EXTEND..
52
+ puts(yellow "Just YELLOW 0")
53
+ # This reqwuires a INCLUDE.
54
+ #puts(Storazzo::Colors.yellow "Test YELLOW 1 self")
55
+ #puts(Colors.yellow "Test YELLOW 1 self")
56
+ #puts(Colors.green "Test YELLOW 2 ohne self")
57
+ pwhite "All tests END"
58
+ #puts "All tests END"
59
+ end
60
+ end
61
+ end
File without changes
@@ -0,0 +1,241 @@
1
+
2
+
3
+ module Storazzo
4
+ class Storazzo::RicDisk
5
+ RICDISK_VERSION = "1.0"
6
+ DEFAULT_MEDIA_DIRS = %w{
7
+ /media/riccardo/
8
+ /Volumes/
9
+ /mnt/
10
+ ~/git/storazzo/var/test/disks/
11
+ /wrong/on/purpose/
12
+ }.append(Storazzo.root + "/var/test/disks/")
13
+
14
+
15
+ include Hashify
16
+ extend Storazzo::Colors
17
+
18
+ # todo substitute wqith protobuf..
19
+ attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr
20
+
21
+ def self.interesting_mount_points(opts={})
22
+ #https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
23
+ `mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '`.split(/\n+/)
24
+ end
25
+
26
+ def initialize(path, ricdisk_file)
27
+ @local_mountpoint = path
28
+ @description = "This is an automated RicDisk description from v.#{VERSION}. Riccardo feel free to edit away with characteristicshs of this device.. Created on #{Time.now}'"
29
+ @ricdisk_version = VERSION
30
+ @ricdisk_file = ricdisk_file
31
+ #@questo_non_esiste = :sobenme
32
+ @label = path.split("/").last
33
+ @name = path.split("/").last
34
+ @wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
35
+ @tags = 'ricdisk'
36
+ find_info_from_mount(path)
37
+ find_info_from_df()
38
+ end
39
+
40
+ def ricdisk_absolute_path
41
+ @local_mountpoint + "/" + @ricdisk_file
42
+ end
43
+
44
+ def add_tag(tag)
45
+ @tags += ", #{tag}"
46
+ end
47
+
48
+ # might have other things in the future...
49
+ def find_info_from_mount(path)
50
+ mount_table_lines = interesting_mount_points()
51
+ mount_line = nil
52
+ mount_table_lines.each do |line|
53
+ next if line =~ /^map /
54
+ dev, on, mount_path, mode = line.split(/ /)
55
+ if mount_path==path
56
+ mount_line = line
57
+ else
58
+ @info_from_mount = false
59
+ end
60
+ end
61
+ @info_from_mount = ! (mount_line.nil?)
62
+ if @info_from_mount
63
+ #@mount_line = mount_line
64
+ @description += "\nMount line:\n" + mount_line
65
+ @remote_mountpoint = mount_line.split(/ /)[0]
66
+ @fstype = mount_line.split(/ /)[3].gsub(/[\(,]/, '')
67
+ add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
68
+ end
69
+ end
70
+
71
+ def find_info_from_df()
72
+ path = @local_mountpoint
73
+ df_info = `df -h "#{path}"`
74
+ @df_info = df_info
75
+ lines = df_info.split(/\n+/)
76
+ raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
77
+ mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
78
+ end
79
+
80
+
81
+
82
+ def self.sbrodola_ricdisk(subdir)
83
+ # given a path, if .ricdisk exists i do stuff with it..
84
+ disk_info = nil
85
+ unless self.ok_dir?(subdir)
86
+ puts("Nothing for me here. Existing")
87
+ return
88
+ end
89
+ if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
90
+ deb("Interesting1. Empty file! Now I write YAML with it.")
91
+ disk_info = RicDisk.new(subdir, '.ricdisk')
92
+ #puts(x)
93
+ #puts(yellow x.to_yaml)
94
+ end
95
+ if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
96
+ deb("Interesting2. Empty file! TODO write YAML with it.")
97
+ disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
98
+ # todo write
99
+ #puts(x)
100
+ puts(yellow disk_info.to_yaml)
101
+ end
102
+ if disk_info
103
+ if File.empty?(disk_info.ricdisk_absolute_path) and (disk_info.wr)
104
+ puts(green("yay, we can now write the file '#{disk_info.ricdisk_absolute_path}' (which is R/W, I just checked!) with proper YAML content.."))
105
+ ret = File.write(disk_info.ricdisk_absolute_path, disk_info.to_yaml)
106
+ puts("Written file! ret=#{ret}")
107
+ else
108
+ puts(red("Nope, qualcosa non va.. #{File.empty?(disk_info.ricdisk_absolute_path)}"))
109
+ puts("File size: #{File.size(disk_info.ricdisk_absolute_path)}")
110
+ end
111
+ end
112
+ if File.exists?( "#{subdir}/.ricdisk") and ! File.empty?( "#{subdir}/.ricdisk")
113
+ puts("Config File found with old-style name: '#{subdir}/.ricdisk' !")
114
+ #puts(white `cat "#{subdir}/.ricdisk"`)
115
+ end
116
+ end
117
+
118
+ # separiamo cosi usiamo meglio...
119
+ def self.ok_dir?(subdir)
120
+ File.exists?( "#{subdir}/.ricdisk") or File.exists?( "#{subdir}/.ricdisk.yaml")
121
+ end
122
+
123
+ def self.obsolescence_seconds file_path
124
+ creation_time = File.stat(file_path).ctime
125
+ deb("[obsolescence_seconds] File #{file_path}: #{creation_time} - #{(Time.now - creation_time)} seconds ago")
126
+ (Time.now - creation_time).to_i
127
+ end
128
+ def self.obsolescence_days(file_path)
129
+ return obsolescence_seconds(file_path) / 86400
130
+ end
131
+
132
+ def self.backquote_execute(cmd)
133
+ # executed a command wrapped by dryrun though
134
+ return "DRYRUN backquote_execute(#{cmd})" if $opts[:dryrun]
135
+ `#{cmd}`
136
+ end
137
+
138
+ def self.upload_to_gcs(file, opts={})
139
+ deb("upload_to_gcs(#{file}). TODO(ricc) after breafast upload to GCS : #{file}")
140
+ mount_name = file.split('/')[-2]
141
+ filename = "#{mount_name}-#{File.basename file}"
142
+ hostname = Socket.gethostname[/^[^.]+/]
143
+ command = "gsutil cp '#{file}' gs://#{$gcs_bucket}/backup/ricdisk-magic/#{ hostname }-#{filename}"
144
+ deb("Command: #{command}")
145
+ ret = backquote_execute(command)
146
+ # if $opts[:debug] do
147
+ # puts "+ Current list of files:"
148
+ # ret = backquote_execute("gsutil ls -al gs://#{$gcs_bucket}/backup/ricdisk-magic/")
149
+ # puts ret
150
+ # end
151
+ ret
152
+ end
153
+
154
+ # Create RDS file.
155
+ def self.calculate_stats_files(dir, opts={})
156
+ opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
157
+ full_file_path = "#{dir}/#{$stats_file}"
158
+
159
+ puts("calculate_stats_files(#{white dir}): #{white full_file_path}")
160
+ puts "TEST1 DIR EXISTS: #{dir} -> #{Dir.directory? dir}"
161
+ Dir.chdir(dir)
162
+ if File.exists?(full_file_path) and ($opts[:force] == false)
163
+ puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
164
+ # TODO check for file time...
165
+ print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
166
+ if obsolescence_days(full_file_path) > 7
167
+ puts("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
168
+ end
169
+ upload_to_gcs(full_file_path) if opts_upload_to_gcs
170
+ else
171
+ puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
172
+ command = "find . -print0 | xargs -0 stats-with-md5.rb --no-color | tee '#{full_file_path}'"
173
+ puts("[#{`pwd`.chomp}] Executing: #{azure command}")
174
+ ret = backquote_execute command
175
+ puts "Done. #{ret.split("\n").count} files processed."
176
+ end
177
+ end
178
+
179
+ def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
180
+ base_dirs = DEFAULT_MEDIA_DIRS if base_dirs.nil?
181
+ active_dirs = []
182
+ base_dirs.each do |ugly_dir|
183
+ # https://stackoverflow.com/questions/1899072/getting-a-list-of-folders-in-a-directory#:~:text=Dir.chdir(%27/destination_directory%27)%0ADir.glob(%27*%27).select%20%7B%7Cf%7C%20File.directory%3F%20f%7D
184
+ dir = File.expand_path(ugly_dir)
185
+ begin
186
+ x=[]
187
+ # puts "TEST2 DIR EXISTS: #{dir} -> #{Dir.exists?(dir)}"
188
+ unless Dir.exists?(dir)
189
+ deb "Dir doesnt exist, skipping: #{dir}"
190
+ next
191
+ end
192
+ Dir.chdir(dir)
193
+ x = Dir.glob('*').select {|f| File.directory? f}
194
+ subdirs = x.map{|subdir| "#{dir}#{subdir}"}
195
+ subdirs.each{|subdir|
196
+ #puts `ls -al "#{subdir}"`
197
+ active_dirs << subdir if self.ok_dir?(subdir)
198
+ }
199
+ #puts(white x)
200
+ rescue Exception => e # optionally: `rescue Exception => ex`
201
+ puts "Exception: '#{e}'"
202
+ ensure # will always get executed
203
+ #deb 'Always gets executed.'
204
+ #x = []
205
+ end
206
+ end
207
+
208
+ if also_mountpoints
209
+ =begin
210
+ Example output from mount:
211
+
212
+ devfs on /dev (devfs, local, nobrowse)
213
+ /dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
214
+ /dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
215
+ /dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
216
+ /dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
217
+ /dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
218
+ /dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
219
+ /dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
220
+ map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
221
+ //riccardo@1.0.1.10/video on /Volumes/video (afpfs, nodev, nosuid, mounted by ricc)
222
+ //riccardo@1.0.1.10/photo on /Volumes/photo (afpfs, nodev, nosuid, mounted by ricc)
223
+ =end
224
+ # add directories from current mountpoints...
225
+ mount_table_lines = interesting_mount_points()
226
+ mount_table_lines.each{|line|
227
+ next if line =~ /^map /
228
+ dev, on, path, mode = line.split(/ /)
229
+ #puts line
230
+ #deb yellow(path)
231
+ active_dirs << path if self.ok_dir?(path)
232
+ }
233
+ end
234
+ active_dirs.uniq!
235
+ puts("find_active_dirs(): found dirs " + green(active_dirs))
236
+ return active_dirs
237
+ end
238
+
239
+
240
+ end
241
+ end
@@ -0,0 +1,6 @@
1
+ # copied from https://github.com/rails/strong_parameters/edit/master/lib/strong_parameters/version.rb
2
+ # I;'m copying the DHH philosophy here.
3
+ module Storazzo
4
+ DHH_VERSION = "0.2.3_TODOFileRead" # TODO file.read ../../VERSION . chomp
5
+ end
6
+
data/lib/storazzo.rb CHANGED
@@ -1,43 +1,30 @@
1
- # copied from https://guides.rubygems.org/make-your-own-gem/#introduction
1
+ # Inspired from https://guides.rubygems.org/make-your-own-gem/#introduction
2
2
 
3
- #require 'storazzo/colors'
4
3
 
5
- module StorazzoMod
6
- VERSION = File.read('./VERSION').chomp # "10.0.0"
4
+ module Storazzo
5
+ #VERSION = File.read('./VERSION').chomp # "10.0.0"
7
6
  #require 'storazzo/translator'
8
7
 
9
- def latest_version
8
+ def latest_parser_version
10
9
  "1.2"
11
10
  end
12
- end
13
-
14
- class Storazzo
15
- require 'storazzo/colors'
16
11
 
17
- # version 1.2
18
- def self.hi
19
- puts "Hello from Storazzo v#{StorazzoMod::VERSION rescue :ERROR}!"
12
+ # Finds RAILS_ROOT for Storazzo Gem. Copied from:
13
+ # https://stackoverflow.com/questions/10132949/finding-the-gem-root
14
+ def self.root
15
+ File.expand_path '../..', __FILE__
20
16
  end
21
17
 
22
- def self.all_tests
23
- # include vs extend: https://stackoverflow.com/questions/15097929/ruby-module-require-and-include
24
- # => http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
25
- #include Storazzo::Colors
26
- extend Storazzo::Colors
27
-
28
- pwhite "All tests BEGIN"
29
- deb "Maybe debug is enabled?"
30
- #puts "This is Storazzo v#{StorazzoMod::VERSION}"
31
- hi
32
- # This works with EXTEND..
33
- puts(yellow "Just YELLOW 0")
34
- # This reqwuires a INCLUDE.
35
- #puts(Storazzo::Colors.yellow "Test YELLOW 1 self")
36
- #puts(Colors.yellow "Test YELLOW 1 self")
37
- #puts(Colors.green "Test YELLOW 2 ohne self")
38
- pwhite "All tests END"
39
- #puts "All tests END"
18
+ def self.version
19
+ File.read(self.root + '/VERSION').chomp # "10.0.0"
40
20
  end
41
- end
21
+ end
42
22
 
23
+ require 'storazzo/colors'
24
+ require 'storazzo/hashify'
25
+ require 'storazzo/ric_disk'
26
+ require 'storazzo/main'
43
27
  require 'storazzo/translator'
28
+
29
+ puts Storazzo::Main.hi
30
+
data/storazzo.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "storazzo"
3
+ # TOSDO: copy approach from here to dry version calculating: https://github.com/rails/strong_parameters/blob/master/strong_parameters.gemspec#L15
4
+ s.version = File.read("VERSION").chomp # TODO cat version File.read(@,.VERSION).chomp
5
+ s.summary = "storazzo is an amazing gem. Code is in https://github.com/palladius/storazzo"
6
+ s.description = "A simple gem to manage your external hard drives and extract MD5 and common stuff from them."
7
+ s.authors = ["Riccardo Carlesso"]
8
+ s.email = "name dot surname at popular Google-owned Mail"
9
+ # Autoglob as per https://stackoverflow.com/questions/11873294/determining-the-gems-list-of-files-for-the-specification
10
+ s.files = %w(Gemfile LICENSE README.md Makefile Rakefile storazzo.gemspec VERSION) + Dir["{bin,lib,test,var}/**/*"]
11
+ s.test_files = Dir["test/**/*"] + Dir["var/test/**/*"]
12
+ s.executables << "ricdisk-magic"
13
+
14
+ s.homepage = "https://rubygems.org/gems/storazzo" # maybe https://github.com/palladius/storazzo
15
+ s.license = "MIT"
16
+
17
+ #s.add_dependency "activesupport", "~> 3.0"
18
+ end
@@ -0,0 +1,34 @@
1
+ require "minitest/autorun"
2
+ require "storazzo"
3
+
4
+ class StorazzoTest < Minitest::Test
5
+ def test_storazzo_hi_with_argument
6
+ assert_match "Hello from Storazzo", Storazzo::Main.hi("ruby this should fail")
7
+ assert_match "ruby this should fail", Storazzo::Main.hi("ruby this should fail")
8
+ end
9
+ def test_storazzo_hi_without_argument
10
+ assert_match "Hello from Storazzo", Storazzo::Main.hi()
11
+ end
12
+
13
+ def test_storazzo_version_should_have_3_numbers_and_2_dots
14
+ # puts Storazzo::version
15
+ assert_equal Storazzo::version.split('.').size , 3, "should be 3 parts, like A.B.C"
16
+ #major, minor, minuscule = Storazzo::VERSION.split('.')
17
+ # assert_match Storazzo::VERSION, "....."
18
+ end
19
+
20
+ # def test_english_hello
21
+ # assert_equal "hello world",
22
+ # Hola.hi("english")
23
+ # end
24
+
25
+ # def test_any_hello
26
+ # assert_equal "hello world",
27
+ # Hola.hi("ruby")
28
+ # end
29
+
30
+ # def test_spanish_hello
31
+ # assert_equal "hola mundo",
32
+ # Hola.hi("spanish")
33
+ # end
34
+ end
@@ -0,0 +1 @@
1
+ Just to test two disks: one with stuff and one empty.
File without changes
@@ -0,0 +1,6 @@
1
+ total 0
2
+ drwxr-xr-x 5 ricc primarygroup 160 Jul 13 07:18 .
3
+ drwxr-xr-x 4 ricc primarygroup 128 Jul 13 07:17 ..
4
+ -rw-r--r-- 1 ricc primarygroup 0 Jul 13 07:17 .ricdisk
5
+ -rw-r--r-- 1 ricc primarygroup 0 Jul 13 07:18 fake file.touch
6
+ -rw-r--r-- 1 ricc primarygroup 0 Jul 13 07:18 ls.txt
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riccardo Carlesso
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple hello world gem.. for now. Then... more!
13
+ description: A simple gem to manage your external hard drives and extract MD5 and
14
+ common stuff from them.
14
15
  email: name dot surname at popular Google-owned Mail
15
- executables: []
16
+ executables:
17
+ - ricdisk-magic
16
18
  extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
21
+ - Gemfile
22
+ - LICENSE
23
+ - Makefile
24
+ - README.md
25
+ - Rakefile
26
+ - VERSION
27
+ - bin/ricdisk-magic
19
28
  - lib/storazzo.rb
20
29
  - lib/storazzo/colors.rb
30
+ - lib/storazzo/debug.rb
31
+ - lib/storazzo/hashify.rb
32
+ - lib/storazzo/main.rb
33
+ - lib/storazzo/parser/parser.rb
34
+ - lib/storazzo/ric_disk.rb
21
35
  - lib/storazzo/translator.rb
36
+ - lib/storazzo/version.rb
37
+ - storazzo.gemspec
38
+ - test/test_storazzo.rb
39
+ - var/test/README.md
40
+ - var/test/disks/disk02-full/fake file.touch
41
+ - var/test/disks/disk02-full/ls.txt
22
42
  homepage: https://rubygems.org/gems/storazzo
23
43
  licenses:
24
44
  - MIT
25
45
  metadata: {}
26
- post_install_message:
46
+ post_install_message:
27
47
  rdoc_options: []
28
48
  require_paths:
29
49
  - lib
@@ -39,7 +59,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
59
  version: '0'
40
60
  requirements: []
41
61
  rubygems_version: 3.1.4
42
- signing_key:
62
+ signing_key:
43
63
  specification_version: 4
44
64
  summary: storazzo is an amazing gem. Code is in https://github.com/palladius/storazzo
45
- test_files: []
65
+ test_files:
66
+ - test/test_storazzo.rb
67
+ - var/test/README.md
68
+ - var/test/disks/disk02-full/fake file.touch
69
+ - var/test/disks/disk02-full/ls.txt