ehbrs-tools 0.5.0 → 0.11.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/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
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'line_result'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class LineResultGroup < ::Ehbrs::Videos::Series::Rename::LineResult
|
10
|
+
attr_reader :name, :children
|
11
|
+
|
12
|
+
def initialize(name, files)
|
13
|
+
@name = name
|
14
|
+
@children = build_children(files)
|
15
|
+
end
|
16
|
+
|
17
|
+
def show(level)
|
18
|
+
super(level)
|
19
|
+
children.each do |child|
|
20
|
+
child.show(level + 1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_children(files)
|
27
|
+
r = {}
|
28
|
+
files.each do |file|
|
29
|
+
key = file.send(child_key)
|
30
|
+
r[key] ||= []
|
31
|
+
r[key] << file
|
32
|
+
end
|
33
|
+
r.sort.map { |v| child_class.new(v[0], v[1]) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs/videos/series/rename/directory_group'
|
4
|
+
require 'ehbrs/videos/series/rename/line_result_group'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Videos
|
8
|
+
module Series
|
9
|
+
module Rename
|
10
|
+
class ResultsBuilder < LineResultGroup
|
11
|
+
def initialize(files)
|
12
|
+
super '', files
|
13
|
+
end
|
14
|
+
|
15
|
+
def line_out
|
16
|
+
'Groups: '.cyan + children.count.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def child_key
|
22
|
+
:dirname
|
23
|
+
end
|
24
|
+
|
25
|
+
def child_class
|
26
|
+
::Ehbrs::Videos::Series::Rename::DirectoryGroup
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'line_result'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class SeasonGroup < ::Ehbrs::Videos::Series::Rename::LineResult
|
10
|
+
attr_reader :season, :files
|
11
|
+
|
12
|
+
def initialize(season, files)
|
13
|
+
@season = season
|
14
|
+
@files = files.sort_by { |f| [f.episode] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def line_out
|
18
|
+
'Season: '.cyan + "#{season} (#{first_episode} - #{last_episode})"
|
19
|
+
end
|
20
|
+
|
21
|
+
def show(level)
|
22
|
+
super
|
23
|
+
files.each { |file| file.show(level + 1) }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def first_episode
|
29
|
+
files.first.episode
|
30
|
+
end
|
31
|
+
|
32
|
+
def last_episode
|
33
|
+
files.last.episode
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'colorize', '~> 0.8.1'
|
21
21
|
s.add_dependency 'docopt', '~> 0.6.1'
|
22
22
|
s.add_dependency 'net-ssh', '~> 4.2'
|
23
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
|
23
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
|
24
24
|
end
|
@@ -88,16 +88,22 @@ module EacRubyUtils
|
|
88
88
|
Kernel.system(c)
|
89
89
|
end
|
90
90
|
|
91
|
+
protected
|
92
|
+
|
93
|
+
def duplicate(command, extra_options)
|
94
|
+
self.class.new(@env, command, extra_options)
|
95
|
+
end
|
96
|
+
|
91
97
|
private
|
92
98
|
|
93
99
|
attr_reader :extra_options
|
94
100
|
|
95
101
|
def duplicate_by_command(new_command)
|
96
|
-
|
102
|
+
duplicate(new_command, @extra_options)
|
97
103
|
end
|
98
104
|
|
99
105
|
def duplicate_by_extra_options(set_extra_options)
|
100
|
-
|
106
|
+
duplicate(@command, @extra_options.merge(set_extra_options))
|
101
107
|
end
|
102
108
|
|
103
109
|
def debug?
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Fs
|
5
|
+
class << self
|
6
|
+
# A [File.extname] which find multiple extensions (Ex.: .tar.gz).
|
7
|
+
def extname(path, limit = -1)
|
8
|
+
recursive_extension(::File.basename(path), limit)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Shortcut to +extname(2)+.
|
12
|
+
def extname2(path)
|
13
|
+
extname(path, 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def recursive_extension(basename, limit)
|
19
|
+
return '' if limit.zero?
|
20
|
+
|
21
|
+
m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
|
22
|
+
if m
|
23
|
+
"#{recursive_extension(m[1], limit - 1)}#{m[2]}"
|
24
|
+
else
|
25
|
+
''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/require_sub'
|
4
|
+
require 'pathname'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
module Fs
|
9
|
+
# Utilities for temporary files.
|
10
|
+
module Temp
|
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
|
+
#
|
23
|
+
# @return [Pathname]
|
24
|
+
def file(*tempfile_args)
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
# Run a block while a temporary file pathname is providade. The file is deleted when block
|
40
|
+
# is finished.
|
41
|
+
def on_file(*tempfile_args)
|
42
|
+
temp_file = file(*tempfile_args)
|
43
|
+
begin
|
44
|
+
yield(temp_file)
|
45
|
+
ensure
|
46
|
+
temp_file.remove
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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,23 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/ruby/on_clean_environment'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
class << self
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def on_clean_envvars(*start_with_vars)
|
12
|
-
old_values = envvars_starting_with(start_with_vars)
|
13
|
-
old_values.keys.each { |k| ENV.delete(k) }
|
14
|
-
yield
|
15
|
-
ensure
|
16
|
-
old_values&.each { |k, v| ENV[k] = v }
|
17
|
-
end
|
18
|
-
|
19
|
-
def envvars_starting_with(start_with_vars)
|
20
|
-
ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
|
7
|
+
# <b>DEPRECATED:</b> Please use <tt>EacRubyUtils::Ruby.on_clean_environment</tt> instead.
|
8
|
+
def on_clean_ruby_environment(*args, &block)
|
9
|
+
::EacRubyUtils::Ruby.on_clean_environment(*args, &block)
|
21
10
|
end
|
22
11
|
end
|
23
12
|
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,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
class Object
|
7
|
+
# Convert +self+ to String and then to Pathname. Return nil if +self+ is +blank?+.
|
8
|
+
#
|
9
|
+
# @return [Pathname]
|
10
|
+
def to_pathname
|
11
|
+
return self if is_a?(::Pathname)
|
12
|
+
|
13
|
+
to_s.blank? ? nil : ::Pathname.new(to_s)
|
14
|
+
end
|
15
|
+
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
|