ehbrs-tools 0.5.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +7 -1
- data/lib/ehbrs/fs.rb +9 -0
- data/lib/ehbrs/fs/compressed_package.rb +48 -0
- data/lib/ehbrs/gems.rb +37 -0
- data/lib/ehbrs/observers.rb +11 -0
- data/lib/ehbrs/observers/base.rb +64 -0
- data/lib/ehbrs/observers/with_persistence.rb +34 -0
- data/lib/ehbrs/runner/fs.rb +19 -0
- data/lib/ehbrs/runner/fs/used_space.rb +161 -0
- data/lib/ehbrs/runner/self.rb +19 -0
- data/lib/ehbrs/runner/self/test.rb +30 -0
- data/lib/ehbrs/runner/vg/ips.rb +67 -18
- data/lib/ehbrs/runner/videos/extract.rb +71 -0
- data/lib/ehbrs/runner/videos/series.rb +21 -0
- data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
- data/lib/ehbrs/self.rb +9 -0
- data/lib/ehbrs/self/observers/used_space.rb +22 -0
- data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/user_dirs.rb +34 -0
- data/lib/ehbrs/vg/wii/game_file.rb +13 -0
- data/lib/ehbrs/videos/extract.rb +11 -0
- data/lib/ehbrs/videos/extract/package.rb +75 -0
- data/lib/ehbrs/videos/extract/package_file.rb +54 -0
- data/lib/ehbrs/videos/series.rb +11 -0
- data/lib/ehbrs/videos/series/rename.rb +13 -0
- data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
- data/lib/ehbrs/videos/series/rename/file.rb +114 -0
- data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
- data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
- data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
- data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
- data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
- data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +52 -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/on_clean_ruby_environment.rb +5 -16
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
- 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/object/to_pathname.rb +15 -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/regexp/if_match.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.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/ruby.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb +26 -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/extname_spec.rb +18 -0
- 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_spec.rb +52 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
- metadata +85 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f3e4b8b8c20622926deed970635cf35570dc1171177cd99ee276a78a40d916e
|
4
|
+
data.tar.gz: 62f890aa3e488464d788a1f7ea5a055ba99e22ca1e48427fdf6ff30643c4290c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c33b1f44b74bd9b3a1b89739dcb4cb1b013ce99aadec47d0ccfc6fe6d430d265749141d4ddddf73d498771582586146652a00c9de19b2da5a8968b86da578e
|
7
|
+
data.tar.gz: f8cd84b153932edb1a1ce1b20ca7df3dc707899a6d2d801b6d771d24ee3eb3cdc0a718ccaaf850f68ef86a9e132d50b296210c2dcd15eacc9b673fcc79300ce2
|
data/lib/ehbrs/executables.rb
CHANGED
@@ -15,8 +15,10 @@ module Ehbrs
|
|
15
15
|
private
|
16
16
|
|
17
17
|
{
|
18
|
+
'-?' => %w[rar],
|
19
|
+
'-h' => %w[unzip],
|
18
20
|
'-version' => %w[ffmpeg ffprobe],
|
19
|
-
'--version' => %w[flips
|
21
|
+
'--version' => %w[flips tar wit]
|
20
22
|
}.each do |validate_arg, commands|
|
21
23
|
commands.each do |command|
|
22
24
|
define_method("#{command}_uncached") do
|
@@ -24,6 +26,10 @@ module Ehbrs
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
def sevenzip_uncached
|
31
|
+
env.executable('7z', '--help')
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/ehbrs/fs.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/files/info'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Fs
|
8
|
+
class CompressedPackage < ::Avm::Files::Info
|
9
|
+
MIME_TYPES = {
|
10
|
+
'application/zip' => :zip,
|
11
|
+
'application/x-7z-compressed' => :sevenzip,
|
12
|
+
'application/x-rar' => :rar,
|
13
|
+
'application/x-tar' => :tar
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
def extract_to(target)
|
17
|
+
target = target.to_pathname
|
18
|
+
target.mkpath
|
19
|
+
sub_extract_to(target)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def sub_extract_to(target)
|
25
|
+
MIME_TYPES[content_type.mime_type].if_present do |v|
|
26
|
+
return send("#{v}_extract_command", target).execute!
|
27
|
+
end
|
28
|
+
raise "Unknown how to extract \"#{path}\" (#{content_type})"
|
29
|
+
end
|
30
|
+
|
31
|
+
def sevenzip_extract_command(target_dir)
|
32
|
+
::Ehbrs::Executables.sevenzip.command('x', path, '-o', target_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
def tar_extract_command(target_dir)
|
36
|
+
::Ehbrs::Executables.tar.command('-xf', path, '-C', target_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
def rar_extract_command(target_dir)
|
40
|
+
::Ehbrs::Executables.rar.command('x', path.expand_path).chdir(target_dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
def zip_extract_command(target_dir)
|
44
|
+
::Ehbrs::Executables.unzip.command(path, '-d', target_dir)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ehbrs/gems.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/gem'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Gems
|
7
|
+
class << self
|
8
|
+
enable_simple_cache
|
9
|
+
|
10
|
+
def app_path
|
11
|
+
::Pathname.new('../..').expand_path(__dir__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def vendor_gems_root
|
15
|
+
app_path.join('vendor')
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def app_uncached
|
21
|
+
::EacRubyGemsUtils::Gem.new(app_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_uncached
|
25
|
+
vendor_gems + [app]
|
26
|
+
end
|
27
|
+
|
28
|
+
def vendor_gems_uncached
|
29
|
+
r = []
|
30
|
+
vendor_gems_root.each_child.each do |child|
|
31
|
+
r << ::EacRubyGemsUtils::Gem.new(child) if child.directory?
|
32
|
+
end
|
33
|
+
r
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -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,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,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 Self < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
require_sub __FILE__
|
11
|
+
include ::EacCli::DefaultRunner
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Self utilities'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|