avm-tools 0.7.0 → 0.8.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/files/rotate.rb +43 -5
- data/lib/avm/tools/runner/files/rotate.rb +15 -3
- data/lib/avm/tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec26f5acffe872504b8bb38a3ac9576c5e8a0371ed59bf47291bbaa7ee409e86
|
|
4
|
+
data.tar.gz: abff823fcf4d67c8585234b44bc02c09c71f5abfc4c07cb81879c12e6d207f30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21c93ff405233684dc17a31d1fcecaab294f04de974984745e48539099d88e09f3e1006f9e576a2b34205ebae75668c58a5286de1d7f72ec917ab4c43416e54c
|
|
7
|
+
data.tar.gz: 99e36aebae62dfd8d654177019156d9c7ba2dc187b778aad3b206da3e637657eb3f68bc968bb1293d717379d73447d19148d45114f41d738aeb17e48bfef2ddd
|
data/lib/avm/files/rotate.rb
CHANGED
|
@@ -8,10 +8,11 @@ module Avm
|
|
|
8
8
|
class Rotate
|
|
9
9
|
include ::EacRubyUtils::SimpleCache
|
|
10
10
|
|
|
11
|
-
attr_reader :source_path
|
|
11
|
+
attr_reader :options, :source_path
|
|
12
12
|
|
|
13
|
-
def initialize(source_path)
|
|
13
|
+
def initialize(source_path, options = {})
|
|
14
14
|
@source_path = source_path
|
|
15
|
+
@options = options
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def run
|
|
@@ -19,14 +20,47 @@ module Avm
|
|
|
19
20
|
return validate_msg if validate_msg.present?
|
|
20
21
|
|
|
21
22
|
::FileUtils.mv(source_path, target_path)
|
|
23
|
+
check_space_limit
|
|
22
24
|
nil
|
|
23
25
|
end
|
|
24
26
|
|
|
27
|
+
def space_limit
|
|
28
|
+
r = options[:space_limit].try(:to_i)
|
|
29
|
+
return r if r.present? && r.positive?
|
|
30
|
+
|
|
31
|
+
r
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def space_used
|
|
35
|
+
rotated_files.inject(0) { |a, e| a + ::File.size(e) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def rotated_files
|
|
39
|
+
::Dir["#{dirname}/#{source_basename_without_extension}*#{source_extension}"]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def oldest_rotated_file
|
|
43
|
+
rotated_files.min_by { |file| [::File.mtime(file)] }
|
|
44
|
+
end
|
|
45
|
+
|
|
25
46
|
private
|
|
26
47
|
|
|
48
|
+
def check_space_limit
|
|
49
|
+
return unless space_limit
|
|
50
|
+
|
|
51
|
+
while space_used > space_limit
|
|
52
|
+
file = oldest_rotated_file
|
|
53
|
+
unless file
|
|
54
|
+
raise 'oldest_rotated_file returned nil ' \
|
|
55
|
+
"(Limit: #{space_limit}, used: #{space_used})"
|
|
56
|
+
end
|
|
57
|
+
::File.delete(file)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
27
61
|
def validate
|
|
28
|
-
return
|
|
29
|
-
return
|
|
62
|
+
return "Source file \"#{source_path}\" does not exist" unless ::File.exist?(source_path)
|
|
63
|
+
return "File \"#{source_path}\" is already rotated" if source_rotated?
|
|
30
64
|
|
|
31
65
|
nil
|
|
32
66
|
end
|
|
@@ -44,7 +78,11 @@ module Avm
|
|
|
44
78
|
end
|
|
45
79
|
|
|
46
80
|
def target_path_uncached
|
|
47
|
-
::File.join(
|
|
81
|
+
::File.join(dirname, target_basename)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def dirname
|
|
85
|
+
::File.dirname(source_path)
|
|
48
86
|
end
|
|
49
87
|
|
|
50
88
|
def target_basename
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'eac_ruby_utils/console/docopt_runner'
|
|
4
|
+
require 'eac_ruby_utils/console/speaker'
|
|
4
5
|
require 'avm/files/rotate'
|
|
5
6
|
|
|
6
7
|
module Avm
|
|
@@ -8,19 +9,30 @@ module Avm
|
|
|
8
9
|
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
|
9
10
|
class Files < ::EacRubyUtils::Console::DocoptRunner
|
|
10
11
|
class Rotate < ::EacRubyUtils::Console::DocoptRunner
|
|
12
|
+
include ::EacRubyUtils::Console::Speaker
|
|
13
|
+
|
|
11
14
|
DOC = <<~DOCOPT
|
|
12
15
|
Rotates a file (Like a backup).
|
|
13
16
|
|
|
14
17
|
Usage:
|
|
15
|
-
__PROGRAM__ <path>
|
|
18
|
+
__PROGRAM__ [options] <path>
|
|
16
19
|
__PROGRAM__ -h | --help
|
|
17
20
|
|
|
18
21
|
Options:
|
|
19
|
-
-h --help
|
|
22
|
+
-h --help Show this screen.
|
|
23
|
+
-L --space-limit=<space> Limit by <space> the space used by rotated files.
|
|
20
24
|
DOCOPT
|
|
21
25
|
|
|
22
26
|
def run
|
|
23
|
-
|
|
27
|
+
error_message = rotate.run
|
|
28
|
+
fatal_error(error_message) if error_message
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def rotate
|
|
32
|
+
@rotate ||= ::Avm::Files::Rotate.new(
|
|
33
|
+
options.fetch('<path>'),
|
|
34
|
+
space_limit: options.fetch('--space-limit')
|
|
35
|
+
)
|
|
24
36
|
end
|
|
25
37
|
end
|
|
26
38
|
end
|
data/lib/avm/tools/version.rb
CHANGED
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.8.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: 2019-08-
|
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: eac_launcher
|