avm 0.73.1 → 0.75.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/data/dumper.rb +142 -0
- data/lib/avm/data/loader.rb +28 -0
- data/lib/avm/data/package/dump.rb +14 -80
- data/lib/avm/data/package/load.rb +10 -19
- data/lib/avm/data/package.rb +8 -12
- data/lib/avm/data/performer.rb +1 -1
- data/lib/avm/instances/data/package.rb +5 -0
- data/lib/avm/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 283b2992d153ecb696d270dca06440c1211ad0986d2bcccbba13d59880ec8241
|
4
|
+
data.tar.gz: df2da2e866a10834d9b2d7c07e921f332de3b64937592bad04eb0c334cd1b3a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57b1246b460a76df268e0b1021e27e7a38ba6056225b5c363fa8ad53b52d5ec09d092518709060cab4fc8b472cce619d8a8b84ed9ff398e502ee5b827613d40b
|
7
|
+
data.tar.gz: 4552cfce3a392507c560938a8ae956278fe03b335d50c5213e4aecfde007b5beaa66012fc0c32a24ab0736f2dae4b5b85e0b3310c7c803a96c6d74e240fae775
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/performer'
|
4
|
+
require 'avm/data/rotate'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'eac_ruby_utils/fs/temp'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Data
|
10
|
+
class Dumper < ::Avm::Data::Performer
|
11
|
+
DEFAULT_EXPIRE_TIME = 1.day
|
12
|
+
DEFAULT_OVERWRITE = false
|
13
|
+
DEFAULT_ROTATE = true
|
14
|
+
|
15
|
+
enable_speaker
|
16
|
+
enable_listable
|
17
|
+
immutable_accessor :expire_time, :target_path
|
18
|
+
immutable_accessor :overwrite, :rotate, type: :boolean
|
19
|
+
|
20
|
+
# @return [nil]
|
21
|
+
def cannot_perform_reason
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Pathname]
|
26
|
+
def default_dump_path
|
27
|
+
r = data_owner.data_default_dump_path
|
28
|
+
include_excludes_path_suffix.if_present(r) do |v|
|
29
|
+
r.basename_sub('.*') { |b| "#{b}#{v}#{r.extname}" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Boolean]
|
34
|
+
def target_path_expired?
|
35
|
+
target_path_time.if_present(true) { |v| v >= expire_time }
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [ActiveSupport::Duration, nil]
|
39
|
+
def target_path_time
|
40
|
+
target_path.exist? ? ::Time.now - ::File.mtime(target_path) : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
attr_reader :temp_data_path
|
46
|
+
|
47
|
+
# @return [Array<Symbol>]
|
48
|
+
def all_units
|
49
|
+
data_owner.units.keys.sort
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_temp_data_file
|
53
|
+
data_owner.dump(temp_data_path, *include_excludes_arguments)
|
54
|
+
raise "\"#{temp_data_path}\" do not exist" unless temp_data_path.exist?
|
55
|
+
raise "\"#{temp_data_path}\" is not a file" unless temp_data_path.file?
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [String, nil]
|
59
|
+
def do_rotate
|
60
|
+
return unless target_path.exist?
|
61
|
+
return unless rotate?
|
62
|
+
|
63
|
+
infom "Rotating \"#{target_path}\"..."
|
64
|
+
::Avm::Data::Rotate.new(target_path).run
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array<Symbol>]
|
68
|
+
def excluded_units
|
69
|
+
excludes.map(&:to_sym).sort
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [ActiveSupport::Duration]
|
73
|
+
def expire_time_get_filter(value)
|
74
|
+
value || DEFAULT_EXPIRE_TIME
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [String]
|
78
|
+
def include_excludes_path_suffix
|
79
|
+
return nil unless data_owner.respond_to?(:units)
|
80
|
+
|
81
|
+
r = included_units.any? ? included_units : all_units
|
82
|
+
r -= excluded_units if excluded_units.any?
|
83
|
+
r.any? && r != all_units ? "_#{r.join('-')}" : ''
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Array<Symbol>]
|
87
|
+
def included_units
|
88
|
+
includes.map(&:to_sym).sort
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [self]
|
92
|
+
def internal_perform
|
93
|
+
use_current? ? internal_perform_use_current : internal_perform_new
|
94
|
+
end
|
95
|
+
|
96
|
+
def internal_perform_new
|
97
|
+
on_temp_data_file do
|
98
|
+
build_temp_data_file
|
99
|
+
do_rotate
|
100
|
+
move_data_to_target_path
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def internal_perform_use_current
|
105
|
+
infom "Dump \"#{target_path}\" exists and is unexpired"
|
106
|
+
end
|
107
|
+
|
108
|
+
def move_data_to_target_path
|
109
|
+
::FileUtils.mv(temp_data_path, target_path.assert_parent)
|
110
|
+
end
|
111
|
+
|
112
|
+
def on_temp_data_file
|
113
|
+
::EacRubyUtils::Fs::Temp.on_file do |file|
|
114
|
+
@temp_data_path = file.to_pathname
|
115
|
+
yield
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Boolean]
|
120
|
+
def overwrite_get_filter(value)
|
121
|
+
value.nil? ? DEFAULT_OVERWRITE : value
|
122
|
+
end
|
123
|
+
|
124
|
+
def rotate_get_filter(value)
|
125
|
+
value.nil? ? DEFAULT_ROTATE : value
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [Pathname]
|
129
|
+
def target_path_get_filter(value)
|
130
|
+
(value || default_dump_path).to_pathname
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [Boolean]
|
134
|
+
def use_current?
|
135
|
+
return false unless target_path.exist?
|
136
|
+
return false if overwrite?
|
137
|
+
|
138
|
+
!target_path_expired?
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/performer'
|
4
|
+
require 'avm/data/rotate'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'eac_ruby_utils/fs/temp'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Data
|
10
|
+
class Loader < ::Avm::Data::Performer
|
11
|
+
immutable_accessor :source_path
|
12
|
+
|
13
|
+
# @return [String, nil]
|
14
|
+
def cannot_perform_reason
|
15
|
+
return 'Source path not set' if source_path.blank?
|
16
|
+
return "\"#{source_path}\" is not a file" unless source_path.file?
|
17
|
+
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def internal_perform
|
24
|
+
data_owner.load(source_path, *include_excludes_arguments)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,109 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avm/data/package/base_performer'
|
3
4
|
require 'avm/data/package/build_directory'
|
4
|
-
require 'avm/data/rotate'
|
5
5
|
require 'eac_ruby_utils/core_ext'
|
6
6
|
require 'minitar'
|
7
7
|
|
8
8
|
module Avm
|
9
9
|
module Data
|
10
10
|
class Package
|
11
|
-
class Dump
|
12
|
-
|
13
|
-
enable_listable
|
11
|
+
class Dump < ::Avm::Data::Package::BasePerformer
|
12
|
+
enable_method_class
|
14
13
|
include ::Avm::Data::Package::BuildDirectory
|
15
14
|
|
16
|
-
|
15
|
+
attr_reader :target_path
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def initialize(package, data_file_path, options = {})
|
23
|
-
@package = package
|
24
|
-
@data_file_path = data_file_path
|
25
|
-
options = options.to_options_consumer
|
26
|
-
@existing, @expire_time = options.consume(:existing, :expire_time)
|
27
|
-
options.validate
|
28
|
-
self.class.lists.existing.value_validate!(@existing)
|
29
|
-
end
|
30
|
-
|
31
|
-
def runnable?
|
32
|
-
cannot_run_reason.blank?
|
33
|
-
end
|
34
|
-
|
35
|
-
def cannot_run_reason
|
36
|
-
return nil if !data_file_exist? ||
|
37
|
-
[EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
|
38
|
-
|
39
|
-
if existing == EXISTING_DENIED
|
40
|
-
'Data exist and overwriting is denied'
|
41
|
-
elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired?
|
42
|
-
'Data exist and yet is not expired'
|
43
|
-
end
|
17
|
+
def initialize(package, target_path, options = {})
|
18
|
+
super(package, options)
|
19
|
+
@target_path = target_path.to_pathname
|
44
20
|
end
|
45
21
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
package_file = on_build_directory do
|
22
|
+
# @return [void]
|
23
|
+
def result
|
24
|
+
on_build_directory do
|
50
25
|
dump_units_to_build_directory
|
51
26
|
create_package_file
|
52
27
|
end
|
53
|
-
rotate
|
54
|
-
move_download_to_final_dest(package_file)
|
55
|
-
end
|
56
|
-
|
57
|
-
def data_file_exist?
|
58
|
-
::File.exist?(data_file_path)
|
59
|
-
end
|
60
|
-
|
61
|
-
def data_file_time
|
62
|
-
data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil
|
63
|
-
end
|
64
|
-
|
65
|
-
def data_file_expired?
|
66
|
-
data_file_time.if_present(false) { |v| v >= expire_time }
|
67
|
-
end
|
68
|
-
|
69
|
-
def expire_time
|
70
|
-
@expire_time || DEFAULT_EXPIRE_TIME
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def move_download_to_final_dest(download_path)
|
76
|
-
::FileUtils.mkdir_p(::File.dirname(data_file_path))
|
77
|
-
::FileUtils.mv(download_path, data_file_path)
|
78
|
-
end
|
79
|
-
|
80
|
-
def rotate
|
81
|
-
return unless data_file_exist?
|
82
|
-
return unless existing == EXISTING_ROTATE
|
83
|
-
|
84
|
-
infom "Rotating \"#{data_file_path}\"..."
|
85
|
-
::Avm::Data::Rotate.new(data_file_path).run
|
86
28
|
end
|
87
29
|
|
88
|
-
|
89
|
-
f = ::Tempfile.new(self.class.name.parameterize + '-download')
|
90
|
-
path = f.path
|
91
|
-
f.close
|
92
|
-
f.unlink
|
93
|
-
path
|
94
|
-
end
|
30
|
+
protected
|
95
31
|
|
96
32
|
def dump_units_to_build_directory
|
97
|
-
package.dump_units_to_directory(build_directory)
|
33
|
+
package.dump_units_to_directory(build_directory, selected_units)
|
98
34
|
end
|
99
35
|
|
100
36
|
def create_package_file
|
101
|
-
|
102
|
-
infom "Creating package \"#{package_path}\" from \"#{build_directory}\"..."
|
37
|
+
infom "Creating package \"#{target_path}\" from \"#{build_directory}\"..."
|
103
38
|
::Dir.chdir(build_directory.to_path) do
|
104
|
-
::Minitar.pack('.', File.open(
|
39
|
+
::Minitar.pack('.', ::File.open(target_path, 'wb'))
|
105
40
|
end
|
106
|
-
package_path
|
107
41
|
end
|
108
42
|
end
|
109
43
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avm/data/package/base_performer'
|
3
4
|
require 'avm/data/package/build_directory'
|
4
5
|
require 'eac_ruby_utils/core_ext'
|
5
6
|
require 'minitar'
|
@@ -7,37 +8,27 @@ require 'minitar'
|
|
7
8
|
module Avm
|
8
9
|
module Data
|
9
10
|
class Package
|
10
|
-
class Load
|
11
|
+
class Load < ::Avm::Data::Package::BasePerformer
|
12
|
+
enable_method_class
|
11
13
|
enable_speaker
|
12
14
|
include ::Avm::Data::Package::BuildDirectory
|
13
15
|
|
14
|
-
|
16
|
+
attr_reader :source_path
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
+
def initialize(package, source_path, options = {})
|
19
|
+
super(package, options)
|
20
|
+
@source_path = source_path.to_pathname
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
return nil if data_file_exist?
|
22
|
-
|
23
|
-
"Data file \"#{data_file_path}\" does not exist"
|
24
|
-
end
|
25
|
-
|
26
|
-
def run
|
27
|
-
raise "Cannot run: #{cannot_run_reason}" unless runnable?
|
28
|
-
|
23
|
+
def result
|
29
24
|
on_build_directory do
|
30
25
|
extract_packages_to_build_directory
|
31
|
-
package.load_units_from_directory(build_directory)
|
26
|
+
package.load_units_from_directory(build_directory, selected_units)
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
|
-
def data_file_exist?
|
36
|
-
::File.exist?(data_file_path)
|
37
|
-
end
|
38
|
-
|
39
30
|
def extract_packages_to_build_directory
|
40
|
-
::Minitar.unpack(
|
31
|
+
::Minitar.unpack(source_path.to_path, build_directory.to_path)
|
41
32
|
end
|
42
33
|
end
|
43
34
|
end
|
data/lib/avm/data/package.rb
CHANGED
@@ -32,23 +32,19 @@ module Avm
|
|
32
32
|
DATA_FILE_EXTENSION
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
::Avm::Data::Package::Dump.new(self, data_path, options)
|
37
|
-
end
|
38
|
-
|
39
|
-
def load(data_path)
|
40
|
-
::Avm::Data::Package::Load.new(self, data_path)
|
41
|
-
end
|
42
|
-
|
43
|
-
def dump_units_to_directory(directory)
|
35
|
+
def dump_units_to_directory(directory, selected_units = nil)
|
44
36
|
run_callbacks :dump do
|
45
|
-
units.each
|
37
|
+
(selected_units || units).each do |identifier, unit|
|
38
|
+
unit.dump_to_directory(directory, identifier)
|
39
|
+
end
|
46
40
|
end
|
47
41
|
end
|
48
42
|
|
49
|
-
def load_units_from_directory(directory)
|
43
|
+
def load_units_from_directory(directory, selected_units = nil)
|
50
44
|
run_callbacks :load do
|
51
|
-
units.each
|
45
|
+
(selected_units || units).each do |identifier, unit|
|
46
|
+
unit.load_from_directory(directory, identifier)
|
47
|
+
end
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
data/lib/avm/data/performer.rb
CHANGED
data/lib/avm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.75.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.19'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.19'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: eac_cli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,6 +233,8 @@ files:
|
|
233
233
|
- lib/avm/applications/base/stereotype.rb
|
234
234
|
- lib/avm/data/callbacks.rb
|
235
235
|
- lib/avm/data/clearer.rb
|
236
|
+
- lib/avm/data/dumper.rb
|
237
|
+
- lib/avm/data/loader.rb
|
236
238
|
- lib/avm/data/package.rb
|
237
239
|
- lib/avm/data/package/base_performer.rb
|
238
240
|
- lib/avm/data/package/build_directory.rb
|