storazzo 0.0.6 โ 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/LICENSE +1 -0
- data/Makefile +46 -0
- data/README.md +19 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/bin/ricdisk-magic +152 -0
- data/lib/storazzo/colors.rb +7 -3
- data/lib/storazzo/common.rb +12 -0
- data/lib/storazzo/debug.rb +10 -0
- data/lib/storazzo/hashify.rb +33 -0
- data/lib/storazzo/main.rb +69 -0
- data/lib/storazzo/parser/parser.rb +0 -0
- data/lib/storazzo/ric_disk.rb +358 -0
- data/lib/storazzo/ric_disk_config.rb +93 -0
- data/lib/storazzo/ric_disk_statsfile.rb +10 -0
- data/lib/storazzo/ric_disk_ugly.rb +251 -0
- data/lib/storazzo/version.rb +6 -0
- data/lib/storazzo.rb +29 -30
- data/storazzo.gemspec +18 -0
- data/test/test_storazzo.rb +34 -0
- data/var/test/README.md +1 -0
- data/var/test/disks/disk02-full/fake file.touch +0 -0
- data/var/test/disks/disk02-full/ls.txt +6 -0
- metadata +34 -8
- data/bin/ricdisk-magic.rb +0 -395
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b20663eda1cb6d0a43c4391e3c50a111802c4ddbdfdfe28c0f99fd3a12af2d9f
|
4
|
+
data.tar.gz: 7efd0bf78085f676796c91f24fece24621e18477ca67d0b002536b6c13492fe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17baa0e81ee526a21bf5a4129b66d51f04db26cecb3215288fd410468a0d8212aba2f22b1163a9be89f20d4e79791e778f74f7a7d965fcbff0c67f1f7054c43e
|
7
|
+
data.tar.gz: d2d208632520d5f65bf9a0292f336271eaef1c1b88ee605222f1970d3127e47cb1229add34d310bed8af74d536a1a520b8c3dc290dc24be46037a9e740ab50ce
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# todo
|
data/Makefile
ADDED
@@ -0,0 +1,46 @@
|
|
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 4. Prove I can include local gem in irb and play around. Similarly to rails console without reload.
|
33
|
+
make irb-test
|
34
|
+
@echo 'OK: ALL TESTS PASSED. #STIKA'
|
35
|
+
|
36
|
+
# RicDisk test
|
37
|
+
mounts:
|
38
|
+
echo "Storazzo::Main.all_mounts ; nil" | irb -Ilib -rstorazzo
|
39
|
+
|
40
|
+
irb:
|
41
|
+
irb -Ilib -rstorazzo
|
42
|
+
irb-test:
|
43
|
+
./irb-test.sh
|
44
|
+
|
45
|
+
watch-test:
|
46
|
+
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.2.0
|
data/bin/ricdisk-magic
ADDED
@@ -0,0 +1,152 @@
|
|
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 'yaml'
|
10
|
+
require 'socket'
|
11
|
+
require 'optparse' # http://ruby.about.com/od/advancedruby/a/optionparser.htm
|
12
|
+
|
13
|
+
#require_relative '../lib/storazzo'
|
14
|
+
|
15
|
+
puts "First I need to figure out how to bring in all the libraries in here.."
|
16
|
+
puts Storazzo::Main.hi(ARGV[0])
|
17
|
+
exit(0)
|
18
|
+
############# ############# ############# ############# ############# ############# ############# #############
|
19
|
+
|
20
|
+
|
21
|
+
# I believe this is wrong
|
22
|
+
#require 'storazzo'
|
23
|
+
# required to have methods wiothout self.
|
24
|
+
#include 'lib/ric_disk'
|
25
|
+
#extend Storazzo::Colors
|
26
|
+
|
27
|
+
if RUBY_VERSION.split('.')[0] == 1
|
28
|
+
puts "Refusing to launch a script form Ruby 1. Sorry Ric, its 2020 damn it!"
|
29
|
+
exit 2020
|
30
|
+
end
|
31
|
+
|
32
|
+
$PROG_VER = '0.3'
|
33
|
+
$DEBUG = false
|
34
|
+
|
35
|
+
HISTORY = <<-BIG_LONG_MULTILINE
|
36
|
+
2022-07-11 v0.3 Ported from private files in GIC into storazzo (open source on gitHub) and cleaned up italian and libs
|
37
|
+
2022-07-DD v0.2 Some private stuff on GIC
|
38
|
+
BIG_LONG_MULTILINE
|
39
|
+
|
40
|
+
=begin
|
41
|
+
|
42
|
+
############################################################
|
43
|
+
@author: Riccardo Carlesso
|
44
|
+
@email: riccardo.carlesso@gmail.com
|
45
|
+
@maturity: development
|
46
|
+
@language: Ruby
|
47
|
+
@synopsis: Brief Description here
|
48
|
+
@tags: development, rcarlesso, test
|
49
|
+
@description: See description
|
50
|
+
############################################################
|
51
|
+
|
52
|
+
=end
|
53
|
+
|
54
|
+
|
55
|
+
$myconf = {
|
56
|
+
:app_name => "RicDisk Magic should be sth like #{$0}",
|
57
|
+
:description => "
|
58
|
+
This program is loosely inspired to ricdisk-magic.sh but its much better.
|
59
|
+
Idea di base: trovare tutti le directory con file ricdisk e da esso estrarre info e magari METTERE info.
|
60
|
+
Il tutto condito con un bel protobuf e un'entita che metto in Lib.
|
61
|
+
".strip.gsub(/^\s+/, "").gsub(/\s+$/, ""),
|
62
|
+
# TODO move to some class default
|
63
|
+
:media_dirs => %w{ /media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/ /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/ },
|
64
|
+
:mount_types => %w{ vfat ntfs },
|
65
|
+
}
|
66
|
+
$stats_file = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
|
67
|
+
$gcs_bucket = 'TODO-CHANGE-CONFIG-palladius'
|
68
|
+
|
69
|
+
# This template from scripta.rb. from 2.1.0 removed aby ric gem dependency.
|
70
|
+
# 2022-04-26 2.1.1 Added more colors
|
71
|
+
# 2022-04-26 2.1.0 Historical momemnt: removed gem 'ric' dependency
|
72
|
+
$TEMPLATE_VER = '2.1.1'
|
73
|
+
|
74
|
+
|
75
|
+
def usage(comment=nil)
|
76
|
+
puts white($optparse.banner)
|
77
|
+
puts($optparse.summarize)
|
78
|
+
puts("Description: " + gray($myconf[:description]))
|
79
|
+
puts red(comment) if comment
|
80
|
+
#puts "Description: #{ $myconf[:description] }"
|
81
|
+
exit 13
|
82
|
+
end
|
83
|
+
|
84
|
+
# include it in main if you want a custome one
|
85
|
+
def init() # see lib_autoinit in lib/util.rb
|
86
|
+
$opts = {}
|
87
|
+
# setting defaults
|
88
|
+
$opts[:verbose] = false
|
89
|
+
$opts[:dryrun] = false
|
90
|
+
$opts[:debug] = false
|
91
|
+
$opts[:force] = false
|
92
|
+
|
93
|
+
$optparse = OptionParser.new do |opts|
|
94
|
+
opts.banner = "#{$0} v.#{$PROG_VER}\n Usage: #{File.basename $0} [options] file1 file2 ..."
|
95
|
+
opts.on( '-d', '--debug', 'enables debug (DFLT=false)' ) { $opts[:debug] = true ; $DEBUG = true }
|
96
|
+
opts.on( '-f', '--force', 'force stuff (DFLT=false)' ) { $opts[:force] = true }
|
97
|
+
opts.on( '-h', '--help', 'Display this screen' ) { usage }
|
98
|
+
#opts.on( '-j', '--jabba', 'Activates my Jabber powerful CLI' ) { $opts[:jabba] = true }
|
99
|
+
opts.on( '-n', '--dryrun', "Don't really execute code" ) { $opts[:dryrun] = true }
|
100
|
+
opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) {|file| $opts[:logfile] = file }
|
101
|
+
opts.on( '-v', '--verbose', 'Output more information' ) { $opts[:verbose] = true}
|
102
|
+
end
|
103
|
+
$optparse.parse!
|
104
|
+
end
|
105
|
+
|
106
|
+
def real_program
|
107
|
+
deb("Hello world from a templated '#{yellow $0 }'")
|
108
|
+
deb "+ Options are: #{gray $opts}"
|
109
|
+
deb "+ Depured args: #{azure ARGV}"
|
110
|
+
deb "+ Script-specifig super-cool conf: #{green $prog_conf_d}"
|
111
|
+
deb "+ Your configuration: #{purple $myconf.inspect}"
|
112
|
+
|
113
|
+
# Your code goes here...
|
114
|
+
puts white("Hello world from #{$myconf[:app_name]}!")
|
115
|
+
puts "Description: '''#{white $myconf[:description] }'''"
|
116
|
+
|
117
|
+
|
118
|
+
config = RicDiskConfig.auto_sbrodola(ARGV)
|
119
|
+
|
120
|
+
# if ARGV == [] # empty -> ALL
|
121
|
+
# dirs = RicDisk.find_active_dirs()
|
122
|
+
# dirs.each {|dir|
|
123
|
+
# RicDisk.sbrodola_ricdisk(dir)
|
124
|
+
# RicDisk.calculate_stats_files(dir) # dir is inutile
|
125
|
+
# } # TODO refactor in option sbrodola_afterwards=true. :)
|
126
|
+
# else
|
127
|
+
# deb "I consider ARGV come la lista di directories da parsare :)"
|
128
|
+
# dirs = RicDisk.find_active_dirs()
|
129
|
+
# ARGV.each{ |dir|
|
130
|
+
# dir = File.expand_path(dir)
|
131
|
+
# if dirs.include?(dir)
|
132
|
+
# deb "Legit dir: #{green dir}"
|
133
|
+
# RicDisk.sbrodola_ricdisk(dir)
|
134
|
+
# RicDisk.calculate_stats_files(dir) # dir is inutile
|
135
|
+
# else
|
136
|
+
# deb "Figghiu ri buttana: doesnt exist #{red dir}"
|
137
|
+
# end
|
138
|
+
# }
|
139
|
+
# end #/if aRGV
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
def main(filename)
|
144
|
+
deb "I'm called by #{white filename}"
|
145
|
+
deb "HISTORY: #{gray HISTORY}"
|
146
|
+
#deb "To remove this shit, just set $DEBUG=false :)"
|
147
|
+
init # Enable this to have command line parsing capabilities!
|
148
|
+
#warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
|
149
|
+
real_program
|
150
|
+
end
|
151
|
+
|
152
|
+
main(__FILE__)
|
data/lib/storazzo/colors.rb
CHANGED
@@ -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
|
-
|
9
|
+
|
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,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,69 @@
|
|
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::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
|
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
|
42
|
+
#sbrodola_ricdisk("/Volumes/")
|
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'
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.all_tests
|
51
|
+
# include vs extend: https://stackoverflow.com/questions/15097929/ruby-module-require-and-include
|
52
|
+
# => http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
|
53
|
+
#include Storazzo::Colors
|
54
|
+
extend Storazzo::Colors
|
55
|
+
|
56
|
+
pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
|
57
|
+
deb "Maybe debug is enabled?"
|
58
|
+
hi
|
59
|
+
# This works with EXTEND..
|
60
|
+
puts(yellow "Just YELLOW 0")
|
61
|
+
# This reqwuires a INCLUDE.
|
62
|
+
#puts(Storazzo::Colors.yellow "Test YELLOW 1 self")
|
63
|
+
#puts(Colors.yellow "Test YELLOW 1 self")
|
64
|
+
#puts(Colors.green "Test YELLOW 2 ohne self")
|
65
|
+
pwhite "All tests END"
|
66
|
+
#puts "All tests END"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
File without changes
|