ehbrs-tools 0.7.0 → 0.13.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/google.rb +9 -0
- data/lib/ehbrs/google/translate.rb +11 -0
- data/lib/ehbrs/google/translate/session.rb +61 -0
- data/lib/ehbrs/runner/finances.rb +19 -0
- data/lib/ehbrs/runner/finances/bb_browser.rb +40 -0
- data/lib/ehbrs/runner/google.rb +19 -0
- data/lib/ehbrs/runner/google/translate.rb +92 -0
- data/lib/ehbrs/runner/self.rb +19 -0
- data/lib/ehbrs/runner/self/test.rb +30 -0
- 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/tools/version.rb +1 -1
- 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/aranha-selenium/Gemfile +5 -0
- data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
- data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
- data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
- data/vendor/eac_docker/Gemfile +5 -0
- data/vendor/eac_docker/eac_docker.gemspec +18 -0
- data/vendor/eac_docker/lib/eac_docker.rb +7 -0
- data/vendor/eac_docker/lib/eac_docker/container.rb +50 -0
- data/vendor/eac_docker/lib/eac_docker/executables.rb +18 -0
- data/vendor/eac_docker/lib/eac_docker/images.rb +9 -0
- data/vendor/eac_docker/lib/eac_docker/images/base.rb +14 -0
- data/vendor/eac_docker/lib/eac_docker/images/named.rb +30 -0
- data/vendor/eac_docker/lib/eac_docker/rspec.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +5 -0
- data/vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb +9 -0
- data/vendor/eac_docker/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_docker/spec/spec_helper.rb +103 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +8 -0
- 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_cache.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb +15 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +28 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +42 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +72 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +8 -59
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_not_found_error.rb +7 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/base.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/generic.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb +29 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
- 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 +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb +22 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
- data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
- metadata +101 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a216d21cdcdb218151fbfd96d21d4b378ae35c4071d222707178c48a6f4ad69
|
4
|
+
data.tar.gz: dec260f1e8ffceb7eaa91fb4052b136d8222525c473e348abd897e86d0ba4e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 000fb54ab3abd785846e2d05802a7d12752109be7a2ac2314ea7804bcc90a4f98f3ee443dd693c6cba1687333c32d2832387f17acc9e32e44a6fb1cb22e23954
|
7
|
+
data.tar.gz: 8b060bb61da97a62b3fd1648060fb667ea9ed074fd719c194806d15469bae413031f663df10877b0099d109a4d78544f8e3148b842d36841e68f0140daa99b15
|
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 wit]
|
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
|
data/lib/ehbrs/google.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/selenium/session'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Google
|
7
|
+
module Translate
|
8
|
+
class Session
|
9
|
+
START_URL = 'https://translate.google.com.br/#view=home&op=docs&sl=en&tl=pt'
|
10
|
+
CLOSE_POPUP_CSS = '.dismiss-button'
|
11
|
+
FILE_INPUT_XPATH = '//*[@id = "tlid-file-input"]'
|
12
|
+
SUBMIT_XPATH = '//form[@action="//translate.googleusercontent.com/translate_f"]' \
|
13
|
+
'//input[@type="submit"]'
|
14
|
+
RESULT_XPATHS = [
|
15
|
+
'//script[contains(@src, "https://translate.google.com/translate_a")]',
|
16
|
+
'/html/body/pre'
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
attr_reader :sub
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@sub = ::Aranha::Selenium::Session.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def translate(source_document_path)
|
26
|
+
go_to_upload_form
|
27
|
+
input_file(source_document_path)
|
28
|
+
close_changes_alert_popup
|
29
|
+
click_on_translate_button
|
30
|
+
wait_for_load_translation
|
31
|
+
sub.current_source
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def go_to_upload_form
|
37
|
+
sub.navigate.to START_URL
|
38
|
+
sub.wait_for_element(xpath: FILE_INPUT_XPATH)
|
39
|
+
end
|
40
|
+
|
41
|
+
def input_file(source_document_path)
|
42
|
+
sub.find_element(xpath: FILE_INPUT_XPATH).send_keys(source_document_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def click_on_translate_button
|
46
|
+
sub.wait_for_click(xpath: SUBMIT_XPATH)
|
47
|
+
end
|
48
|
+
|
49
|
+
def close_changes_alert_popup
|
50
|
+
sub.wait_for_click(css: CLOSE_POPUP_CSS)
|
51
|
+
end
|
52
|
+
|
53
|
+
def wait_for_load_translation
|
54
|
+
sub.wait.until do
|
55
|
+
RESULT_XPATHS.any? { |xpath| sub.find_elements(xpath: xpath).size.positive? }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
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 Finances < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
include ::EacCli::DefaultRunner
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Utilidades financeiras.'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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
|
+
require 'ehbrs/videos/extract/package'
|
7
|
+
require 'eac_docker/images/named'
|
8
|
+
|
9
|
+
module Ehbrs
|
10
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class Finances < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
class BbBrowser < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
include ::EacCli::DefaultRunner
|
14
|
+
require_sub __FILE__
|
15
|
+
|
16
|
+
runner_definition do
|
17
|
+
desc 'Bankline para Banco do Brasil com módulo de segurança.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
infov 'Docker run arguments', docker_container.run_command_args
|
22
|
+
infov 'System result', docker_container.run_command.system
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def docker_image_uncached
|
28
|
+
::EacDocker::Images::Named.new('lichti/warsaw-browser')
|
29
|
+
end
|
30
|
+
|
31
|
+
def docker_container_uncached
|
32
|
+
docker_image.container.env('DISPLAY', "unix#{ENV.fetch('DISPLAY')}")
|
33
|
+
.volume(::File.join(ENV['HOME'], 'Downloads'), '/home/bank/Downloads')
|
34
|
+
.volume('/tmp/.X11-unix', '/tmp/.X11-unix').command_arg('bb')
|
35
|
+
.temporary(true).interactive(true).tty(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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 Google < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
require_sub __FILE__
|
11
|
+
include ::EacCli::DefaultRunner
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Utilidades Google.'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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
|
+
require 'ehbrs/google/translate/session'
|
7
|
+
|
8
|
+
module Ehbrs
|
9
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class Google < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class Translate < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
include ::EacCli::DefaultRunner
|
13
|
+
|
14
|
+
runner_definition do
|
15
|
+
desc 'Traduz um documento com Google Translate.'
|
16
|
+
arg_opt '-o', '--output-file', 'Salva saída em <output-file>.'
|
17
|
+
bool_opt '-w', '--overwrite', 'Permite sobreescrever arquivo de saída.'
|
18
|
+
pos_arg 'source-file'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
start_banner
|
23
|
+
validate
|
24
|
+
if output_to_stdout?
|
25
|
+
out(translated_content)
|
26
|
+
else
|
27
|
+
::File.write(output_file, translated_content)
|
28
|
+
end
|
29
|
+
success 'Concluído'
|
30
|
+
end
|
31
|
+
|
32
|
+
def start_banner
|
33
|
+
infov 'Source file', source_file
|
34
|
+
infov 'Target file', output_file
|
35
|
+
end
|
36
|
+
|
37
|
+
def translated_content_uncached
|
38
|
+
session.translate(source_file)
|
39
|
+
end
|
40
|
+
|
41
|
+
def source_file
|
42
|
+
options.fetch('<source-file>')
|
43
|
+
end
|
44
|
+
|
45
|
+
def output_file
|
46
|
+
options.fetch('--output-file') || default_output_file
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_output_file
|
50
|
+
::File.join(
|
51
|
+
::File.dirname(source_file),
|
52
|
+
::File.basename(source_file, '.*') + '_translated.html'
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def session_uncached
|
57
|
+
::Ehbrs::Google::Translate::Session.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate
|
61
|
+
validate_source_file
|
62
|
+
validate_output_file
|
63
|
+
validate_output_content
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_source_file
|
67
|
+
return if ::File.exist?(source_file)
|
68
|
+
|
69
|
+
fatal_error "Source file \"#{source_file}\" does not exist"
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate_output_file
|
73
|
+
return if output_to_stdout?
|
74
|
+
return unless ::File.exist?(output_file)
|
75
|
+
return if options.fetch('--overwrite')
|
76
|
+
|
77
|
+
fatal_error "Output file \"#{output_file}\" already exists"
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate_output_content
|
81
|
+
return if translated_content.present?
|
82
|
+
|
83
|
+
fatal_error 'Output content is empty'
|
84
|
+
end
|
85
|
+
|
86
|
+
def output_to_stdout?
|
87
|
+
output_file == '-'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/default_runner'
|
4
|
+
require 'ehbrs/gems'
|
5
|
+
require 'eac_ruby_gems_utils/tests/multiple'
|
6
|
+
require 'eac_ruby_utils/core_ext'
|
7
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
8
|
+
|
9
|
+
module Ehbrs
|
10
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class Self < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
class Test < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
require_sub __FILE__
|
14
|
+
include ::EacCli::DefaultRunner
|
15
|
+
|
16
|
+
runner_definition do
|
17
|
+
desc 'Test core and local gems.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
fatal_error 'Some test did not pass' unless tests.ok?
|
22
|
+
end
|
23
|
+
|
24
|
+
def tests_uncached
|
25
|
+
::EacRubyGemsUtils::Tests::Multiple.new(::Ehbrs::Gems.all)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|