storazzo 0.1.1 → 0.2.1

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: 0c1d447526136c87cfefa48b69232971dd9e6df07a07ac1410eede18d0fa6b5e
4
- data.tar.gz: c295db76797061749062a49f01b0bf08132ff86b5c48f61b0549d10bbe8066e0
3
+ metadata.gz: b4f4672b3d74c331f1b352f0222a2bb53d8be4ee0903703af69ec7cf4c41a714
4
+ data.tar.gz: c8438ba1c39183217e9e4570dd5013e5ae19389836b054fbf12824e7bc25a174
5
5
  SHA512:
6
- metadata.gz: 6127acae73ae0e07e3b000344e8b784964e50aa40a99404d5d0b1653a04c93c9f92270531ae5add2247b0e8d91fb5f501af1535d6dfa28abc123df6ce964b957
7
- data.tar.gz: 1abb40a264233b9df3f87cb46222b235dbc64baef885e8589c30c18d31fef103dba95291d83787b07c856f4ce54f85602747068c88e90bb0f411d389a44cc269
6
+ metadata.gz: 34f3068aff14301f3931d6098d3cbdbdcee743ad0311858117341b55b7456a27cf835490cc1bf8e6082ce489807298fa6cd115f06149852ed1af76bdc5f9538b
7
+ data.tar.gz: dc9f78da4db98ee8ddf4a02bab936cb45a5b617745ca4761f80cb8d6e269f4846e07e58059875b27fa0d6443997d965a3dd0a57a9174ba7821dae01520adb42b
data/Gemfile CHANGED
@@ -1 +1,5 @@
1
- # useless now
1
+ # useless now
2
+
3
+
4
+ # to troubleshoot/debug things
5
+ gem 'rubocop'
data/Makefile CHANGED
@@ -23,16 +23,24 @@ list:
23
23
 
24
24
  test:
25
25
  echo 1. Testing the library end to end by requiring it..
26
- echo "Storazzo::Main.all_tests " | irb -Ilib -rstorazzo
27
- #echo "Storazzo::Main.all_mounts " | irb -Ilib -rstorazzo
26
+ echo "Storazzo::Main.all_tests " | irb -Ilib -rstorazzo
27
+ make mounts
28
28
  #echo 2. Testing ricdisk-magic
29
29
  #bin/ricdisk-magic Ciao-da-Makefile
30
30
  echo 3. run rake test.. ont configured yet just a memo for the future.
31
31
  RUBYOPT="-W0" rake test
32
+ echo 4. Prove I can include local gem in irb and play around. Similarly to rails console without reload.
33
+ make irb-test
32
34
  @echo 'OK: ALL TESTS PASSED. #STIKA'
33
35
 
36
+ # RicDisk test
37
+ mounts:
38
+ echo "Storazzo::Main.all_mounts ; nil" | irb -Ilib -rstorazzo
39
+
34
40
  irb:
35
41
  irb -Ilib -rstorazzo
42
+ irb-test:
43
+ ./irb-test.sh
36
44
 
37
45
  watch-test:
38
46
  watch -c make test
data/README.md CHANGED
@@ -1,10 +1,19 @@
1
1
 
2
2
  # storazzo Gem
3
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).
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
5
 
6
6
  # INSTALL
7
7
 
8
8
  `gem install storazzo`
9
9
 
10
- (Latest version is hosted in https://rubygems.org/gems/storazzo)
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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.1
data/bin/ricdisk-magic CHANGED
@@ -6,45 +6,20 @@
6
6
  # placeholder until i make it work..
7
7
  # https://guides.rubygems.org/make-your-own-gem/#adding-an-executable
8
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
-
9
+ require 'yaml'
10
+ require 'socket'
11
+ require 'optparse' # http://ruby.about.com/od/advancedruby/a/optionparser.htm
39
12
 
13
+ include Storazzo
14
+ include Storazzo::Colors
40
15
 
16
+ #require_relative '../lib/storazzo'
41
17
 
18
+ puts "First I need to figure out how to bring in all the libraries in here.."
19
+ puts Storazzo::Main.hi(ARGV.join '::')
20
+ #exit(0)
21
+ ############# ############# ############# ############# ############# ############# ############# #############
42
22
 
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
23
 
49
24
  # I believe this is wrong
50
25
  #require 'storazzo'
@@ -57,10 +32,11 @@ if RUBY_VERSION.split('.')[0] == 1
57
32
  exit 2020
58
33
  end
59
34
 
60
- $PROG_VER = '0.3'
61
- $DEBUG = false
35
+ $PROG_VER = '0.4'
36
+ $DEBUG = true
62
37
 
63
38
  HISTORY = <<-BIG_LONG_MULTILINE
39
+ 2022-07-13 v0.4 Now that library has stabilized this kind of works! I can just push gem, update amd include here and work quite well :)
64
40
  2022-07-11 v0.3 Ported from private files in GIC into storazzo (open source on gitHub) and cleaned up italian and libs
65
41
  2022-07-DD v0.2 Some private stuff on GIC
66
42
  BIG_LONG_MULTILINE
@@ -88,11 +64,11 @@ $myconf = {
88
64
  Il tutto condito con un bel protobuf e un'entita che metto in Lib.
89
65
  ".strip.gsub(/^\s+/, "").gsub(/\s+$/, ""),
90
66
  # TODO move to some class default
91
- :media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
67
+ :media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
92
68
  :mount_types => %w{ vfat ntfs },
93
69
  }
94
- $stats_file = "ricdisk_stats_v11.rds"
95
- $gcs_bucket = 'palladius'
70
+ $stats_file = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
71
+ $gcs_bucket = 'TODO-CHANGE-CONFIG-palladius'
96
72
 
97
73
  # This template from scripta.rb. from 2.1.0 removed aby ric gem dependency.
98
74
  # 2022-04-26 2.1.1 Added more colors
@@ -142,26 +118,31 @@ def real_program
142
118
  puts white("Hello world from #{$myconf[:app_name]}!")
143
119
  puts "Description: '''#{white $myconf[:description] }'''"
144
120
 
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
121
+
122
+ config = RicDiskConfig.load # auto_sbrodola(ARGV)
123
+ config.iterate_through_file_list_for_disks(ARGV)
124
+
125
+ # if ARGV == [] # empty -> ALL
126
+ # dirs = RicDisk.find_active_dirs()
127
+ # dirs.each {|dir|
128
+ # RicDisk.sbrodola_ricdisk(dir)
129
+ # RicDisk.calculate_stats_files(dir) # dir is inutile
130
+ # } # TODO refactor in option sbrodola_afterwards=true. :)
131
+ # else
132
+ # deb "I consider ARGV come la lista di directories da parsare :)"
133
+ # dirs = RicDisk.find_active_dirs()
134
+ # ARGV.each{ |dir|
135
+ # dir = File.expand_path(dir)
136
+ # if dirs.include?(dir)
137
+ # deb "Legit dir: #{green dir}"
138
+ # RicDisk.sbrodola_ricdisk(dir)
139
+ # RicDisk.calculate_stats_files(dir) # dir is inutile
140
+ # else
141
+ # deb "Figghiu ri buttana: doesnt exist #{red dir}"
142
+ # end
143
+ # }
144
+ # end #/if aRGV
145
+
165
146
  end
166
147
 
167
148
  def main(filename)
@@ -6,7 +6,7 @@ module Storazzo
6
6
  end
7
7
 
8
8
  module Storazzo::Colors
9
- #class Storazzo::Colors1
9
+
10
10
  PREPEND_ME = "[Storazzo::Colors] "
11
11
 
12
12
  def deb(s); puts "#DEB #{gray(s)}" if $DEBUG; end
@@ -0,0 +1,12 @@
1
+ # Ric common stuff! :)
2
+
3
+
4
+ module Storazzo::Common
5
+
6
+
7
+ def deb(str)
8
+ puts "[DEB] #{str}"
9
+ end
10
+
11
+
12
+ end
data/lib/storazzo/main.rb CHANGED
@@ -3,6 +3,17 @@
3
3
  # eg from RicDisk.
4
4
 
5
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
+
6
17
  class Storazzo::Main # Can be same name as Module: https://stackoverflow.com/questions/13261474/ruby-modules-and-classes-same-name-in-structure
7
18
  require 'storazzo/colors'
8
19
  extend Storazzo::Colors
@@ -16,12 +27,24 @@ module Storazzo
16
27
  end
17
28
 
18
29
  def self.all_mounts(opts={})
19
- extend Storazzo::RicDisk
20
30
  opts_verbose = opts.fetch :verbose, true
21
31
 
32
+ self.hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDiskUgly::RICDISK_VERSION}"
33
+
34
+ pwhite("1. First I load the config in verbose mode..")
35
+ config = Storazzo::RicDiskConfig.instance
36
+ config.load
37
+ # puts config.object_id
38
+ # puts Storazzo::RicDiskConfig.instance.object_id
22
39
  pwhite "TODO(ricc): show a list of all RicDisk relevant mounts" if opts_verbose
40
+ #d = Storazzo::RicDisk.new
41
+ config.iterate_through_file_list_for_disks() # analyze_local_system
23
42
  #sbrodola_ricdisk("/Volumes/")
24
- sbrodola_ricdisk(StorazzoMod::root + "./var/disks/") rescue "[Storazzo::AllMount] SomeError: #{$!}"
43
+ Storazzo::RicDisk.test
44
+ Storazzo::RicDisk.find_active_dirs
45
+ #Storazzo::RicDisk.sbrodola_ricdisk StorazzoMod::root + "./var/disks/"
46
+ #sbrodola_ricdisk(StorazzoMod::root + "./var/disks/") rescue "[Storazzo::AllMount] SomeError: #{$!}"
47
+ self.hi 'Storazzo::Main.all_mounts(): END'
25
48
  end
26
49
 
27
50
  def self.all_tests
@@ -30,9 +53,8 @@ module Storazzo
30
53
  #include Storazzo::Colors
31
54
  extend Storazzo::Colors
32
55
 
33
- pwhite "All tests BEGIN"
56
+ pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
34
57
  deb "Maybe debug is enabled?"
35
- #puts "This is Storazzo v#{StorazzoMod::VERSION}"
36
58
  hi
37
59
  # This works with EXTEND..
38
60
  puts(yellow "Just YELLOW 0")
@@ -1,93 +1,185 @@
1
-
1
+ # A RicDisk wraps a local mount/disk/folder
2
+ # it's considered interesting if there's a ".ricdisk/.ricdisk"
2
3
 
3
4
  module Storazzo
4
5
  class Storazzo::RicDisk
5
- RICDISK_VERSION = "1.0"
6
+
6
7
  include Hashify
7
8
  extend Storazzo::Colors
8
-
9
- # todo substitute wqith protobuf..
10
- attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr
11
-
12
- def self.interesting_mount_points(opts={})
13
- #https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
14
- `mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '`.split(/\n+/)
15
- end
16
-
17
- def initialize(path, ricdisk_file)
9
+
10
+
11
+ ## Instance variables
12
+
13
+ # in order of finding, so the first will be the one we actually READ and use. I could looknat the date but cmon...
14
+ @@config_files = %W{ ricdisk.yaml .ricdisk }
15
+ @@ricdisk_version = '2.0'
16
+ @@default_gemfile_test_disks_folder = Storazzo.root + "/var/test/disks/"
17
+ # Immutable
18
+ DEFAULT_MEDIA_FOLDERS = %w{
19
+ /Volumes/
20
+ /mnt/
21
+ }.append(@@default_gemfile_test_disks_folder ).append("/media/#{ENV["USER"]}/" )
22
+
23
+ # # todo substitute with protobuf..
24
+ attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
25
+
26
+
27
+ ################################
28
+ ## INSTANCE methods
29
+ ################################
30
+
31
+
32
+ def initialize(path, opts={})
33
+ puts "[DEB] RicDisk initialize.. path=#{path}"
18
34
  @local_mountpoint = path
19
- @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}'"
20
- @ricdisk_version = VERSION
21
- @ricdisk_file = ricdisk_file
22
- #@questo_non_esiste = :sobenme
35
+ @description = "This is an automated RicDisk description from v.#{@@ricdisk_version}. Created on #{Time.now}'"
36
+ @ricdisk_version = @@ricdisk_version
37
+ #@ricdisk_file = ricdisk_file
38
+ @ricdisk_file = RicDisk.get_ricdisk_file(path)
39
+ @ricdisk_file_empty = ricdisk_file_empty?
23
40
  @label = path.split("/").last
24
41
  @name = path.split("/").last
25
- @wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
26
- @tags = 'ricdisk'
27
- find_info_from_mount(path)
28
- find_info_from_df()
42
+ #@wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
43
+ @tags = ['ricdisk', 'storazzo']
44
+ @size = `du -s '#{path}'`.split(/\s/)[0] # self.size
45
+ puts :beleza
46
+ # @config = RicDiskConfig.instance.get_config
47
+ # #puts @config if @config
48
+ # find_info_from_mount(path)
49
+ # find_info_from_df()
29
50
  end
30
-
31
- def ricdisk_absolute_path
32
- @local_mountpoint + "/" + @ricdisk_file
51
+
52
+ def ricdisk_file_empty?()
53
+ File.empty?( "#{local_mountpoint}/#.ricdisk.yaml")
33
54
  end
34
-
35
- def add_tag(tag)
36
- @tags += ", #{tag}"
55
+
56
+ def ok_dir?
57
+ not @ricdisk_file.nil?
37
58
  end
59
+
60
+
61
+ def analyze_local_system()
62
+ puts :TODO
63
+ puts "1. Interesting Mounts: #{green interesting_mount_points}"
64
+ puts "2. Sbrodoling everything: :TODO"
65
+ # find_info_from_mount(path)
66
+ # find_info_from_df()
67
+ end
68
+
69
+ def path
70
+ local_mountpoint
71
+ end
72
+
73
+ def to_s
74
+ "RicDisk(paz=#{path}, writeable=#{writeable?}, size=#{size}B)"
75
+ end
76
+
77
+ # could take long..
78
+ # def size
79
+ # `du -s '#{path}'`.split(/\s/)[0]
80
+ # end
81
+
82
+ def writeable?()
83
+ :boh
84
+ end
85
+
86
+ ################################
87
+ ## CLASS methods
88
+ ################################
89
+
90
+
91
+ # All places where to find for something :)
92
+ def self.default_media_folders
93
+ DEFAULT_MEDIA_FOLDERS
94
+ end
95
+
96
+
97
+ def self.test # _localgem_disks
98
+ d = RicDisk.new( @@default_gemfile_test_disks_folder)
99
+ puts (d)
100
+ puts "do something with it: #{d}"
101
+ #d.find_active_dirs()
102
+ end
103
+
104
+
105
+
106
+
38
107
 
39
- # might have other things in the future...
40
- def find_info_from_mount(path)
41
- mount_table_lines = interesting_mount_points()
42
- mount_line = nil
43
- mount_table_lines.each do |line|
44
- next if line =~ /^map /
45
- dev, on, mount_path, mode = line.split(/ /)
46
- if mount_path==path
47
- mount_line = line
48
- else
49
- @info_from_mount = false
50
- end
108
+ def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
109
+ if base_dirs.nil?
110
+ base_dirs = default_media_folders
111
+ puts "find_active_dirs with empty input -> using default_media_folders: #{yellow default_media_folders}"
51
112
  end
52
- @info_from_mount = ! (mount_line.nil?)
53
- if @info_from_mount
54
- #@mount_line = mount_line
55
- @description += "\nMount line:\n" + mount_line
56
- @remote_mountpoint = mount_line.split(/ /)[0]
57
- @fstype = mount_line.split(/ /)[3].gsub(/[\(,]/, '')
58
- add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
113
+ active_dirs = []
114
+ base_dirs.each do |ugly_dir|
115
+ # 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
116
+ dir = File.expand_path(ugly_dir)
117
+ begin
118
+ x=[]
119
+ # puts "TEST2 DIR EXISTS: #{dir} -> #{Dir.exists?(dir)}"
120
+ unless Dir.exists?(dir)
121
+ deb "Dir doesnt exist, skipping: #{dir}"
122
+ next
123
+ end
124
+ Dir.chdir(dir)
125
+ x = Dir.glob('*').select {|f| File.directory? f}
126
+ subdirs = x.map{|subdir| "#{dir}#{subdir}"}
127
+ subdirs.each{|subdir|
128
+ #puts `ls -al "#{subdir}"`
129
+ active_dirs << subdir if ok_dir? # self.ok_dir?(subdir)
130
+ }
131
+ #puts(white x)
132
+ rescue Exception => e # optionally: `rescue Exception => ex`
133
+ puts "Exception: '#{e}'"
134
+ ensure # will always get executed
135
+ #deb 'Always gets executed.'
136
+ #x = []
137
+ end
59
138
  end
60
139
  end
61
-
62
- def find_info_from_df()
63
- path = @local_mountpoint
64
- df_info = `df -h "#{path}"`
65
- @df_info = df_info
66
- lines = df_info.split(/\n+/)
67
- raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
68
- mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
140
+
141
+
142
+ # new
143
+ def self.get_ricdisk_file(path)
144
+ puts "RICC_WARNING TODO use @@config_files instead"
145
+ return ".ricdisk.yaml" if File.exist?("#{path}/.ricdisk.yaml") #and File.empty?( "#{path}/.ricdisk.yaml")
146
+ return ".ricdisk" if File.exist?("#{path}/.ricdisk") # and File.empty?( "#{path}/.ricdisk")
147
+ return nil
69
148
  end
149
+
70
150
 
71
-
72
-
73
- def self.sbrodola_ricdisk(subdir)
151
+ def self.interesting_mount_points(opts={})
152
+ #https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
153
+ `mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '`.split(/\n+/)
154
+ end
155
+
156
+ # maybe move to a RiccFile class? Maybe even INHERIT from FILE?
157
+ def self.obsolescence_seconds file_path
158
+ creation_time = File.stat(file_path).ctime
159
+ deb("[obsolescence_seconds] File #{file_path}: #{creation_time} - #{(Time.now - creation_time)} seconds ago")
160
+ (Time.now - creation_time).to_i
161
+ end
162
+ # maybe move to a RiccFile class? Maybe even INHERIT from FILE?
163
+ def self.obsolescence_days(file_path)
164
+ return obsolescence_seconds(file_path) / 86400
165
+ end
166
+
167
+
168
+ # FORMER SBRODOLA, now write_config_yaml_to_disk
169
+ def self.write_config_yaml_to_disk(subdir) # sbrodola_ricdisk(subdir)
74
170
  # given a path, if .ricdisk exists i do stuff with it..
75
171
  disk_info = nil
76
172
  unless self.ok_dir?(subdir)
77
- puts("Nothing for me here. Existing")
173
+ puts("Nothing for me here: '#{subdir}'. Existing")
78
174
  return
79
175
  end
80
176
  if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
81
177
  deb("Interesting1. Empty file! Now I write YAML with it.")
82
178
  disk_info = RicDisk.new(subdir, '.ricdisk')
83
- #puts(x)
84
- #puts(yellow x.to_yaml)
85
179
  end
86
180
  if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
87
181
  deb("Interesting2. Empty file! TODO write YAML with it.")
88
182
  disk_info = RicDisk.new(subdir, '.ricdisk.yaml')
89
- # todo write
90
- #puts(x)
91
183
  puts(yellow disk_info.to_yaml)
92
184
  end
93
185
  if disk_info
@@ -105,50 +197,22 @@ module Storazzo
105
197
  #puts(white `cat "#{subdir}/.ricdisk"`)
106
198
  end
107
199
  end
108
-
109
- # separiamo cosi usiamo meglio...
200
+
201
+ # TODO obsolete this as i should NOT be calling it from clas, but from method.
110
202
  def self.ok_dir?(subdir)
111
203
  File.exists?( "#{subdir}/.ricdisk") or File.exists?( "#{subdir}/.ricdisk.yaml")
112
204
  end
113
205
 
114
- def self.obsolescence_seconds file_path
115
- creation_time = File.stat(file_path).ctime
116
- deb("[obsolescence_seconds] File #{file_path}: #{creation_time} - #{(Time.now - creation_time)} seconds ago")
117
- (Time.now - creation_time).to_i
118
- end
119
- def self.obsolescence_days(file_path)
120
- return obsolescence_seconds(file_path) / 86400
121
- end
122
-
123
- def self.backquote_execute(cmd)
124
- # executed a command wrapped by dryrun though
125
- return "DRYRUN backquote_execute(#{cmd})" if $opts[:dryrun]
126
- `#{cmd}`
127
- end
128
-
129
- def self.upload_to_gcs(file, opts={})
130
- deb("upload_to_gcs(#{file}). TODO(ricc) after breafast upload to GCS : #{file}")
131
- mount_name = file.split('/')[-2]
132
- filename = "#{mount_name}-#{File.basename file}"
133
- hostname = Socket.gethostname[/^[^.]+/]
134
- command = "gsutil cp '#{file}' gs://#{$gcs_bucket}/backup/ricdisk-magic/#{ hostname }-#{filename}"
135
- deb("Command: #{command}")
136
- ret = backquote_execute(command)
137
- # if $opts[:debug] do
138
- # puts "+ Current list of files:"
139
- # ret = backquote_execute("gsutil ls -al gs://#{$gcs_bucket}/backup/ricdisk-magic/")
140
- # puts ret
141
- # end
142
- ret
143
- end
144
-
206
+
207
+
145
208
  # Create RDS file.
146
209
  def self.calculate_stats_files(dir, opts={})
147
210
  opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
148
211
  full_file_path = "#{dir}/#{$stats_file}"
212
+ return "This refacgtor is for another day"
149
213
 
150
214
  puts("calculate_stats_files(#{white dir}): #{white full_file_path}")
151
- puts "TEST1 DIR EXISTS: #{dir} -> #{Dir.directory? dir}"
215
+ puts "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
152
216
  Dir.chdir(dir)
153
217
  if File.exists?(full_file_path) and ($opts[:force] == false)
154
218
  puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
@@ -167,66 +231,128 @@ module Storazzo
167
231
  end
168
232
  end
169
233
 
170
- def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
171
- base_dirs = $myconf[:media_dirs] if base_dirs.nil?
172
- active_dirs = []
173
- base_dirs.each do |ugly_dir|
174
- # 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
175
- dir = File.expand_path(ugly_dir)
176
- begin
177
- x=[]
178
- # puts "TEST2 DIR EXISTS: #{dir} -> #{Dir.exists?(dir)}"
179
- unless Dir.exists?(dir)
180
- deb "Dir doesnt exist, skipping: #{dir}"
181
- next
182
- end
183
- Dir.chdir(dir)
184
- x = Dir.glob('*').select {|f| File.directory? f}
185
- subdirs = x.map{|subdir| "#{dir}#{subdir}"}
186
- subdirs.each{|subdir|
187
- #puts `ls -al "#{subdir}"`
188
- active_dirs << subdir if self.ok_dir?(subdir)
189
- }
190
- #puts(white x)
191
- rescue Exception => e # optionally: `rescue Exception => ex`
192
- puts "Exception: '#{e}'"
193
- ensure # will always get executed
194
- #deb 'Always gets executed.'
195
- #x = []
196
- end
197
- end
198
-
199
- if also_mountpoints
200
- =begin
201
- Example output from mount:
202
-
203
- devfs on /dev (devfs, local, nobrowse)
204
- /dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
205
- /dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
206
- /dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
207
- /dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
208
- /dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
209
- /dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
210
- /dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
211
- map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
212
- //riccardo@1.0.1.10/video on /Volumes/video (afpfs, nodev, nosuid, mounted by ricc)
213
- //riccardo@1.0.1.10/photo on /Volumes/photo (afpfs, nodev, nosuid, mounted by ricc)
214
- =end
215
- # add directories from current mountpoints...
216
- mount_table_lines = interesting_mount_points()
217
- mount_table_lines.each{|line|
218
- next if line =~ /^map /
219
- dev, on, path, mode = line.split(/ /)
220
- #puts line
221
- #deb yellow(path)
222
- active_dirs << path if self.ok_dir?(path)
223
- }
224
- end
225
- active_dirs.uniq!
226
- puts("find_active_dirs(): found dirs " + green(active_dirs))
227
- return active_dirs
228
- end
234
+ # if also_mountpoints
235
+ # =begin
236
+ # Example output from mount:
237
+
238
+ # devfs on /dev (devfs, local, nobrowse)
239
+ # /dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
240
+ # /dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
241
+ # /dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
242
+ # /dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
243
+ # /dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
244
+ # /dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
245
+ # /dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
246
+ # map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
247
+ # //riccardo@1.0.1.10/video on /Volumes/video (afpfs, nodev, nosuid, mounted by ricc)
248
+ # //riccardo@1.0.1.10/photo on /Volumes/photo (afpfs, nodev, nosuid, mounted by ricc)
249
+ # =end
250
+ # # add directories from current mountpoints...
251
+ # mount_table_lines = interesting_mount_points()
252
+ # mount_table_lines.each{|line|
253
+ # next if line =~ /^map /
254
+ # dev, on, path, mode = line.split(/ /)
255
+ # #puts line
256
+ # #deb yellow(path)
257
+ # active_dirs << path if self.ok_dir?(path)
258
+ # }
259
+ # end
260
+ # active_dirs.uniq!
261
+ # puts("find_active_dirs(): found dirs " + green(active_dirs))
262
+ # return active_dirs
263
+ # end
229
264
 
265
+
266
+
267
+ end #/Class
268
+ end #/Module
269
+
270
+
271
+
272
+
273
+
274
+ # def initialize(path, ricdisk_file)
275
+ # puts "[DEB] RicDisk initialize.. path=#{path}"
276
+ # @local_mountpoint = path
277
+ # @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}'"
278
+ # @ricdisk_version = VERSION
279
+ # @ricdisk_file = ricdisk_file
280
+ # #@questo_non_esiste = :sobenme
281
+ # @label = path.split("/").last
282
+ # @name = path.split("/").last
283
+ # @wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
284
+ # @tags = 'ricdisk'
285
+ # puts :beleza
286
+ # @config = RicDiskConfig.instance.get_config
287
+ # #puts @config if @config
288
+ # find_info_from_mount(path)
289
+ # find_info_from_df()
290
+ # end
291
+
292
+ # def ricdisk_absolute_path
293
+ # @local_mountpoint + "/" + @ricdisk_file
294
+ # end
230
295
 
231
- end
232
- end
296
+ # def add_tag(tag)
297
+ # @tags += ", #{tag}"
298
+ # end
299
+
300
+ # # might have other things in the future...
301
+ # def find_info_from_mount(path)
302
+ # mount_table_lines = interesting_mount_points()
303
+ # mount_line = nil
304
+ # mount_table_lines.each do |line|
305
+ # next if line =~ /^map /
306
+ # dev, on, mount_path, mode = line.split(/ /)
307
+ # if mount_path==path
308
+ # mount_line = line
309
+ # else
310
+ # @info_from_mount = false
311
+ # end
312
+ # end
313
+ # @info_from_mount = ! (mount_line.nil?)
314
+ # if @info_from_mount
315
+ # #@mount_line = mount_line
316
+ # @description += "\nMount line:\n" + mount_line
317
+ # @remote_mountpoint = mount_line.split(/ /)[0]
318
+ # @fstype = mount_line.split(/ /)[3].gsub(/[\(,]/, '')
319
+ # add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
320
+ # end
321
+ # end
322
+
323
+ # def find_info_from_df()
324
+ # path = @local_mountpoint
325
+ # df_info = `df -h "#{path}"`
326
+ # @df_info = df_info
327
+ # lines = df_info.split(/\n+/)
328
+ # raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
329
+ # mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
330
+ # end
331
+
332
+
333
+
334
+
335
+
336
+
337
+ # def self.backquote_execute(cmd)
338
+ # # executed a command wrapped by dryrun though
339
+ # return "DRYRUN backquote_execute(#{cmd})" if $opts[:dryrun]
340
+ # `#{cmd}`
341
+ # end
342
+
343
+ # def self.upload_to_gcs(file, opts={})
344
+ # deb("upload_to_gcs(#{file}). TODO(ricc) after breafast upload to GCS : #{file}")
345
+ # mount_name = file.split('/')[-2]
346
+ # filename = "#{mount_name}-#{File.basename file}"
347
+ # hostname = Socket.gethostname[/^[^.]+/]
348
+ # command = "gsutil cp '#{file}' gs://#{$gcs_bucket}/backup/ricdisk-magic/#{ hostname }-#{filename}"
349
+ # deb("Command: #{command}")
350
+ # ret = backquote_execute(command)
351
+ # # if $opts[:debug] do
352
+ # # puts "+ Current list of files:"
353
+ # # ret = backquote_execute("gsutil ls -al gs://#{$gcs_bucket}/backup/ricdisk-magic/")
354
+ # # puts ret
355
+ # # end
356
+ # ret
357
+ # end
358
+
@@ -0,0 +1,94 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+
4
+ module Storazzo
5
+ class Storazzo::RicDiskConfig
6
+ include Singleton
7
+ include Storazzo::Common
8
+ include Storazzo::Colors
9
+
10
+ @@default_config_location = "~/.storazzo.yaml"
11
+ attr_accessor :config, :config_file
12
+
13
+ public
14
+ def load(config_path=nil, opts={})
15
+ verbose = opts.fetch :verbose, false
16
+
17
+ puts "[VERBOSE] Storazzo::RicDiskConfig.load(): BEGIN " if verbose
18
+ # trying default location
19
+ possible_locations = [ @@default_config_location , "./.storazzo.yaml"]
20
+ if config_path
21
+ possible_locations =possible_locations.append(config_path)
22
+ end
23
+ puts "[VERBOSE] Searching these paths in order: #{possible_locations}" if verbose
24
+ possible_locations.each do |possible_path|
25
+ paz = File.expand_path(possible_path)
26
+ #puts "DEB paz:#{paz}"
27
+ if File.exists?(paz)
28
+ @config_file = paz
29
+ @config = YAML.load(File.read paz) # YAML.load(File.read("file_path"))
30
+ #pp @config if verbose
31
+ #config_ver = @config[:ConfigVersion]
32
+ #puts @config[:ConfigVersion]
33
+ puts "Storazzo::RicDiskConfig v#{config_ver} parsed correctly"
34
+ puts "RicDiskConfig.to_s: #{self}" if verbose
35
+ return self.config
36
+ end
37
+ end
38
+ # only get here if nothing is found
39
+ raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}"
40
+ # @config = 42
41
+ # puts "[VERBOSE] Storazzo::RicDiskConfig.load(): END " if verbose
42
+ end
43
+
44
+ def config_ver
45
+ #self.
46
+ @config['ConfigVersion']
47
+ end
48
+ def config_default_folder
49
+ #self.
50
+ @config['Config']['DefaultFolder'] #rescue "Unknown config_default_folder: #{$!}"
51
+ end
52
+
53
+ def to_s
54
+ size = File.size @config_file
55
+ "RicDiskConfig(v#{config_ver}, file=#{ @config_file}) with #{size} bytes" # - config_default_folder=#{self.config_default_folder}"
56
+ end
57
+
58
+ def get_config(opts={})
59
+ return load(opts) if @config.nil?
60
+ @config
61
+ end
62
+
63
+ def self.gem_default_config_path
64
+ Storazzo.root + "/etc/storazzo_config.sample.yaml"
65
+ end
66
+
67
+ # UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
68
+ def iterate_through_file_list_for_disks(files_list=[])
69
+ if files_list == [] # or files_list.nil? # empty -> ALL
70
+ deb "iterate_through_file_list_for_disks(): no args provided"
71
+ dirs = RicDisk.find_active_dirs()
72
+ puts "DEB find_active_dirs: #{green dirs}"
73
+ dirs.each {|dir|
74
+ RicDisk.write_config_yaml_to_disk(dir)
75
+ RicDisk.calculate_stats_files(dir) # dir is inutile
76
+ } # TODO refactor in option sbrodola_afterwards=true. :)
77
+ else
78
+ deb "iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)"
79
+ dirs = RicDisk.find_active_dirs()
80
+ files_list.each do |dir|
81
+ dir = File.expand_path(dir)
82
+ if dirs.include?(dir)
83
+ deb "Legit dir: #{green dir}"
84
+ RicDisk.write_config_yaml_to_disk(dir)
85
+ RicDisk.calculate_stats_files(dir) # dir is inutile
86
+ else
87
+ deb "Figghiu ri buttana: doesnt exist #{red dir}"
88
+ end
89
+ end
90
+ end
91
+ end #/iterate_through_file_list_for_disks
92
+
93
+ end
94
+ end
@@ -0,0 +1,10 @@
1
+ # This class wraps the RDS file: we're going to write this RDS file
2
+ # directly in the disk: /mount/
3
+ module Storazzo
4
+ class Storazzo::RicDiskStatsFile
5
+ @@default_name = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
6
+
7
+
8
+
9
+ end
10
+ end
@@ -0,0 +1,251 @@
1
+
2
+
3
+ module Storazzo
4
+ class Storazzo::RicDiskUgly
5
+ RICDISK_VERSION = "1.0ugly"
6
+ DEFAULT_MEDIA_DIRS = %w{
7
+ /media/riccardo/
8
+ /Volumes/
9
+ /mnt/
10
+ ~/storazzo/var/test/disks/
11
+ }.append(Storazzo.root + "/var/test/disks/")
12
+
13
+ include Hashify
14
+ extend Storazzo::Colors
15
+
16
+ # todo substitute with protobuf..
17
+ attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr
18
+
19
+ def self.interesting_mount_points(opts={})
20
+ #https://unix.stackexchange.com/questions/177014/showing-only-interesting-mount-points-filtering-non-interesting-types
21
+ `mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '`.split(/\n+/)
22
+ end
23
+
24
+ def initialize(path, ricdisk_file)
25
+ puts "[DEB] RicDiskUgly initialize.. path=#{path}"
26
+ @local_mountpoint = path
27
+ @description = "This is an automated RicDiskUgly description from v.#{VERSION}. Riccardo feel free to edit away with characteristicshs of this device.. Created on #{Time.now}'"
28
+ @ricdisk_version = VERSION
29
+ @ricdisk_file = ricdisk_file
30
+ #@questo_non_esiste = :sobenme
31
+ @label = path.split("/").last
32
+ @name = path.split("/").last
33
+ @wr = File.writable?("#{path}/#{ricdisk_file}" ) # .writeable?
34
+ @tags = 'ricdisk'
35
+ puts :beleza
36
+ @config = RicDiskConfig.instance.get_config
37
+ #puts @config if @config
38
+ find_info_from_mount(path)
39
+ find_info_from_df()
40
+ end
41
+
42
+ def ricdisk_absolute_path
43
+ @local_mountpoint + "/" + @ricdisk_file
44
+ end
45
+
46
+ def add_tag(tag)
47
+ @tags += ", #{tag}"
48
+ end
49
+
50
+ # might have other things in the future...
51
+ def find_info_from_mount(path)
52
+ mount_table_lines = interesting_mount_points()
53
+ mount_line = nil
54
+ mount_table_lines.each do |line|
55
+ next if line =~ /^map /
56
+ dev, on, mount_path, mode = line.split(/ /)
57
+ if mount_path==path
58
+ mount_line = line
59
+ else
60
+ @info_from_mount = false
61
+ end
62
+ end
63
+ @info_from_mount = ! (mount_line.nil?)
64
+ if @info_from_mount
65
+ #@mount_line = mount_line
66
+ @description += "\nMount line:\n" + mount_line
67
+ @remote_mountpoint = mount_line.split(/ /)[0]
68
+ @fstype = mount_line.split(/ /)[3].gsub(/[\(,]/, '')
69
+ add_tag(:synology) if @remote_mountpoint.match('1.0.1.10')
70
+ end
71
+ end
72
+
73
+ def find_info_from_df()
74
+ path = @local_mountpoint
75
+ df_info = `df -h "#{path}"`
76
+ @df_info = df_info
77
+ lines = df_info.split(/\n+/)
78
+ raise "I need exactly TWO lines! Or no info is served here..." unless lines.size == 2
79
+ mount, @size_readable, used_size, avail_size, @disk_utilization, other = lines[1].split(/\s+/) # second line..
80
+ end
81
+
82
+
83
+
84
+ def self.sbrodola_ricdisk(subdir)
85
+ # given a path, if .ricdisk exists i do stuff with it..
86
+ disk_info = nil
87
+ unless self.ok_dir?(subdir)
88
+ puts("Nothing for me here. Existing")
89
+ return
90
+ end
91
+ if File.exists?( "#{subdir}/.ricdisk") and File.empty?( "#{subdir}/.ricdisk")
92
+ deb("Interesting1. Empty file! Now I write YAML with it.")
93
+ disk_info = RicDiskUgly.new(subdir, '.ricdisk')
94
+ #puts(x)
95
+ #puts(yellow x.to_yaml)
96
+ end
97
+ if File.exists?( "#{subdir}/.ricdisk.yaml") and File.empty?( "#{subdir}/.ricdisk.yaml")
98
+ deb("Interesting2. Empty file! TODO write YAML with it.")
99
+ disk_info = RicDiskUgly.new(subdir, '.ricdisk.yaml')
100
+ # todo write
101
+ #puts(x)
102
+ puts(yellow disk_info.to_yaml)
103
+ end
104
+ if disk_info
105
+ if File.empty?(disk_info.ricdisk_absolute_path) and (disk_info.wr)
106
+ 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.."))
107
+ ret = File.write(disk_info.ricdisk_absolute_path, disk_info.to_yaml)
108
+ puts("Written file! ret=#{ret}")
109
+ else
110
+ puts(red("Nope, qualcosa non va.. #{File.empty?(disk_info.ricdisk_absolute_path)}"))
111
+ puts("File size: #{File.size(disk_info.ricdisk_absolute_path)}")
112
+ end
113
+ end
114
+ if File.exists?( "#{subdir}/.ricdisk") and ! File.empty?( "#{subdir}/.ricdisk")
115
+ puts("Config File found with old-style name: '#{subdir}/.ricdisk' !")
116
+ #puts(white `cat "#{subdir}/.ricdisk"`)
117
+ end
118
+ end
119
+
120
+ # separiamo cosi usiamo meglio...
121
+ def self.ok_dir?(subdir)
122
+ File.exists?( "#{subdir}/.ricdisk") or File.exists?( "#{subdir}/.ricdisk.yaml")
123
+ end
124
+
125
+ def self.obsolescence_seconds file_path
126
+ creation_time = File.stat(file_path).ctime
127
+ deb("[obsolescence_seconds] File #{file_path}: #{creation_time} - #{(Time.now - creation_time)} seconds ago")
128
+ (Time.now - creation_time).to_i
129
+ end
130
+ def self.obsolescence_days(file_path)
131
+ return obsolescence_seconds(file_path) / 86400
132
+ end
133
+
134
+ def self.backquote_execute(cmd)
135
+ # executed a command wrapped by dryrun though
136
+ return "DRYRUN backquote_execute(#{cmd})" if $opts[:dryrun]
137
+ `#{cmd}`
138
+ end
139
+
140
+ def self.upload_to_gcs(file, opts={})
141
+ deb("upload_to_gcs(#{file}). TODO(ricc) after breafast upload to GCS : #{file}")
142
+ mount_name = file.split('/')[-2]
143
+ filename = "#{mount_name}-#{File.basename file}"
144
+ hostname = Socket.gethostname[/^[^.]+/]
145
+ command = "gsutil cp '#{file}' gs://#{$gcs_bucket}/backup/ricdisk-magic/#{ hostname }-#{filename}"
146
+ deb("Command: #{command}")
147
+ ret = backquote_execute(command)
148
+ # if $opts[:debug] do
149
+ # puts "+ Current list of files:"
150
+ # ret = backquote_execute("gsutil ls -al gs://#{$gcs_bucket}/backup/ricdisk-magic/")
151
+ # puts ret
152
+ # end
153
+ ret
154
+ end
155
+
156
+ # Create RDS file.
157
+ def self.calculate_stats_files(dir, opts={})
158
+ opts_upload_to_gcs = opts.fetch :upload_to_gcs, true
159
+ full_file_path = "#{dir}/#{$stats_file}"
160
+
161
+ puts("calculate_stats_files(#{white dir}): #{white full_file_path}")
162
+ puts "TEST1 DIR EXISTS: #{dir} -> #{File.directory? dir}"
163
+ Dir.chdir(dir)
164
+ if File.exists?(full_file_path) and ($opts[:force] == false)
165
+ puts "File '#{$stats_file}' exists already." # - now should see if its too old, like more than 1 week old"
166
+ # TODO check for file time...
167
+ print "Lines found: #{yellow `wc -l "#{full_file_path}" `.chomp }. File obsolescence (days): #{yellow obsolescence_days(full_file_path)}."
168
+ if obsolescence_days(full_file_path) > 7
169
+ puts("*** ACHTUNG *** FIle is pretty old. You might consider rotating: #{yellow "mv #{full_file_path} #{full_file_path}_old"}. Or invoke with --force")
170
+ end
171
+ upload_to_gcs(full_file_path) if opts_upload_to_gcs
172
+ else
173
+ puts "Crunching data stats from '#{dir}' into '#{$stats_file}' ... please bear with me.. [maybe file didnt exist, maybe $opts[:force] is true]"
174
+ command = "find . -print0 | xargs -0 stats-with-md5.rb --no-color | tee '#{full_file_path}'"
175
+ puts("[#{`pwd`.chomp}] Executing: #{azure command}")
176
+ ret = backquote_execute command
177
+ puts "Done. #{ret.split("\n").count} files processed."
178
+ end
179
+ end
180
+
181
+ def self.find_active_dirs(base_dirs=nil, also_mountpoints=true)
182
+ base_dirs = DEFAULT_MEDIA_DIRS if base_dirs.nil?
183
+ active_dirs = []
184
+ base_dirs.each do |ugly_dir|
185
+ # 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
186
+ dir = File.expand_path(ugly_dir)
187
+ begin
188
+ x=[]
189
+ # puts "TEST2 DIR EXISTS: #{dir} -> #{Dir.exists?(dir)}"
190
+ unless Dir.exists?(dir)
191
+ deb "Dir doesnt exist, skipping: #{dir}"
192
+ next
193
+ end
194
+ Dir.chdir(dir)
195
+ x = Dir.glob('*').select {|f| File.directory? f}
196
+ subdirs = x.map{|subdir| "#{dir}#{subdir}"}
197
+ subdirs.each{|subdir|
198
+ #puts `ls -al "#{subdir}"`
199
+ active_dirs << subdir if self.ok_dir?(subdir)
200
+ }
201
+ #puts(white x)
202
+ rescue Exception => e # optionally: `rescue Exception => ex`
203
+ puts "Exception: '#{e}'"
204
+ ensure # will always get executed
205
+ #deb 'Always gets executed.'
206
+ #x = []
207
+ end
208
+ end
209
+
210
+ if also_mountpoints
211
+ =begin
212
+ Example output from mount:
213
+
214
+ devfs on /dev (devfs, local, nobrowse)
215
+ /dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
216
+ /dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
217
+ /dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
218
+ /dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
219
+ /dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
220
+ /dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
221
+ /dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
222
+ map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
223
+ //riccardo@1.0.1.10/video on /Volumes/video (afpfs, nodev, nosuid, mounted by ricc)
224
+ //riccardo@1.0.1.10/photo on /Volumes/photo (afpfs, nodev, nosuid, mounted by ricc)
225
+ =end
226
+ # add directories from current mountpoints...
227
+ mount_table_lines = interesting_mount_points()
228
+ mount_table_lines.each{|line|
229
+ next if line =~ /^map /
230
+ dev, on, path, mode = line.split(/ /)
231
+ #puts line
232
+ #deb yellow(path)
233
+ active_dirs << path if self.ok_dir?(path)
234
+ }
235
+ end
236
+ active_dirs.uniq!
237
+ puts("find_active_dirs(): found dirs " + green(active_dirs))
238
+ return active_dirs
239
+ end
240
+
241
+
242
+ def analyze_local_system()
243
+ puts :TODO
244
+ puts "1. Interesting Mounts: #{green interesting_mount_points}"
245
+ puts "2. Sbrodoling everything: :TODO"
246
+ # find_info_from_mount(path)
247
+ # find_info_from_df()
248
+ end
249
+
250
+ end
251
+ end
data/lib/storazzo.rb CHANGED
@@ -16,13 +16,25 @@ module Storazzo
16
16
  end
17
17
 
18
18
  def self.version
19
- File.read('./VERSION').chomp # "10.0.0"
19
+ File.read(self.root + '/VERSION').chomp # "10.0.0"
20
+ end
21
+
22
+ # alias_method :VERSION, :version
23
+ def self.VERSION
24
+ version
20
25
  end
21
26
  end
22
27
 
28
+ # nice to paste nice output
29
+ require 'pp'
30
+
31
+ require 'storazzo/common'
23
32
  require 'storazzo/colors'
24
33
  require 'storazzo/hashify'
25
- require 'storazzo/ric_disk'
34
+ require 'storazzo/ric_disk' # NEW and will build from ground up using multiple files..
35
+ require 'storazzo/ric_disk_ugly' # OLD and 90% working
36
+ require 'storazzo/ric_disk_config'
37
+ require 'storazzo/ric_disk_statsfile'
26
38
  require 'storazzo/main'
27
39
  require 'storazzo/translator'
28
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riccardo Carlesso
@@ -27,11 +27,15 @@ files:
27
27
  - bin/ricdisk-magic
28
28
  - lib/storazzo.rb
29
29
  - lib/storazzo/colors.rb
30
+ - lib/storazzo/common.rb
30
31
  - lib/storazzo/debug.rb
31
32
  - lib/storazzo/hashify.rb
32
33
  - lib/storazzo/main.rb
33
34
  - lib/storazzo/parser/parser.rb
34
35
  - lib/storazzo/ric_disk.rb
36
+ - lib/storazzo/ric_disk_config.rb
37
+ - lib/storazzo/ric_disk_statsfile.rb
38
+ - lib/storazzo/ric_disk_ugly.rb
35
39
  - lib/storazzo/translator.rb
36
40
  - lib/storazzo/version.rb
37
41
  - storazzo.gemspec