avm-tools 0.114.2 → 0.115.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/avm/tools/version.rb +1 -1
- data/sub/avm/lib/avm/instances/base/auto_values/database.rb +2 -2
- data/sub/avm/lib/avm/instances/entry_keys.rb +2 -1
- data/sub/avm/lib/avm/self/instance.rb +0 -1
- data/sub/avm/lib/avm/sources/base/instance.rb +28 -0
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb +77 -0
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb +23 -12
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb +1 -1
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/deploy.rb +1 -1
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/deploy/config/install.sh.template +3 -3
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +4 -0
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +10 -0
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_fs/lib/eac_fs/patches/object/fs_cache.rb +6 -1
- data/sub/eac_fs/lib/eac_fs/version.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit.rb +46 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit_array.rb +81 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte.rb +105 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte_array.rb +36 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb +12 -4
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb +11 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_noext.rb +10 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb +13 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/bit_array_spec.rb +22 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/byte_spec.rb +54 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_noext_spec.rb +26 -0
- metadata +17 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf0d93631b14929c6e271ba0dd835f75a9633a961b3f870daa5c64eb467e0ef2
|
|
4
|
+
data.tar.gz: '0281c164c78506d7fe5ac8f601ce4380661f835a3c4e0ebe7c48c60334419565'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcbb490835a6f843cb9179effd073b661e7d4c7d1006ae4a135744d692203425ab8c4f9dbd18d55af1b1744655ec216c3feaf23470c1df691788eb3d94030a9d
|
|
7
|
+
data.tar.gz: 2e647b2157fe2c3bdf9ea51ebaac0809e4299af1bb13c96b73bae51c68e9876ba37347a9a85f3e15b8eede0c837546edf05079b116abf67081ecbe28062092b3
|
data/lib/avm/tools/version.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Avm
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def auto_database_password
|
|
40
|
-
database_auto_common('password')
|
|
40
|
+
database_auto_common('password') || id
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def auto_database_port
|
|
@@ -45,7 +45,7 @@ module Avm
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def auto_database_username
|
|
48
|
-
database_auto_common('username')
|
|
48
|
+
database_auto_common('username') || id
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def auto_database_system
|
|
@@ -47,7 +47,8 @@ module Avm
|
|
|
47
47
|
docker: %w[registry],
|
|
48
48
|
mailer: {
|
|
49
49
|
'' => %w[id from reply_to],
|
|
50
|
-
smtp: %w[address port domain username password authentication
|
|
50
|
+
smtp: %w[address port domain username password authentication openssl_verify_mode
|
|
51
|
+
starttls_auto tls]
|
|
51
52
|
},
|
|
52
53
|
ssh: %w[hostname port url username],
|
|
53
54
|
web: %w[authority hostname path port scheme url userinfo]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/instances/application'
|
|
4
|
+
require 'avm/instances/base'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Sources
|
|
8
|
+
class Base
|
|
9
|
+
module Instance
|
|
10
|
+
DEFAULT_INSTANCE_SUFFIX = 'dev'
|
|
11
|
+
|
|
12
|
+
def instance_suffix
|
|
13
|
+
DEFAULT_INSTANCE_SUFFIX
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def application_uncached
|
|
19
|
+
::Avm::Instances::Application.new(path.basename)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def instance_uncached
|
|
23
|
+
::Avm::Instances::Base.new(application, DEFAULT_INSTANCE_SUFFIX)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/sub/avm/lib/avm/version.rb
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module EacPostgresqlBase0
|
|
7
|
+
class Instance
|
|
8
|
+
class Assert
|
|
9
|
+
common_constructor :instance
|
|
10
|
+
delegate :name, :password, :user, to: :instance
|
|
11
|
+
|
|
12
|
+
def perform
|
|
13
|
+
create_user unless user_exist?
|
|
14
|
+
change_password unless password_ok?
|
|
15
|
+
create_database unless database_exist?
|
|
16
|
+
change_owner unless user_owner?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def change_owner
|
|
20
|
+
root_execute("ALTER DaTABASE \"#{name}\" OWNER TO \"#{user}\"")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def change_password
|
|
24
|
+
root_execute("ALTER USER \"#{user}\" WITH PASSWORD '#{password}'")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_user
|
|
28
|
+
root_execute("CREATE USER \"#{user}\" WITH PASSWORD '#{password}'")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def current_owner
|
|
32
|
+
root_query(<<~SQL
|
|
33
|
+
SELECT pg_catalog.pg_get_userbyid(datdba)
|
|
34
|
+
FROM pg_catalog.pg_database
|
|
35
|
+
WHERE datname = '#{name}'
|
|
36
|
+
SQL
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def database_exist?
|
|
41
|
+
root_boolean_query("FROM pg_database WHERE datname='#{name}'")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def password_ok?
|
|
45
|
+
instance.psql_command_command('SELECT 1', false)
|
|
46
|
+
.execute!(exit_outputs: { 512 => 'login_failed' }).strip == '1'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def user_exist?
|
|
50
|
+
root_boolean_query("FROM pg_roles WHERE rolname='#{user}'")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def user_owner?
|
|
54
|
+
user == current_owner
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def create_database
|
|
58
|
+
root_execute("CREATE DATABASE \"#{name}\" WITH OWNER \"#{user}\"")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def root_boolean_query(sql_after_projection)
|
|
64
|
+
root_query("SELECT 1 #{sql_after_projection}") == '1'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def root_execute(sql)
|
|
68
|
+
instance.root_psql_command(sql).execute!
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def root_query(sql)
|
|
72
|
+
root_execute(sql).strip
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'avm/eac_postgresql_base0/instance/data_unit'
|
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
5
|
|
|
5
6
|
module Avm
|
|
6
7
|
module EacPostgresqlBase0
|
|
7
8
|
class Instance
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
require_sub __FILE__
|
|
10
|
+
|
|
11
|
+
MAINTENANCE_DATABASE = 'postgres'
|
|
12
|
+
|
|
13
|
+
common_constructor :env, :connection_params do
|
|
14
|
+
self.connection_params = connection_params.with_indifferent_access
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def assert
|
|
18
|
+
::Avm::EacPostgresqlBase0::Instance::Assert.new(self).perform
|
|
11
19
|
end
|
|
12
20
|
|
|
13
21
|
def data_unit
|
|
@@ -23,20 +31,23 @@ module Avm
|
|
|
23
31
|
dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
|
|
24
32
|
end
|
|
25
33
|
|
|
26
|
-
def psql_command
|
|
27
|
-
env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args)
|
|
34
|
+
def psql_command(database = true)
|
|
35
|
+
env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args(database))
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
def psql_command_command(sql)
|
|
31
|
-
psql_command.append(['--quiet', '--tuples-only', '--command', sql])
|
|
38
|
+
def psql_command_command(sql, database = true)
|
|
39
|
+
psql_command(database).append(['--quiet', '--tuples-only', '--command', sql])
|
|
32
40
|
end
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
def root_psql_command(sql = nil)
|
|
43
|
+
args = ['sudo', '-u', 'postgres', 'psql']
|
|
44
|
+
args += ['--quiet', '--tuples-only', '--command', sql] if sql.present?
|
|
45
|
+
env.command(*args)
|
|
46
|
+
end
|
|
37
47
|
|
|
38
|
-
def common_command_args
|
|
39
|
-
['--host', host, '--username', user, '--port', port,
|
|
48
|
+
def common_command_args(database = true)
|
|
49
|
+
['--host', host, '--username', user, '--port', port,
|
|
50
|
+
(database ? name : MAINTENANCE_DATABASE)]
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
def host
|
data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/deploy/config/install.sh.template
CHANGED
|
@@ -18,9 +18,9 @@ export git_repositories_hierarchical_organisation=false
|
|
|
18
18
|
export smtp_server='%%MAILER.SMTP.ADDRESS%%'
|
|
19
19
|
export smtp_port='%%MAILER.SMTP.PORT%%'
|
|
20
20
|
export smtp_domain='%%MAILER.SMTP.DOMAIN%%'
|
|
21
|
-
export smtp_tls='%%
|
|
22
|
-
export smtp_enable_starttls_auto='%%
|
|
23
|
-
export smtp_openssl_verify_mode='%%
|
|
21
|
+
export smtp_tls='%%MAILER.SMTP.TLS%%'
|
|
22
|
+
export smtp_enable_starttls_auto='%%MAILER.SMTP.STARTTLS_AUTO%%'
|
|
23
|
+
export smtp_openssl_verify_mode='%%MAILER.SMTP.OPENSSL_VERIFY_MODE%%'
|
|
24
24
|
export smtp_authentication='%%MAILER.SMTP.AUTHENTICATION%%'
|
|
25
25
|
export smtp_username='%%MAILER.SMTP.USERNAME%%'
|
|
26
26
|
export smtp_password='%%MAILER.SMTP.PASSWORD%%'
|
|
@@ -23,6 +23,10 @@ module EacCli
|
|
|
23
23
|
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
def respond_to_call?((method_name))
|
|
27
|
+
parent.respond_to?(:runner_context) && parent.runner_context.respond_to_call?(method_name)
|
|
28
|
+
end
|
|
29
|
+
|
|
26
30
|
protected
|
|
27
31
|
|
|
28
32
|
def parent_call(method_name, *args)
|
|
@@ -37,6 +37,16 @@ module EacCli
|
|
|
37
37
|
def program_name
|
|
38
38
|
runner_context.if_present(&:program_name) || $PROGRAM_NAME
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
def respond_to_missing?(method, include_all = false)
|
|
42
|
+
runner_context.respond_to_call?(method) || super
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def method_missing(method, *args, &block)
|
|
46
|
+
return super unless runner_context.respond_to_call?(method)
|
|
47
|
+
|
|
48
|
+
runner_context.call(method, *args, &block)
|
|
49
|
+
end
|
|
40
50
|
end
|
|
41
51
|
end
|
|
42
52
|
end
|
|
@@ -10,7 +10,12 @@ class Object
|
|
|
10
10
|
def fs_#{type}
|
|
11
11
|
oid = fs_object_id_by_type(:'#{type}')
|
|
12
12
|
oid = [oid.to_s] unless oid.is_a?(::Enumerable)
|
|
13
|
-
oid.inject(
|
|
13
|
+
oid.inject(fs_#{type}_parent) { |a, e| a.child(e.to_s) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [EacFs::StorageTree]
|
|
17
|
+
def fs_#{type}_parent
|
|
18
|
+
self.class.fs_#{type}
|
|
14
19
|
end
|
|
15
20
|
CODE
|
|
16
21
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
|
4
|
+
|
|
5
|
+
module EacRubyUtils
|
|
6
|
+
class Bit
|
|
7
|
+
VALID_VALUES = [0, 1].freeze
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def assert(obj)
|
|
11
|
+
return obj if obj.is_a?(self)
|
|
12
|
+
|
|
13
|
+
new(obj.to_i)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def valid_integer?(value)
|
|
17
|
+
value.is_a?(::Integer) && VALID_VALUES.include?(value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate_integer(value)
|
|
21
|
+
return value if valid_integer?(value)
|
|
22
|
+
|
|
23
|
+
raise(::ArgumentError, "Invalid bit value: #{value} (Valid: #{VALID_VALUES})")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
attr_reader :value
|
|
28
|
+
compare_by :value
|
|
29
|
+
delegate :to_s, :zero?, to: :value
|
|
30
|
+
|
|
31
|
+
# @param value [Integer]
|
|
32
|
+
def initialize(value)
|
|
33
|
+
@value = self.class.validate_integer(value)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [Boolean]
|
|
37
|
+
def one?
|
|
38
|
+
!zero?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [Integer]
|
|
42
|
+
def to_i
|
|
43
|
+
value
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/bit'
|
|
4
|
+
require 'eac_ruby_utils/byte'
|
|
5
|
+
require 'eac_ruby_utils/byte_array'
|
|
6
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
|
7
|
+
|
|
8
|
+
module EacRubyUtils
|
|
9
|
+
class BitArray
|
|
10
|
+
class << self
|
|
11
|
+
def assert(obj)
|
|
12
|
+
return obj if obj.is_a?(self)
|
|
13
|
+
return new(obj) if obj.is_a?(::Enumerable)
|
|
14
|
+
|
|
15
|
+
raise "Could not convert #{obj} to #{self}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
delegate :each, :each_with_index, :to_a, :size, :count, :length, :[], :fetch, to: :values_array
|
|
20
|
+
compare_by :values_array
|
|
21
|
+
|
|
22
|
+
def initialize(values = [])
|
|
23
|
+
values.each { |value| push(value) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(value)
|
|
27
|
+
push(value)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [EacRubyUtils::BitArray] +self+.
|
|
31
|
+
def push_array(other_bit_array)
|
|
32
|
+
values_array.push(*other_bit_array.to_a)
|
|
33
|
+
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @param value [EacRubyUtils::Bit]
|
|
38
|
+
# @return [EacRubyUtils::Bit]
|
|
39
|
+
def push(value)
|
|
40
|
+
values_array.push(::EacRubyUtils::Bit.assert(value))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [EacRubyUtils::BitArray]
|
|
44
|
+
def reverse
|
|
45
|
+
self.class.new(values_array.reverse)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @param big_endian [Boolean]
|
|
49
|
+
# @return [EacRubyUtils::ByteArray]
|
|
50
|
+
def to_byte_array(big_endian = false)
|
|
51
|
+
unless count.modulo(::EacRubyUtils::Byte::BIT_COUNT).zero?
|
|
52
|
+
raise 'Bits returned is not multile of 8'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
byte_bits_enumerator.each_with_object(::EacRubyUtils::ByteArray.new) do |e, a|
|
|
56
|
+
a << ::EacRubyUtils::Byte.from_bit_array(e, big_endian)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @return [Array<Integer>]
|
|
61
|
+
def to_int_array
|
|
62
|
+
values_array.map(&:to_i)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def byte_bits_enumerator
|
|
68
|
+
::Enumerator.new do |y|
|
|
69
|
+
offset = 0
|
|
70
|
+
while offset < values_array.count
|
|
71
|
+
y.yield(values_array.slice(offset, ::EacRubyUtils::Byte::BIT_COUNT))
|
|
72
|
+
offset += ::EacRubyUtils::Byte::BIT_COUNT
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def values_array
|
|
78
|
+
@values_array ||= []
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/bit'
|
|
4
|
+
require 'eac_ruby_utils/bit_array'
|
|
5
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
|
6
|
+
|
|
7
|
+
module EacRubyUtils
|
|
8
|
+
class Byte
|
|
9
|
+
ASSEMBLY_HEXADECIMAL_PREFIX = '$'
|
|
10
|
+
BIT_COUNT = 8
|
|
11
|
+
BIT_INDEX_RANGE = (0..7).freeze
|
|
12
|
+
VALUE_RANGE = (0..255).freeze
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def assert(obj)
|
|
16
|
+
return obj if obj.is_a?(self)
|
|
17
|
+
|
|
18
|
+
new(obj.to_i)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def from_bit_array(bit_array, big_endian = false)
|
|
22
|
+
bit_array = ::EacRubyUtils::BitArray.assert(bit_array)
|
|
23
|
+
raise ::ArgumentError, "Wrong bit array size: #{bit_array.size}" if
|
|
24
|
+
bit_array.size != BIT_COUNT
|
|
25
|
+
|
|
26
|
+
bit_array = bit_array.reverse if big_endian
|
|
27
|
+
bit_array.each_with_index.inject(new(0)) do |a, e|
|
|
28
|
+
a.bit_set(e[1], e[0])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def valid_bit_index?(value)
|
|
33
|
+
value.is_a?(::Integer) && BIT_INDEX_RANGE.include?(value)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def validate_bit_index(value)
|
|
37
|
+
return value if valid_bit_index?(value)
|
|
38
|
+
|
|
39
|
+
raise(::ArgumentError, "Invalid bit index: #{value} (Range: #{BIT_INDEX_RANGE})")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def valid_value?(value)
|
|
43
|
+
value.is_a?(::Integer) && VALUE_RANGE.include?(value)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def validate_value(value)
|
|
47
|
+
return value if valid_value?(value)
|
|
48
|
+
|
|
49
|
+
raise(::ArgumentError, "Invalid byte value: #{value} (Range: #{VALUE_RANGE})")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
attr_reader :value
|
|
54
|
+
compare_by :value
|
|
55
|
+
|
|
56
|
+
def initialize(value)
|
|
57
|
+
self.value = value
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @param bit_index [Integer]
|
|
61
|
+
# @return [EacRubyUtils::Bit]
|
|
62
|
+
def [](bit_index)
|
|
63
|
+
bit_get(bit_index)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @param bit_index [Integer]
|
|
67
|
+
# @return [EacRubyUtils::Bit]
|
|
68
|
+
def bit_get(bit_index)
|
|
69
|
+
self.class.validate_bit_index(bit_index)
|
|
70
|
+
|
|
71
|
+
::EacRubyUtils::Bit.new((value & (1 << bit_index)) >> bit_index)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def bit_set(bit_index, bit_value)
|
|
75
|
+
self.class.validate_bit_index(bit_index)
|
|
76
|
+
bit = ::EacRubyUtils::Bit.assert(bit_value)
|
|
77
|
+
mask = (1 << bit_index)
|
|
78
|
+
self.class.new(bit.zero? ? value & ~mask : value | mask)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @return [EacRubyUtils::BitArray]
|
|
82
|
+
def to_bit_array(range = BIT_INDEX_RANGE)
|
|
83
|
+
::EacRubyUtils::BitArray.new(range.map { |bit_index| self[bit_index] })
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @return [Integer]
|
|
87
|
+
def to_i
|
|
88
|
+
value
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @return [String]
|
|
92
|
+
def to_asm_hex
|
|
93
|
+
ASSEMBLY_HEXADECIMAL_PREFIX + to_hex
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# @return [String]
|
|
97
|
+
def to_hex
|
|
98
|
+
value.to_s(16).upcase.rjust(2, '0')
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
attr_writer :value
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/byte'
|
|
4
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
|
5
|
+
|
|
6
|
+
module EacRubyUtils
|
|
7
|
+
class ByteArray
|
|
8
|
+
delegate :to_a, :size, :count, :length, :[], :fetch, :map, to: :values_array
|
|
9
|
+
compare_by :values_array
|
|
10
|
+
|
|
11
|
+
def initialize(values = [])
|
|
12
|
+
values.each { |value| push(value) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def <<(value)
|
|
16
|
+
push(value)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param value [EacRubyUtils::Byte]
|
|
20
|
+
# @return [EacRubyUtils::Byte]
|
|
21
|
+
def push(value)
|
|
22
|
+
values_array.push(::EacRubyUtils::Byte.assert(value))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [Array<Integer>]
|
|
26
|
+
def to_int_array
|
|
27
|
+
values_array.map(&:to_i)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def values_array
|
|
33
|
+
@values_array ||= []
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -5,15 +5,23 @@ require 'open3'
|
|
|
5
5
|
module EacRubyUtils
|
|
6
6
|
module Envs
|
|
7
7
|
class Process
|
|
8
|
+
EXIT_CODE_KEY = :exit_code
|
|
9
|
+
ERR_KEY = :stderr
|
|
10
|
+
OUT_KEY = :stdout
|
|
11
|
+
|
|
8
12
|
def initialize(command)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
self.data = { command: command }
|
|
14
|
+
data[OUT_KEY], data[ERR_KEY], data[EXIT_CODE_KEY] = Open3.capture3(command)
|
|
15
|
+
data[EXIT_CODE_KEY] = data[EXIT_CODE_KEY].to_i
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def to_h
|
|
15
|
-
|
|
19
|
+
data.dup
|
|
16
20
|
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_accessor :data
|
|
17
25
|
end
|
|
18
26
|
end
|
|
19
27
|
end
|
|
@@ -11,4 +11,15 @@ class Object
|
|
|
11
11
|
"Argument \"#{argument_name}\" is not a #{klass}" \
|
|
12
12
|
"(Actual class: #{self.class}, actual value: #{self})"
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
# Raises a ArgumentError if +self.count+ is not equal to +count+.
|
|
16
|
+
#
|
|
17
|
+
# @return +self+
|
|
18
|
+
def assert_count(count, argument_name = 'unknown_argument_name')
|
|
19
|
+
return self if self.count == count
|
|
20
|
+
|
|
21
|
+
raise ::ArgumentError,
|
|
22
|
+
"Argument \"#{argument_name}\" has wrong elements count" \
|
|
23
|
+
"(Actual: #{self.count}, Required: #{count})"
|
|
24
|
+
end
|
|
14
25
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
5
|
+
class Pathname
|
|
6
|
+
# A .glob that raises a ::RuntimeError if +self+ is not a directory.
|
|
7
|
+
# @return [Pathname]
|
|
8
|
+
def reqdir_glob(*args)
|
|
9
|
+
raise ::RuntimeError, "\"#{self}\" is not a directory" unless directory?
|
|
10
|
+
|
|
11
|
+
glob(*args)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/bit_array'
|
|
4
|
+
|
|
5
|
+
RSpec.describe ::EacRubyUtils::BitArray do
|
|
6
|
+
describe '#to_byte_array' do
|
|
7
|
+
let(:instance) { described_class.new([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1]) }
|
|
8
|
+
|
|
9
|
+
{
|
|
10
|
+
false => [0xF0, 0xDC],
|
|
11
|
+
true => [0x0F, 0x3B]
|
|
12
|
+
}.each do |big_endian, expected_bytes|
|
|
13
|
+
context "when big-endian is #{big_endian}" do
|
|
14
|
+
let(:expected_value) { ::EacRubyUtils::ByteArray.new(expected_bytes) }
|
|
15
|
+
|
|
16
|
+
it do
|
|
17
|
+
expect(instance.to_byte_array(big_endian)).to eq(expected_value)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/byte'
|
|
4
|
+
|
|
5
|
+
RSpec.describe ::EacRubyUtils::Byte do
|
|
6
|
+
describe '#[]' do
|
|
7
|
+
let(:instance) { described_class.new(0xDC) }
|
|
8
|
+
|
|
9
|
+
[0, 0, 1, 1, 1, 0, 1, 1].each_with_index do |bit_value, bit_index|
|
|
10
|
+
context "when bit index is #{bit_index}" do
|
|
11
|
+
it { expect(instance[bit_index].value).to eq(bit_value) }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#bit_set' do
|
|
17
|
+
let(:instance) { described_class.new(0b11011100) }
|
|
18
|
+
|
|
19
|
+
{
|
|
20
|
+
0 => [0b11011100, 0b11011100, 0b11011000, 0b11010100,
|
|
21
|
+
0b11001100, 0b11011100, 0b10011100, 0b01011100],
|
|
22
|
+
1 => [0b11011101, 0b11011110, 0b11011100, 0b11011100,
|
|
23
|
+
0b11011100, 0b11111100, 0b11011100, 0b11011100]
|
|
24
|
+
}.each do |bit_value, expected_values|
|
|
25
|
+
expected_values.each_with_index do |expected_value, bit_index|
|
|
26
|
+
context "when bit index is #{bit_index} and bit value is #{bit_value}" do
|
|
27
|
+
it do
|
|
28
|
+
expect(instance.bit_set(bit_index, bit_value))
|
|
29
|
+
.to eq(described_class.new(expected_value))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#from_bit_array' do
|
|
37
|
+
let(:bit_array) { [0, 0, 1, 1, 1, 0, 1, 1] }
|
|
38
|
+
|
|
39
|
+
{ false => 0b11011100, true => 0b00111011 }.each do |big_endian, expected_integer|
|
|
40
|
+
context "when big-endian is #{big_endian}" do
|
|
41
|
+
let(:expected_value) { described_class.new(expected_integer) }
|
|
42
|
+
|
|
43
|
+
it do
|
|
44
|
+
expect(described_class.from_bit_array(bit_array, big_endian)).to eq(expected_value)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it do
|
|
50
|
+
expect { described_class.from_bit_array([0, 0, 1, 1, 1, 0, 1]) }
|
|
51
|
+
.to raise_error(::ArgumentError)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/patches/pathname/basename_noext'
|
|
4
|
+
|
|
5
|
+
RSpec.describe ::Pathname do
|
|
6
|
+
describe '#basename_noext' do
|
|
7
|
+
{
|
|
8
|
+
'After.Life.S01E01.WEBRip.x264-ION10.mp4' =>
|
|
9
|
+
%w[After.Life.S01E01.WEBRip.x264-ION10 After.Life.S01E01.WEBRip.x264-ION10.mp4
|
|
10
|
+
After.Life.S01E01.WEBRip.x264-ION10 After.Life.S01E01.WEBRip.x264-ION10],
|
|
11
|
+
's01e01.en.srt' => %w[s01e01 s01e01.en.srt s01e01.en s01e01 s01e01],
|
|
12
|
+
's01e01.srt' => %w[s01e01 s01e01.srt s01e01 s01e01 s01e01],
|
|
13
|
+
'/path/to/file.tar.gz' => %w[file file.tar.gz file.tar file file]
|
|
14
|
+
}.each do |source, expected_values|
|
|
15
|
+
expected_values.each_with_index do |expected_value, index|
|
|
16
|
+
limit = index - 1
|
|
17
|
+
context "when source is \"#{source}\" and limit is \"#{limit}\"" do
|
|
18
|
+
let(:instance) { described_class.new(source) }
|
|
19
|
+
let(:expected_path) { described_class.new(expected_value) }
|
|
20
|
+
|
|
21
|
+
it { expect(instance.basename_noext(limit)).to eq(expected_path) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: avm-tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.115.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: 2022-
|
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aranha-parsers
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.
|
|
33
|
+
version: '0.17'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.
|
|
40
|
+
version: '0.17'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: avm-eac_asciidoctor_base0
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.2'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.2'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: avm-eac_redmine_base0
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -460,6 +460,7 @@ files:
|
|
|
460
460
|
- sub/avm-eac_postgresql_base0/avm-eac_postgresql_base0.gemspec
|
|
461
461
|
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0.rb
|
|
462
462
|
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb
|
|
463
|
+
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb
|
|
463
464
|
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/data_unit.rb
|
|
464
465
|
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance_with.rb
|
|
465
466
|
- sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb
|
|
@@ -740,6 +741,7 @@ files:
|
|
|
740
741
|
- sub/avm/lib/avm/sources.rb
|
|
741
742
|
- sub/avm/lib/avm/sources/base.rb
|
|
742
743
|
- sub/avm/lib/avm/sources/base/configuration.rb
|
|
744
|
+
- sub/avm/lib/avm/sources/base/instance.rb
|
|
743
745
|
- sub/avm/lib/avm/sources/base/testing.rb
|
|
744
746
|
- sub/avm/lib/avm/sources/configuration.rb
|
|
745
747
|
- sub/avm/lib/avm/sources/configuration/_locale.rb
|
|
@@ -1195,9 +1197,13 @@ files:
|
|
|
1195
1197
|
- sub/eac_ruby_utils/lib/eac_ruby_utils.rb
|
|
1196
1198
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb
|
|
1197
1199
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb
|
|
1200
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/bit.rb
|
|
1201
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/bit_array.rb
|
|
1198
1202
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb
|
|
1199
1203
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
|
|
1200
1204
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb
|
|
1205
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/byte.rb
|
|
1206
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/byte_array.rb
|
|
1201
1207
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb
|
|
1202
1208
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
|
|
1203
1209
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
|
|
@@ -1298,11 +1304,13 @@ files:
|
|
|
1298
1304
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb
|
|
1299
1305
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_uri.rb
|
|
1300
1306
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb
|
|
1307
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_noext.rb
|
|
1301
1308
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb
|
|
1302
1309
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/if_exist.rb
|
|
1303
1310
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/mkpath_s.rb
|
|
1304
1311
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/parent_n.rb
|
|
1305
1312
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/readlink_r.rb
|
|
1313
|
+
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb
|
|
1306
1314
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb
|
|
1307
1315
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb
|
|
1308
1316
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/to_parser.rb
|
|
@@ -1335,7 +1343,9 @@ files:
|
|
|
1335
1343
|
- sub/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb
|
|
1336
1344
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb
|
|
1337
1345
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb
|
|
1346
|
+
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/bit_array_spec.rb
|
|
1338
1347
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb
|
|
1348
|
+
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/byte_spec.rb
|
|
1339
1349
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb
|
|
1340
1350
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb
|
|
1341
1351
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compact_spec.rb
|
|
@@ -1366,6 +1376,7 @@ files:
|
|
|
1366
1376
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/compact_spec.rb
|
|
1367
1377
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb
|
|
1368
1378
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec_files/path/my_stub_with_template
|
|
1379
|
+
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_noext_spec.rb
|
|
1369
1380
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb
|
|
1370
1381
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/parent_n_spec.rb
|
|
1371
1382
|
- sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/string/delimited_spec.rb
|