ehbrs-tools 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa659c13e85b5935fb4c1f79c3dacece337e2a2c4305d3696447a63585d8cf9f
4
- data.tar.gz: 760fe597d4e550c63c5ecc5a6a94d22b5ee70d2d5ea73a3b036c7a21c7bf3d92
3
+ metadata.gz: 96df751900aa306378007272674b8421190952ee71b133b05c10fd247397ec50
4
+ data.tar.gz: 80cce53bd76f46cb08de212d227ac639345198a5c93e9fb3deedd7c214831bf9
5
5
  SHA512:
6
- metadata.gz: 84aaa531f252a3a05242866c3593056cb33df6cce824a186067d610cf51a2ad01b5077f61d726d23fd19b75218809df0a44bf7cab842780da47642e1f274a80d
7
- data.tar.gz: 7ccbf1c9fe7be6a41a1a6acffdcabff9ca4c821ee313606e3ddaf8cc3d89daa3d7357ea77b972b0c824499e8c39836f9d97b5094eceac57b5f03b522a46294b5
6
+ metadata.gz: 538ff43fc795b7dac1aa2ab1cd24974aa8155603e0f4929c5a2a8e7186e2f546625293b6db799c73f46198114541a213bd33d9a27b819d91182e6cbf743a81a7
7
+ data.tar.gz: 2292ab898b428f1afb0c490816c0756d832c2cc40fd81ef7e7aa5dfb90a11b28b257ed09de45563d12d84d915b054081db71475da169dedc26bdaab5aa1945ac
@@ -16,7 +16,7 @@ module Ehbrs
16
16
 
17
17
  {
18
18
  '-version' => %w[ffmpeg ffprobe],
19
- '--version' => %w[flips-linux wit]
19
+ '--version' => %w[flips wit]
20
20
  }.each do |validate_arg, commands|
21
21
  commands.each do |command|
22
22
  define_method("#{command}_uncached") do
@@ -4,6 +4,7 @@ require 'eac_cli/runner'
4
4
  require 'eac_cli/default_runner'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
  require 'eac_ruby_utils/console/docopt_runner'
7
+ require 'eac_ruby_utils/fs/temp'
7
8
  require 'ehbrs/executables'
8
9
 
9
10
  module Ehbrs
@@ -17,71 +18,119 @@ module Ehbrs
17
18
  arg_opt '-o', '--output-file', ' Saída no arquivo <output-file>.'
18
19
  bool_opt '-w', '--overwrite', 'Sobrescreve o arquivo de saída se existente.'
19
20
  pos_arg 'source-file'
20
- pos_arg 'ips-file'
21
+ pos_arg 'ips-files', repeat: true
21
22
  end
22
23
 
23
24
  def run
24
25
  validate
26
+ start_banner
27
+ run_patches
28
+ infov 'Concluído'
25
29
  end
26
30
 
27
31
  private
28
32
 
29
- def run_patch
30
- ::Ehbrs::Executables.floating_ips.command
31
- .append(['--apply', ips_file, source_file, output_file]).system!
33
+ def on_temp_files
34
+ ::EacRubyUtils::Fs::Temp.on_file do |input|
35
+ ::EacRubyUtils::Fs::Temp.on_file do |output|
36
+ yield TempFiles.new(source_file, input, output)
37
+ end
38
+ end
39
+ end
40
+
41
+ def run_patch(source_path, ips_path, output_path)
42
+ ::Ehbrs::Executables.flips.command
43
+ .append(['--apply', ips_path, source_path, output_path]).system!
44
+ end
45
+
46
+ def run_patches
47
+ on_temp_files do |temp|
48
+ ips_files.each do |ips_file|
49
+ run_patch(temp.input, ips_file, temp.output)
50
+ temp.swap
51
+ end
52
+ temp.move_result_to(output_file)
53
+ end
32
54
  end
33
55
 
34
56
  def source_file
35
- options.fetch('<source-file>')
57
+ options.fetch('<source-file>').to_pathname
36
58
  end
37
59
 
38
60
  def start_banner
39
61
  infov 'Source file', source_file
40
- infov 'IPS file', ips_file
41
62
  infov 'Output file', output_file
63
+ infov 'IPS files', ips_files.count
64
+ ips_files.each { |ips_file| infov ' * ', ips_file }
42
65
  end
43
66
 
44
- def ips_file
45
- options.fetch('<ips-file>')
67
+ def ips_files
68
+ options.fetch('<ips-files>').map(&:to_pathname)
46
69
  end
47
70
 
48
71
  def output_file
49
- options.fetch('--output-file') || default_output_file
72
+ options.fetch('--output-file').to_pathname || default_output_file
50
73
  end
51
74
 
52
75
  def default_output_file
53
- ::File.join(
54
- ::File.dirname(ips_file),
55
- ::File.basename(ips_file, '.*') + ::File.extname(source_file)
76
+ ips_files.last.parent.join(
77
+ ips_files.map { |f| f.basename('.*').to_path }.join('_') + source_file.extname
56
78
  )
57
79
  end
58
80
 
59
81
  def validate
60
82
  validate_source_file
61
- validate_ips_file
83
+ ips_files.each { |ips_file| validate_ips_file(ips_file) }
62
84
  validate_output_file
63
- start_banner
64
- run_patch
65
85
  end
66
86
 
67
87
  def validate_source_file
68
- return if ::File.exist?(source_file)
88
+ return if source_file.exist?
69
89
 
70
90
  fatal_error("Arquivo fonte \"#{source_file}\" não existe")
71
91
  end
72
92
 
73
- def validate_ips_file
93
+ def validate_ips_file(ips_file)
74
94
  return if ::File.exist?(ips_file)
75
95
 
76
96
  fatal_error("Arquivo IPS \"#{ips_file}\" não existe")
77
97
  end
78
98
 
79
99
  def validate_output_file
80
- return unless ::File.exist?(output_file)
100
+ return unless output_file.exist?
81
101
  return if options.fetch('--overwrite')
82
102
 
83
103
  fatal_error("Arquivo de saída \"#{output_file}\" já existe")
84
104
  end
105
+
106
+ class TempFiles
107
+ common_constructor :initial, :temp0, :temp1
108
+
109
+ def input
110
+ swaped? ? temp0 : initial
111
+ end
112
+
113
+ def move_result_to(dest)
114
+ return unless swaped?
115
+
116
+ ::FileUtils.mv(temp0.to_path, dest.to_path)
117
+ end
118
+
119
+ def output
120
+ temp1
121
+ end
122
+
123
+ def swap
124
+ temp0_current = temp0
125
+ self.temp0 = temp1
126
+ self.temp1 = temp0_current
127
+ @swaped = true
128
+ end
129
+
130
+ def swaped?
131
+ @swaped ? true : false
132
+ end
133
+ end
85
134
  end
86
135
  end
87
136
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  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
- self.class.new(@env, new_command, @extra_options)
102
+ duplicate(new_command, @extra_options)
97
103
  end
98
104
 
99
105
  def duplicate_by_extra_options(set_extra_options)
100
- self.class.new(@env, @command, @extra_options.merge(set_extra_options))
106
+ duplicate(@command, @extra_options.merge(set_extra_options))
101
107
  end
102
108
 
103
109
  def debug?
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'tempfile'
5
+
6
+ module EacRubyUtils
7
+ module Fs
8
+ # Utilities for temporary files.
9
+ module Temp
10
+ class << self
11
+ # @return [Pathname]
12
+ def file(*tempfile_args)
13
+ file = Tempfile.new(*tempfile_args)
14
+ r = ::Pathname.new(file.path)
15
+ file.close
16
+ file.unlink
17
+ r
18
+ end
19
+
20
+ # Run a block while a temporary file pathname is providade. The file is deleted when block
21
+ # is finished.
22
+ def on_file(*tempfile_args)
23
+ pathname = file(*tempfile_args)
24
+ begin
25
+ yield(pathname)
26
+ ensure
27
+ pathname.unlink if pathname.exist?
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ 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
- def on_clean_ruby_environment
6
- on_clean_envvars('BUNDLE', 'RUBY') { yield }
7
- end
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,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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs/command'
4
+ require 'eac_ruby_utils/ruby/on_clean_environment'
5
+
6
+ module EacRubyUtils
7
+ module Ruby
8
+ # A [EacRubyUtils::Envs::Command] which runs in a clean Ruby environment.
9
+ class Command < ::EacRubyUtils::Envs::Command
10
+ def initialize(bundle_args, extra_options = {})
11
+ super(::EacRubyUtils::Envs.local, bundle_args, extra_options)
12
+ end
13
+
14
+ %w[system execute].each do |method_prefix|
15
+ [method_prefix, "#{method_prefix}!"].each do |method_name|
16
+ define_method method_name do |*args, &block|
17
+ ::EacRubyUtils::Ruby.on_clean_environment do
18
+ super(*args, &block)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def duplicate(command, extra_options)
27
+ self.class.new(gem, command, extra_options)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Ruby
5
+ class << self
6
+ # Executes a block in an environment when the variables BUNDLE* and RUBY* are removed.
7
+ def on_clean_environment
8
+ on_clean_envvars('BUNDLE', 'RUBY') { yield }
9
+ end
10
+
11
+ private
12
+
13
+ def on_clean_envvars(*start_with_vars)
14
+ old_values = envvars_starting_with(start_with_vars)
15
+ old_values.keys.each { |k| ENV.delete(k) }
16
+ yield
17
+ ensure
18
+ old_values&.each { |k, v| ENV[k] = v }
19
+ end
20
+
21
+ def envvars_starting_with(start_with_vars)
22
+ ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module EacRubyUtils
6
+ module Ruby
7
+ ::EacRubyUtils.require_sub(__FILE__)
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.28.0'
4
+ VERSION = '0.30.0'
5
5
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/temp'
4
+
5
+ RSpec.describe ::EacRubyUtils::Fs::Temp do
6
+ describe '#on_file' do
7
+ it do
8
+ temp_path = nil
9
+ described_class.on_file do |path|
10
+ temp_path = path
11
+ expect(temp_path).not_to exist
12
+ temp_path.write('StubText')
13
+ expect(temp_path).to exist
14
+ end
15
+ expect(temp_path).not_to exist
16
+ end
17
+
18
+ it 'not fail if already removed' do
19
+ temp_path = nil
20
+ described_class.on_file do |path|
21
+ temp_path = path
22
+ expect(temp_path).not_to exist
23
+ temp_path.write('StubText')
24
+ expect(temp_path).to exist
25
+ temp_path.unlink
26
+ end
27
+ expect(temp_path).not_to exist
28
+ end
29
+ end
30
+ 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.5.0
4
+ version: 0.6.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-04-26 00:00:00.000000000 Z
11
+ date: 2020-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -157,6 +157,7 @@ files:
157
157
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb
158
158
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb
159
159
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs.rb
160
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb
160
161
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb
161
162
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb
162
163
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb
@@ -187,6 +188,7 @@ files:
187
188
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
188
189
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
189
190
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb
191
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb
190
192
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb
191
193
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb
192
194
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb
@@ -194,6 +196,9 @@ files:
194
196
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec.rb
195
197
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/conditional.rb
196
198
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/stubbed_ssh.rb
199
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby.rb
200
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb
201
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb
197
202
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb
198
203
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb
199
204
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates.rb
@@ -212,6 +217,7 @@ files:
212
217
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb
213
218
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb
214
219
  - 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
215
221
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb
216
222
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
217
223
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb