ehbrs-tools 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/observers/base.rb +64 -0
- data/lib/ehbrs/observers/with_persistence.rb +34 -0
- data/lib/ehbrs/observers.rb +11 -0
- data/lib/ehbrs/runner/fs/used_space.rb +161 -0
- data/lib/ehbrs/runner/fs.rb +19 -0
- data/lib/ehbrs/self/observers/used_space.rb +22 -0
- data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
- data/lib/ehbrs/self.rb +9 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/user_dirs.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +27 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +12 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/{temp.rb → temp_spec.rb} +22 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
- metadata +37 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72afec8feac114779c526cf0b74bfddf4bb73f3c7b72c68b96d695814773cfad
|
4
|
+
data.tar.gz: 456156ff658bcd0c6ccab236d1c0785706e739fe0a98ffafd7ed1c2879216bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 549a83c6869358985e585fa9641d93b4b4260eef0da9c00ef48dd98f79c2ade46d8a1bc14dd71742bc9921001dbb066fcb93e9709cb0b82cb81e4cfb24a902ea
|
7
|
+
data.tar.gz: 7292c6e2fa9133ce8b9b82f8e0fce3e6183ca95932023a38172d57db1a8684bc24db517c2eaf95a42b900bb0fc22fa643469af78cb5e860bc73aee20d2e81fe9
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Observers
|
8
|
+
class Base
|
9
|
+
include ::EacRubyUtils::Listable
|
10
|
+
|
11
|
+
lists.add_string :blank_value, :add, :ignore, :raise
|
12
|
+
|
13
|
+
attr_reader :records, :blank_value, :last_check_time
|
14
|
+
|
15
|
+
common_constructor :options, default: [{}] do
|
16
|
+
@records = options[:records] || []
|
17
|
+
@blank_value = options[:blank_value].if_present(BLANK_VALUE_ADD) do |v|
|
18
|
+
v = v.to_s
|
19
|
+
::Ehbrs::Observers::Base.lists.blank_value.value_validate!(v)
|
20
|
+
v
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def check(value, date = ::Time.zone.now)
|
25
|
+
@last_check_time = date
|
26
|
+
send("check_with_blank_value_#{blank_value}", value, date)
|
27
|
+
end
|
28
|
+
|
29
|
+
def changing_value?(value)
|
30
|
+
records.if_present(true) do
|
31
|
+
last_value.if_present(value.present?) { |v| v != value }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def last_change_time
|
36
|
+
records.last.if_present(&:time)
|
37
|
+
end
|
38
|
+
|
39
|
+
def last_value
|
40
|
+
records.last.if_present(&:value)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def check_with_blank_value_add(value, time)
|
46
|
+
return false unless changing_value?(value)
|
47
|
+
|
48
|
+
records << ::OpenStruct.new(value: value, time: time)
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_with_blank_value_ignore(value, date)
|
53
|
+
return false if value.blank? ? false : check_with_blank_value_add(value, date)
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_with_blank_value_raise(value, date)
|
57
|
+
raise(::ArgumentError, "Blank value checked (Value: #{value}, Class: #{value.class})") if
|
58
|
+
value.blank?
|
59
|
+
|
60
|
+
check_with_blank_value_add(value, date)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs/observers/base'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Observers
|
8
|
+
class WithPersistence < ::Ehbrs::Observers::Base
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def initialize(path, options = {})
|
12
|
+
super(options)
|
13
|
+
@path = path.to_pathname
|
14
|
+
load
|
15
|
+
end
|
16
|
+
|
17
|
+
def check(value, date = ::Time.zone.now)
|
18
|
+
save if super(value, date)
|
19
|
+
end
|
20
|
+
|
21
|
+
def load
|
22
|
+
save unless path.exist?
|
23
|
+
data = ::YAML.load_file(path.to_path)
|
24
|
+
@records = data.fetch(:records).map { |h| ::OpenStruct.new(h) }
|
25
|
+
@last_check_time = data.fetch(:last_check_time)
|
26
|
+
end
|
27
|
+
|
28
|
+
def save
|
29
|
+
path.parent.mkpath
|
30
|
+
path.write({ records: records.map(&:to_h), last_check_time: last_check_time }.to_yaml)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs/self/observers/used_space'
|
4
|
+
require 'filesize'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
8
|
+
class Fs < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class UsedSpace < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
include ::EacCli::DefaultRunner
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
desc 'Verifica e anota alterações de espaço usado de um objeto de sistema de arquivos.'
|
14
|
+
bool_opt '-c', '--check', 'Anota o espaço em disco.'
|
15
|
+
bool_opt '-v', '--verbose', 'Verbose.'
|
16
|
+
pos_arg :paths, repeat: true
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
root_banner
|
21
|
+
paths.each(&:run)
|
22
|
+
end
|
23
|
+
|
24
|
+
def check?
|
25
|
+
options.fetch('--check')
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def root_banner
|
31
|
+
return unless verbose?
|
32
|
+
|
33
|
+
infov 'Paths', paths.count
|
34
|
+
infov 'Check?', check?
|
35
|
+
infov 'Verbose?', verbose?
|
36
|
+
end
|
37
|
+
|
38
|
+
def path_class
|
39
|
+
verbose? ? PathVerbose : PathUnverbose
|
40
|
+
end
|
41
|
+
|
42
|
+
def paths_uncached
|
43
|
+
options.fetch('<paths>').map { |path| path_class.new(self, path) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def verbose?
|
47
|
+
options.fetch('--verbose')
|
48
|
+
end
|
49
|
+
|
50
|
+
class PathBase
|
51
|
+
enable_simple_cache
|
52
|
+
enable_console_speaker
|
53
|
+
common_constructor :runner, :path do
|
54
|
+
self.path = path.to_pathname
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def last_change_time
|
60
|
+
time_label(observer.observer.last_change_time)
|
61
|
+
end
|
62
|
+
|
63
|
+
def last_check
|
64
|
+
time_label(observer.observer.last_check_time)
|
65
|
+
end
|
66
|
+
|
67
|
+
def last_value
|
68
|
+
bytes_label(observer.observer.last_value)
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_value
|
72
|
+
bytes_label(observer.current_value).colorize(
|
73
|
+
observer.changing_value? ? :green : :light_black
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def changing_value?
|
78
|
+
changing_label(observer.changing_value?)
|
79
|
+
end
|
80
|
+
|
81
|
+
def observer_uncached
|
82
|
+
::Ehbrs::Self::Observers::UsedSpace.new(path)
|
83
|
+
end
|
84
|
+
|
85
|
+
def changing_label(bool)
|
86
|
+
bool.to_s.colorize(bool ? :green : :light_black)
|
87
|
+
end
|
88
|
+
|
89
|
+
def time_label(time)
|
90
|
+
time.if_present('-', &:to_s)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class PathVerbose < PathBase
|
95
|
+
def run
|
96
|
+
infom path.to_s
|
97
|
+
on_speaker_node do |node|
|
98
|
+
node.stderr_line_prefix = ' '
|
99
|
+
banner
|
100
|
+
check
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def banner
|
107
|
+
{ 'Path' => observer.path,
|
108
|
+
'Persistence path' => observer.persistence_path,
|
109
|
+
'Last check' => last_check,
|
110
|
+
'Last change' => last_change_time,
|
111
|
+
'Last value' => last_value,
|
112
|
+
'Current value' => current_value,
|
113
|
+
'Changing?' => changing_value? }.each do |k, v|
|
114
|
+
infov k, v
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def check
|
119
|
+
return unless runner.check?
|
120
|
+
|
121
|
+
infom 'Checking...'
|
122
|
+
if observer.check_current_value
|
123
|
+
success 'A new value was recorded'
|
124
|
+
else
|
125
|
+
info 'No new value was recorded'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def bytes_label(number)
|
130
|
+
number.if_present('-') { |v| "#{v} (#{::Filesize.from("#{v} B").pretty})" }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class PathUnverbose < PathBase
|
135
|
+
def run
|
136
|
+
self.puts output_line
|
137
|
+
end
|
138
|
+
|
139
|
+
def output_line
|
140
|
+
[path.to_s.cyan, last_change_time, last_value, current_value, check_result]
|
141
|
+
.reject(&:blank?).join('|')
|
142
|
+
end
|
143
|
+
|
144
|
+
def check_result
|
145
|
+
return nil unless runner.check?
|
146
|
+
|
147
|
+
observer.check_current_value ? 'Recorded'.green : 'Unchanged'.light_black
|
148
|
+
end
|
149
|
+
|
150
|
+
def bytes_label(number)
|
151
|
+
number.if_present('-') { |v| ::Filesize.from("#{v} B").pretty }
|
152
|
+
end
|
153
|
+
|
154
|
+
def time_label(time)
|
155
|
+
time.if_present('-') { |t| t.strftime('%d/%m/%y %H:%M') }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/default_runner'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class Fs < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
include ::EacCli::DefaultRunner
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Ferramentas para o sistema de arquivos.'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs/self/observers/with_persistence'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Self
|
7
|
+
module Observers
|
8
|
+
class UsedSpace < ::Ehbrs::Self::Observers::WithPersistence
|
9
|
+
def path
|
10
|
+
label
|
11
|
+
end
|
12
|
+
|
13
|
+
def calculate_value
|
14
|
+
env = ::EacRubyUtils::Envs.local
|
15
|
+
env.command('du', '-sb', path.to_s).pipe(
|
16
|
+
env.command('cut', '-f', '-1')
|
17
|
+
).execute!.strip.to_i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs/observers/with_persistence'
|
4
|
+
require 'ehbrs/user_dirs'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Self
|
8
|
+
module Observers
|
9
|
+
class WithPersistence
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :label
|
12
|
+
|
13
|
+
def check_current_value
|
14
|
+
observer.check(current_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def changing_value?
|
18
|
+
observer.changing_value?(current_value)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def current_value_uncached
|
24
|
+
calculate_value
|
25
|
+
end
|
26
|
+
|
27
|
+
def observer_uncached
|
28
|
+
::Ehbrs::Observers::WithPersistence.new(persistence_path, blank_value: :raise)
|
29
|
+
end
|
30
|
+
|
31
|
+
def persistence_path_uncached
|
32
|
+
::Ehbrs::UserDirs.data.child('observers', label.to_s.parameterize)
|
33
|
+
.content_path.to_pathname
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/ehbrs/self.rb
ADDED
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/filesystem_cache'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module UserDirs
|
8
|
+
class << self
|
9
|
+
include ::EacRubyUtils::SimpleCache
|
10
|
+
|
11
|
+
def application_id
|
12
|
+
'ehbrs-tools'
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def user_home_dir_uncached
|
18
|
+
::EacRubyUtils::FilesystemCache.new(ENV['HOME'])
|
19
|
+
end
|
20
|
+
|
21
|
+
def cache_uncached
|
22
|
+
user_home_dir.child('.cache', application_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config_uncached
|
26
|
+
user_home_dir.child('.config', application_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def data_uncached
|
30
|
+
user_home_dir.child('.local', 'share', application_id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/fs/temp/file'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Fs
|
7
|
+
module Temp
|
8
|
+
class Directory < ::EacRubyUtils::Fs::Temp::File
|
9
|
+
def initialize(*tempfile_args)
|
10
|
+
super(*tempfile_args)
|
11
|
+
mkpath
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module Fs
|
8
|
+
module Temp
|
9
|
+
class File < Pathname
|
10
|
+
# Temporary file
|
11
|
+
def initialize(*tempfile_args)
|
12
|
+
file = Tempfile.new(*tempfile_args)
|
13
|
+
path = file.path
|
14
|
+
file.close
|
15
|
+
file.unlink
|
16
|
+
super(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove
|
20
|
+
if directory?
|
21
|
+
rmtree
|
22
|
+
elsif file?
|
23
|
+
unlink
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove!
|
28
|
+
remove
|
29
|
+
raise "Tried to remove \"#{self}\", but it yet exists" if exist?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/require_sub'
|
3
4
|
require 'pathname'
|
4
5
|
require 'tempfile'
|
5
6
|
|
@@ -8,23 +9,41 @@ module EacRubyUtils
|
|
8
9
|
# Utilities for temporary files.
|
9
10
|
module Temp
|
10
11
|
class << self
|
12
|
+
::EacRubyUtils.require_sub __FILE__
|
13
|
+
|
14
|
+
# Shortcut to +EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args)+.
|
15
|
+
#
|
16
|
+
# @return [Pathname]
|
17
|
+
def directory(*tempfile_args)
|
18
|
+
::EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Shortcut to +EacRubyUtils::Fs::Temp::File.new(*tempfile_args)+.
|
22
|
+
#
|
11
23
|
# @return [Pathname]
|
12
24
|
def file(*tempfile_args)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
::EacRubyUtils::Fs::Temp::File.new(*tempfile_args)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Run a block while a temporary directory pathname is provided. The directory is deleted
|
29
|
+
# when the block is finished.
|
30
|
+
def on_directory(*tempfile_args)
|
31
|
+
temp_dir = directory(*tempfile_args)
|
32
|
+
begin
|
33
|
+
yield(temp_dir)
|
34
|
+
ensure
|
35
|
+
temp_dir.remove
|
36
|
+
end
|
18
37
|
end
|
19
38
|
|
20
39
|
# Run a block while a temporary file pathname is providade. The file is deleted when block
|
21
40
|
# is finished.
|
22
41
|
def on_file(*tempfile_args)
|
23
|
-
|
42
|
+
temp_file = file(*tempfile_args)
|
24
43
|
begin
|
25
|
-
yield(
|
44
|
+
yield(temp_file)
|
26
45
|
ensure
|
27
|
-
|
46
|
+
temp_file.remove
|
28
47
|
end
|
29
48
|
end
|
30
49
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
# Produces a array with values's all combinations.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# %i[a b].boolean_combinations
|
8
|
+
# => [[], [:a], [:b], [:a, :b]]
|
9
|
+
#
|
10
|
+
# @return [Array]
|
11
|
+
def bool_array_combs
|
12
|
+
bool_combs([], method(:bool_array_combs_new_comb))
|
13
|
+
end
|
14
|
+
|
15
|
+
# Produces a hash with values's all combinations.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
# %i[a b].boolean_combinations
|
19
|
+
# => [{a: false, b: false}, {a: false, b: true}, {a: true, b: false}, {a: true, b: true}]
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
def bool_hash_combs
|
23
|
+
bool_combs({}, method(:bool_hash_combs_new_comb))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def bool_combs(empty_value, new_comb_method)
|
29
|
+
head = [empty_value]
|
30
|
+
r = inject(head) do |a, value|
|
31
|
+
new_comb_method.call(value, a)
|
32
|
+
end
|
33
|
+
r == head ? [] : r
|
34
|
+
end
|
35
|
+
|
36
|
+
def bool_array_combs_new_comb(value, combs)
|
37
|
+
combs + combs.map { |c| c + [value] }
|
38
|
+
end
|
39
|
+
|
40
|
+
def bool_hash_combs_new_comb(value, combs)
|
41
|
+
combs.flat_map do |comb|
|
42
|
+
[false, true].map { |bool_value| comb.dup.merge(value => bool_value) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Regexp
|
4
|
+
# If +self+ matches +string+ returns +block.call(Match result) or only Match result if block is
|
5
|
+
# not provided.
|
6
|
+
# If +self+ does not match +string+ raises a +ArgumentError+ if +required+ is truthy or return
|
7
|
+
# +nil+ otherwise.
|
8
|
+
def if_match(string, required = true, &block)
|
9
|
+
m = match(string)
|
10
|
+
if m
|
11
|
+
block ? block.call(m) : m
|
12
|
+
elsif required
|
13
|
+
raise(::ArgumentError, "Pattern \"#{self}\" does not match string \"#{string}\"")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/time/zones'
|
4
|
+
require 'eac_ruby_utils/envs'
|
5
|
+
|
6
|
+
class Time
|
7
|
+
class << self
|
8
|
+
TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
|
9
|
+
|
10
|
+
def local_time_zone
|
11
|
+
local_time_zone_by_timedatectl || local_time_zone_by_offset
|
12
|
+
end
|
13
|
+
|
14
|
+
def local_time_zone_by_timedatectl
|
15
|
+
executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
|
16
|
+
return nil unless executable.exist?
|
17
|
+
|
18
|
+
TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
|
19
|
+
end
|
20
|
+
|
21
|
+
def local_time_zone_by_offset
|
22
|
+
::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/fs/temp/directory'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Fs::Temp::Directory do
|
6
|
+
describe '#remove!' do
|
7
|
+
let(:instance) { described_class.new }
|
8
|
+
|
9
|
+
it { expect(instance).to be_directory }
|
10
|
+
it { expect { instance.remove! }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
@@ -27,4 +27,26 @@ RSpec.describe ::EacRubyUtils::Fs::Temp do
|
|
27
27
|
expect(temp_path).not_to exist
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
describe '#on_directory' do
|
32
|
+
it do
|
33
|
+
temp_path = nil
|
34
|
+
described_class.on_directory do |path|
|
35
|
+
temp_path = path
|
36
|
+
expect(temp_path).to be_directory
|
37
|
+
end
|
38
|
+
expect(temp_path).not_to exist
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'not fail if already removed' do
|
42
|
+
temp_path = nil
|
43
|
+
described_class.on_directory do |path|
|
44
|
+
temp_path = path
|
45
|
+
expect(temp_path).to be_directory
|
46
|
+
temp_path.rmtree
|
47
|
+
expect(temp_path).not_to exist
|
48
|
+
end
|
49
|
+
expect(temp_path).not_to exist
|
50
|
+
end
|
51
|
+
end
|
30
52
|
end
|
data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/enumerable/boolean_combinations'
|
4
|
+
|
5
|
+
RSpec.describe ::Enumerable do
|
6
|
+
let(:empty_instance) { [].to_enum }
|
7
|
+
let(:a_instance) { [:a].to_enum }
|
8
|
+
let(:ab_instance) { %i[a b].to_enum }
|
9
|
+
|
10
|
+
describe '#bool_hash_combs' do
|
11
|
+
it do
|
12
|
+
expect(empty_instance.bool_hash_combs).to eq([])
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
expect(a_instance.bool_hash_combs).to eq([{ a: false }, { a: true }])
|
17
|
+
end
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect(ab_instance.bool_hash_combs)
|
21
|
+
.to eq([{ a: false, b: false }, { a: false, b: true }, { a: true, b: false },
|
22
|
+
{ a: true, b: true }])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#bool_array_combs' do
|
27
|
+
it do
|
28
|
+
expect(empty_instance.bool_array_combs).to eq([])
|
29
|
+
end
|
30
|
+
|
31
|
+
it do
|
32
|
+
expect(a_instance.bool_array_combs).to eq([[], [:a]])
|
33
|
+
end
|
34
|
+
|
35
|
+
it do
|
36
|
+
expect(ab_instance.bool_array_combs).to eq([[], [:a], [:b], %i[a b]])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_ruby_utils
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: filesize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: inifile
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,14 +77,23 @@ files:
|
|
63
77
|
- exe/ehbrs
|
64
78
|
- lib/ehbrs.rb
|
65
79
|
- lib/ehbrs/executables.rb
|
80
|
+
- lib/ehbrs/observers.rb
|
81
|
+
- lib/ehbrs/observers/base.rb
|
82
|
+
- lib/ehbrs/observers/with_persistence.rb
|
66
83
|
- lib/ehbrs/runner.rb
|
84
|
+
- lib/ehbrs/runner/fs.rb
|
85
|
+
- lib/ehbrs/runner/fs/used_space.rb
|
67
86
|
- lib/ehbrs/runner/vg.rb
|
68
87
|
- lib/ehbrs/runner/vg/ips.rb
|
69
88
|
- lib/ehbrs/runner/vg/wii.rb
|
70
89
|
- lib/ehbrs/runner/videos.rb
|
71
90
|
- lib/ehbrs/runner/videos/unsupported.rb
|
91
|
+
- lib/ehbrs/self.rb
|
92
|
+
- lib/ehbrs/self/observers/used_space.rb
|
93
|
+
- lib/ehbrs/self/observers/with_persistence.rb
|
72
94
|
- lib/ehbrs/tools.rb
|
73
95
|
- lib/ehbrs/tools/version.rb
|
96
|
+
- lib/ehbrs/user_dirs.rb
|
74
97
|
- lib/ehbrs/vg.rb
|
75
98
|
- lib/ehbrs/vg/wii.rb
|
76
99
|
- lib/ehbrs/vg/wii/file_move.rb
|
@@ -158,6 +181,8 @@ files:
|
|
158
181
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb
|
159
182
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs.rb
|
160
183
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb
|
184
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb
|
185
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb
|
161
186
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb
|
162
187
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb
|
163
188
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb
|
@@ -175,6 +200,8 @@ files:
|
|
175
200
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches.rb
|
176
201
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class.rb
|
177
202
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb
|
203
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb
|
204
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
|
178
205
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb
|
179
206
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
|
180
207
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
|
@@ -191,6 +218,11 @@ files:
|
|
191
218
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb
|
192
219
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb
|
193
220
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb
|
221
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb
|
222
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb
|
223
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb
|
224
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
|
225
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
|
194
226
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb
|
195
227
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb
|
196
228
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec.rb
|
@@ -217,9 +249,11 @@ files:
|
|
217
249
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb
|
218
250
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb
|
219
251
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb
|
220
|
-
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp.rb
|
252
|
+
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb
|
253
|
+
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp_spec.rb
|
221
254
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb
|
222
255
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
|
256
|
+
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb
|
223
257
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb
|
224
258
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb
|
225
259
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/console_speaker_spec.rb
|