ehbrs-tools 0.3.1 → 0.5.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/exe/ehbrs +2 -2
  3. data/lib/ehbrs/executables.rb +8 -7
  4. data/lib/ehbrs/runner.rb +33 -0
  5. data/lib/ehbrs/runner/vg.rb +19 -0
  6. data/lib/ehbrs/runner/vg/ips.rb +88 -0
  7. data/lib/ehbrs/runner/vg/wii.rb +75 -0
  8. data/lib/ehbrs/runner/videos.rb +23 -0
  9. data/lib/ehbrs/runner/videos/unsupported.rb +63 -0
  10. data/lib/ehbrs/tools/version.rb +1 -1
  11. data/lib/ehbrs/vg.rb +9 -0
  12. data/lib/ehbrs/vg/wii.rb +11 -0
  13. data/lib/ehbrs/vg/wii/file_move.rb +89 -0
  14. data/lib/ehbrs/vg/wii/game_file.rb +64 -0
  15. data/lib/ehbrs/vg/wii/wit.rb +13 -0
  16. data/lib/ehbrs/vg/wii/wit/image_format.rb +46 -0
  17. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +62 -0
  18. data/lib/ehbrs/vg/wii/wit/parsers/info.rb +39 -0
  19. data/lib/ehbrs/vg/wii/wit/path.rb +55 -0
  20. data/lib/ehbrs/videos/unsupported/search.rb +13 -10
  21. data/vendor/eac_ruby_utils/lib/eac_ruby_utils.rb +1 -19
  22. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb +1 -1
  23. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/custom_format.rb +53 -0
  24. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +7 -0
  25. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/spawn.rb +32 -0
  26. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs.rb +9 -0
  27. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb +47 -0
  28. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +74 -0
  29. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb +2 -2
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  31. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb +60 -0
  32. metadata +37 -8
  33. data/lib/ehbrs/tools/runner.rb +0 -35
  34. data/lib/ehbrs/tools/runner/vg.rb +0 -26
  35. data/lib/ehbrs/tools/runner/vg/ips.rb +0 -90
  36. data/lib/ehbrs/tools/runner/videos.rb +0 -25
  37. data/lib/ehbrs/tools/runner/videos/unsupported.rb +0 -65
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_traverser.rb +0 -56
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/custom_format'
5
+ require 'ehbrs/vg/wii/wit/parsers/dump'
6
+ require 'ehbrs/vg/wii/wit/path'
7
+ require 'pathname'
8
+
9
+ module Ehbrs
10
+ module Vg
11
+ module Wii
12
+ class GameFile < ::Pathname
13
+ enable_simple_cache
14
+
15
+ FORMAT = ::EacRubyUtils::CustomFormat.new(
16
+ b: :basename,
17
+ d: :dirname,
18
+ e: :extname,
19
+ i: :id6,
20
+ n: :disc_name,
21
+ t: :database_title,
22
+ T: :disc_type
23
+ )
24
+
25
+ def database_title
26
+ properties.fetch('DB title')
27
+ end
28
+
29
+ def disc_name
30
+ properties.fetch('Disc name')
31
+ end
32
+
33
+ def disc_type
34
+ properties.fetch('File & disc type/type')
35
+ end
36
+
37
+ def format(string)
38
+ FORMAT.format(string).with(self)
39
+ end
40
+
41
+ def id6
42
+ properties.fetch('Disc & part IDs/disc')
43
+ end
44
+
45
+ def valid?
46
+ properties.present?
47
+ end
48
+
49
+ def wit_path
50
+ ::Ehbrs::Vg::Wii::Wit::Path.new(disc_type, self)
51
+ end
52
+
53
+ private
54
+
55
+ def properties_uncached
56
+ r = ::Ehbrs::Executables.wit.command.append(['dump', to_s]).execute
57
+ return nil unless r.fetch(:exit_code).zero?
58
+
59
+ ::Ehbrs::Vg::Wii::Wit::Parsers::Dump.new(r.fetch(:stdout)).properties
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Vg
7
+ module Wii
8
+ module Wit
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'ehbrs/vg/wii/wit/parsers/info'
6
+
7
+ module Ehbrs
8
+ module Vg
9
+ module Wii
10
+ module Wit
11
+ class ImageFormat
12
+ class << self
13
+ SECTION_NAME_PATTERN = /\A#{::Regexp.quote('IMAGE-FORMAT:')}(.+)\z/.freeze
14
+
15
+ enable_simple_cache
16
+
17
+ def by_name(name)
18
+ all.find { |i| i.name.downcase == name.to_s.downcase } ||
19
+ raise(::ArgumentError, "Image not found with name \"#{name.to_s.downcase}\"" \
20
+ " (Available: #{all.map(&:name).join(', ')})")
21
+ end
22
+
23
+ private
24
+
25
+ def all_uncached
26
+ ::Ehbrs::Vg::Wii::Wit::Parsers::Info.new(info_output).images.map do |_label, data|
27
+ new(
28
+ *%w[name info option].map { |k| data.fetch(k) },
29
+ *%w[extensions attributes].map { |k| data.fetch(k).to_s.split(/\s+/) }
30
+ )
31
+ end
32
+ end
33
+
34
+ def info_output
35
+ ::Ehbrs::Executables.wit.command
36
+ .append(%w[info image-format --sections])
37
+ .execute!
38
+ end
39
+ end
40
+
41
+ common_constructor :name, :description, :option, :extensions, :attributes
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Vg
7
+ module Wii
8
+ module Wit
9
+ module Parsers
10
+ class Dump
11
+ enable_simple_cache
12
+ common_constructor :output
13
+
14
+ FILE_DISC_TYPE_PATTERN = %r{\A(\S+)/(\S+)\s+&\s+(\S+)\z}.freeze
15
+
16
+ private
17
+
18
+ def properties_uncached
19
+ r = {}
20
+ output.each_line do |line|
21
+ dump_output_line_to_hash(line).if_present { |v| r.merge!(v) }
22
+ end
23
+ r
24
+ end
25
+
26
+ def dump_output_line_to_hash(line)
27
+ m = /\A\s*([^:]+):\s+(.+)\z/.match(line.strip)
28
+ return nil unless m
29
+
30
+ parse_attribute(m[1].strip, m[2].strip)
31
+ end
32
+
33
+ def line_method_parser(label)
34
+ "parse_#{label}".parameterize.underscore
35
+ end
36
+
37
+ def parse_attribute(label, value)
38
+ method = line_method_parser(label)
39
+ return { label => value } unless respond_to?(method, true)
40
+
41
+ send(method, value).map { |k, v| ["#{label}/#{k}", v] }.to_h
42
+ end
43
+
44
+ def parse_file_disc_type(value)
45
+ FILE_DISC_TYPE_PATTERN
46
+ .match(value)
47
+ .if_present { |m| { type: m[1], platform_acronym: m[2], platform_name: m[3] } }
48
+ .if_blank { raise "\"#{FILE_DISC_TYPE_PATTERN}\" does not match \"#{value}\"" }
49
+ end
50
+
51
+ def parse_disc_part_ids(value)
52
+ value.split(',').map(&:strip).map do |v|
53
+ r = v.split('=')
54
+ [r[0].strip, r[1].strip]
55
+ end.to_h
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'fileutils'
6
+ require 'inifile'
7
+
8
+ module Ehbrs
9
+ module Vg
10
+ module Wii
11
+ module Wit
12
+ module Parsers
13
+ class Info
14
+ SECTION_NAME_PATTERN = /\A#{::Regexp.quote('IMAGE-FORMAT:')}(.+)\z/.freeze
15
+
16
+ enable_simple_cache
17
+ common_constructor :output
18
+
19
+ private
20
+
21
+ def images_uncached
22
+ ini = ::IniFile.new(content: output)
23
+ r = {}
24
+ ini.sections.each do |section_name|
25
+ image_section_name = parse_image_section_name(section_name)
26
+ r[image_section_name] = ini[section_name] if image_section_name.present?
27
+ end
28
+ r
29
+ end
30
+
31
+ def parse_image_section_name(section_name)
32
+ SECTION_NAME_PATTERN.match(section_name).if_present { |m| m[1] }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Vg
7
+ module Wii
8
+ module Wit
9
+ class Path
10
+ WIT_PATH_PATTERN = /\A(?:([a-z0-9]+):)?(.+)\z/i.freeze
11
+
12
+ class << self
13
+ def assert(source)
14
+ source = parse(source) unless source.is_a?(self)
15
+ source
16
+ end
17
+
18
+ def parse(path)
19
+ WIT_PATH_PATTERN
20
+ .match(path)
21
+ .if_present { |m| new(m[1], m[2]) }
22
+ .if_blank { raise "\"#{WIT_PATH_PATTERN}\" does not match \"#{path}\"" }
23
+ end
24
+ end
25
+
26
+ common_constructor :type, :path do
27
+ self.type = type.to_s.upcase
28
+ self.path = ::Pathname.new(path.to_s)
29
+ end
30
+
31
+ def change?(other)
32
+ type_change?(other) || path_change?(other)
33
+ end
34
+
35
+ def path_change?(other)
36
+ path.expand_path.to_s != other.path.expand_path.to_s
37
+ end
38
+
39
+ def to_s
40
+ r = path.to_s
41
+ r = "#{type.to_s.upcase}:#{r}" if type.present?
42
+ r
43
+ end
44
+
45
+ def type_change?(other)
46
+ return false if other.type.blank?
47
+ return true if type.blank?
48
+
49
+ type != other.type
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/filesystem_traverser'
3
+ require 'eac_ruby_utils/fs/traversable'
4
4
  require 'eac_ruby_utils/core_ext'
5
5
  require 'ehbrs/videos/unsupported/file'
6
6
 
@@ -8,7 +8,9 @@ module Ehbrs
8
8
  module Videos
9
9
  module Unsupported
10
10
  class Search
11
+ include ::EacRubyUtils::Fs::Traversable
11
12
  enable_console_speaker
13
+ enable_simple_cache
12
14
 
13
15
  VALID_EXTENSIONS = %w[.avi .mp4 .mkv .m4v].freeze
14
16
 
@@ -21,22 +23,23 @@ module Ehbrs
21
23
  run
22
24
  end
23
25
 
26
+ def traverser_recursive
27
+ true
28
+ end
29
+
30
+ def traverser_sort
31
+ true
32
+ end
33
+
24
34
  private
25
35
 
26
36
  def run
27
37
  start_banner
28
- traverser = ::EacRubyUtils::FilesystemTraverser.new
29
- traverser.recursive = true
30
- traverser.check_file = method(:check_file)
31
- traverser.check_path(@root)
38
+ traverser_check_path(@root)
32
39
  end_banner
33
40
  end
34
41
 
35
- def recursive?
36
- true
37
- end
38
-
39
- def check_file(file)
42
+ def traverser_check_file(file)
40
43
  @files += 1
41
44
  check_video(file) if video_file?(file)
42
45
  end
@@ -1,24 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- require 'eac_ruby_utils/arguments_consumer'
5
- require 'eac_ruby_utils/by_reference'
6
- require 'eac_ruby_utils/configs'
7
- require 'eac_ruby_utils/console'
8
- require 'eac_ruby_utils/contextualizable'
9
- require 'eac_ruby_utils/core_ext'
10
- require 'eac_ruby_utils/envs'
11
- require 'eac_ruby_utils/filesystem_cache'
12
- require 'eac_ruby_utils/filesystem_traverser'
13
- require 'eac_ruby_utils/fs_cache'
14
- require 'eac_ruby_utils/listable'
15
- require 'eac_ruby_utils/options_consumer'
16
- require 'eac_ruby_utils/settings_provider'
17
- require 'eac_ruby_utils/patch'
18
- require 'eac_ruby_utils/patches'
19
- require 'eac_ruby_utils/paths_hash'
20
4
  require 'eac_ruby_utils/require_sub'
21
- require 'eac_ruby_utils/rspec'
22
- require 'eac_ruby_utils/simple_cache'
23
- require 'eac_ruby_utils/yaml'
5
+ ::EacRubyUtils.require_sub __FILE__
24
6
  end
@@ -7,7 +7,7 @@ module EacRubyUtils
7
7
  end
8
8
 
9
9
  def method_missing(method_name, *arguments, &block)
10
- return object.send(method_name, *arguments) if object.respond_to?(method_name)
10
+ return object.send(method_name, *arguments, &block) if object.respond_to?(method_name)
11
11
 
12
12
  super
13
13
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ # A formatter like [String.sprintf].
5
+ class CustomFormat
6
+ TYPE_PATTERN = /[a-zA-Z]/.freeze
7
+ SEQUENCE_PATTERN = /(?<!%)%(#{TYPE_PATTERN})/.freeze
8
+
9
+ attr_reader :mapping
10
+
11
+ def initialize(mapping)
12
+ @mapping = mapping.map { |k, v| [k.to_sym, v] }.to_h.freeze
13
+ end
14
+
15
+ def format(string)
16
+ ::EacRubyUtils::CustomFormat::String.new(self, string)
17
+ end
18
+
19
+ class String
20
+ attr_reader :format, :string
21
+
22
+ def initialize(format, string)
23
+ @format = format
24
+ @string = string
25
+ end
26
+
27
+ def mapping
28
+ @mapping ||= format.mapping.select do |k, _v|
29
+ sequences.include?(k)
30
+ end
31
+ end
32
+
33
+ def sequences
34
+ @sequences ||= string.scan(SEQUENCE_PATTERN).map(&:first).uniq.map(&:to_sym)
35
+ end
36
+
37
+ def source_object_value(object, method)
38
+ return object.send(method) if object.respond_to?(method)
39
+ return object[method] if object.respond_to?('[]')
40
+
41
+ raise ::ArgumentError, "Methods \"#{method}\" or \"[]\" not found for #{object}"
42
+ end
43
+
44
+ def with(source_object)
45
+ r = string
46
+ mapping.each do |key, method|
47
+ r = r.gsub(/%#{::Regexp.quote(key)}/, source_object_value(source_object, method).to_s)
48
+ end
49
+ r.gsub('%%', '%')
50
+ end
51
+ end
52
+ end
53
+ end
@@ -4,6 +4,7 @@ require 'active_support/core_ext/hash/indifferent_access'
4
4
  require 'eac_ruby_utils/console/speaker'
5
5
  require 'eac_ruby_utils/envs/command/extra_options'
6
6
  require 'eac_ruby_utils/envs/process'
7
+ require 'eac_ruby_utils/envs/spawn'
7
8
  require 'pp'
8
9
  require 'shellwords'
9
10
 
@@ -69,6 +70,12 @@ module EacRubyUtils
69
70
  r
70
71
  end
71
72
 
73
+ def spawn(options = {})
74
+ c = command(options)
75
+ puts "SPAWN: #{c}".light_red if debug?
76
+ ::EacRubyUtils::Envs::Spawn.new(c)
77
+ end
78
+
72
79
  def system!(options = {})
73
80
  return if system(options)
74
81