liri 0.3.1 → 0.4.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/.gitignore +2 -2
- data/Gemfile.lock +14 -7
- data/Rakefile +5 -0
- data/lib/agent/agent.rb +74 -41
- data/lib/all_libraries.rb +3 -0
- data/lib/common/benchmarking.rb +2 -8
- data/lib/common/compressor/zip.rb +3 -2
- data/lib/common/duration.rb +28 -0
- data/lib/common/hardware.rb +29 -0
- data/lib/common/log.rb +59 -17
- data/lib/common/progressbar.rb +3 -3
- data/lib/common/source_code.rb +2 -2
- data/lib/common/tests_result.rb +28 -16
- data/lib/common/text_time_parser.rb +6 -2
- data/lib/common/tty_progressbar.rb +70 -0
- data/lib/common/unit_test/rspec_result_parser.rb +10 -0
- data/lib/hash_extend.rb +7 -0
- data/lib/liri.rb +23 -23
- data/lib/manager/credential.rb +14 -0
- data/lib/manager/manager.rb +375 -133
- data/lib/task.rb +1 -1
- data/liri.gemspec +6 -6
- data/template/liri-config.yml +74 -36
- metadata +12 -10
- data/config/locales/to_duration_es.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d28f136456100f5326e4434296950754e7ec7246504de6152ae0941e3955dc35
|
4
|
+
data.tar.gz: b91ee07874e27b8dce462a593c8cde523da893355fd1fcbf12a362e0903af306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b42a37864b77d875ae48576a54199f244326d2b2132bcbebc35412f19a805634ac65aca61d3dd172c40c6c21eeea21059b97288af979abb65aed1d4c87ee69a1
|
7
|
+
data.tar.gz: 575c5765c9aa4a2f558a6ee2a33b1559babb85c3ca5849aaa32f93ea65f98b647893683680a96658f2947baebdf2ff86de015235e2b94feba4b1788b89983491
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
liri (0.
|
4
|
+
liri (0.4.0)
|
5
|
+
chronic_duration (~> 0)
|
5
6
|
commander (~> 4)
|
6
7
|
highline (~> 2)
|
7
|
-
i18n (~> 1)
|
8
8
|
net-scp (~> 3)
|
9
9
|
ruby-progressbar (~> 1)
|
10
10
|
rubyzip (~> 2)
|
11
11
|
terminal-table (~> 3)
|
12
|
-
|
12
|
+
tty-progressbar (~> 0)
|
13
13
|
|
14
14
|
GEM
|
15
15
|
remote: https://rubygems.org/
|
@@ -21,12 +21,13 @@ GEM
|
|
21
21
|
descendants_tracker (~> 0.0.4)
|
22
22
|
ice_nine (~> 0.11.0)
|
23
23
|
thread_safe (~> 0.3, >= 0.3.1)
|
24
|
+
chronic_duration (0.10.6)
|
25
|
+
numerizer (~> 0.1.1)
|
24
26
|
coderay (1.1.3)
|
25
27
|
coercible (1.0.0)
|
26
28
|
descendants_tracker (~> 0.0.1)
|
27
29
|
commander (4.6.0)
|
28
30
|
highline (~> 2.0.0)
|
29
|
-
concurrent-ruby (1.1.9)
|
30
31
|
descendants_tracker (0.0.4)
|
31
32
|
thread_safe (~> 0.3, >= 0.3.1)
|
32
33
|
diff-lcs (1.4.4)
|
@@ -43,8 +44,6 @@ GEM
|
|
43
44
|
ruby_parser (~> 3.1, > 3.1.0)
|
44
45
|
sexp_processor (~> 4.8)
|
45
46
|
highline (2.0.3)
|
46
|
-
i18n (1.10.0)
|
47
|
-
concurrent-ruby (~> 1.0)
|
48
47
|
ice_nine (0.11.2)
|
49
48
|
kwalify (0.7.2)
|
50
49
|
launchy (2.5.0)
|
@@ -52,6 +51,7 @@ GEM
|
|
52
51
|
net-scp (3.0.0)
|
53
52
|
net-ssh (>= 2.6.5, < 7.0.0)
|
54
53
|
net-ssh (6.1.0)
|
54
|
+
numerizer (0.1.1)
|
55
55
|
parallel (1.22.1)
|
56
56
|
parser (3.1.2.0)
|
57
57
|
ast (~> 2.4.1)
|
@@ -111,10 +111,17 @@ GEM
|
|
111
111
|
simplecov_json_formatter (~> 0.1)
|
112
112
|
simplecov-html (0.12.3)
|
113
113
|
simplecov_json_formatter (0.1.4)
|
114
|
+
strings-ansi (0.2.0)
|
114
115
|
terminal-table (3.0.2)
|
115
116
|
unicode-display_width (>= 1.1.1, < 3)
|
116
117
|
thread_safe (0.3.6)
|
117
|
-
|
118
|
+
tty-cursor (0.7.1)
|
119
|
+
tty-progressbar (0.18.2)
|
120
|
+
strings-ansi (~> 0.2)
|
121
|
+
tty-cursor (~> 0.7)
|
122
|
+
tty-screen (~> 0.8)
|
123
|
+
unicode-display_width (>= 1.6, < 3.0)
|
124
|
+
tty-screen (0.8.1)
|
118
125
|
tty-which (0.4.2)
|
119
126
|
unicode-display_width (2.1.0)
|
120
127
|
virtus (1.0.5)
|
data/Rakefile
CHANGED
@@ -47,6 +47,11 @@ task :install => [:build, :update_agent_installer, :compress_agent_installer] do
|
|
47
47
|
system "gem install " + Liri::NAME + "-" + Liri::VERSION + ".gem"
|
48
48
|
end
|
49
49
|
|
50
|
+
# Borra la gema despues de llamar a la tarea install
|
51
|
+
Rake::Task[:install].enhance do
|
52
|
+
Rake::Task[:clean].invoke
|
53
|
+
end
|
54
|
+
|
50
55
|
# Publica la gema después de compilar.
|
51
56
|
# > rake publish
|
52
57
|
task :publish => :build do
|
data/lib/agent/agent.rb
CHANGED
@@ -16,39 +16,39 @@ module Liri
|
|
16
16
|
agent_folder_path = setup_manager.agent_folder_path
|
17
17
|
|
18
18
|
Liri.set_logger(setup_manager.logs_folder_path, 'liriagent.log')
|
19
|
-
Liri.logger.info("Agent process started")
|
19
|
+
Liri.logger.info("Agent process started", true)
|
20
20
|
Liri.logger.info("Press Ctrl + c to finish Agent process manually\n", true)
|
21
21
|
|
22
|
-
|
23
|
-
source_code = Common::SourceCode.new(decompressed_source_code_path, agent_folder_path, Liri.compression_class, Liri.unit_test_class)
|
24
|
-
runner = Agent::Runner.new(Liri.unit_test_class, source_code.decompressed_file_folder_path)
|
25
|
-
tests_result = Common::TestsResult.new(agent_folder_path)
|
26
|
-
agent = Agent.new(Liri.udp_port, Liri.tcp_port, source_code, runner, tests_result, agent_folder_path)
|
22
|
+
agent = Agent.new(Liri.udp_port, Liri.tcp_port, agent_folder_path)
|
27
23
|
threads = []
|
28
24
|
threads << agent.start_server_socket_to_process_manager_connection_request # Esperar y procesar la petición de conexión del Manager
|
29
25
|
|
30
|
-
Liri.init_exit(stop, threads
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
Liri.
|
26
|
+
Liri.init_exit(stop, threads)
|
27
|
+
rescue SignalException
|
28
|
+
Liri.logger.info("Agent process finished manually", true)
|
29
|
+
rescue InxiCommandNotFoundError => e
|
30
|
+
Liri.logger.error("Exception(#{e}) Please, install inxi in your operating system", true)
|
31
|
+
ensure
|
32
|
+
# Siempre se ejecutan estos comandos, haya o no excepción
|
33
|
+
Liri.kill(threads) if threads && threads.any?
|
34
|
+
Liri.logger.info("Agent process finished", true)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def initialize(udp_port, tcp_port,
|
38
|
+
def initialize(udp_port, tcp_port, agent_folder_path)
|
39
39
|
@udp_port = udp_port
|
40
40
|
@udp_socket = UDPSocket.new
|
41
41
|
@tcp_port = tcp_port
|
42
42
|
|
43
|
-
@source_code = source_code
|
44
|
-
@runner = runner
|
45
|
-
@tests_result = tests_result
|
46
|
-
|
47
43
|
@all_tests = {}
|
48
44
|
|
49
45
|
@managers = {}
|
50
46
|
|
51
47
|
@agent_folder_path = agent_folder_path
|
48
|
+
|
49
|
+
@processing = true
|
50
|
+
|
51
|
+
@hardware_specs = hardware_specs
|
52
52
|
end
|
53
53
|
|
54
54
|
# Inicia un servidor udp que se mantiene en espera de la primera petición de conexión del Manager
|
@@ -60,15 +60,17 @@ module Liri
|
|
60
60
|
begin
|
61
61
|
@udp_socket.bind('0.0.0.0', @udp_port)
|
62
62
|
rescue Errno::EADDRINUSE => e
|
63
|
-
Liri.logger.error("Exception(#{e}) Busy UDP port #{@udp_port}")
|
63
|
+
Liri.logger.error("Exception(#{e}) Busy UDP port #{@udp_port}", true)
|
64
64
|
Thread.exit
|
65
65
|
end
|
66
66
|
Liri.logger.info("Waiting managers request in UDP port #{@udp_port}")
|
67
67
|
|
68
|
-
|
68
|
+
while @processing
|
69
69
|
@manager_request = @udp_socket.recvfrom(1024)
|
70
70
|
manager_ip_address = @manager_request.last.last
|
71
71
|
manager_data = get_manager_data(JSON.parse(@manager_request.first))
|
72
|
+
# TODO: El cliente TCP debería inicicarse en otro hilo, de este modo se tendrá un cliente TCP para cada Manager
|
73
|
+
# y se evita que un mismo cliente procese la ejecución de varios Manager
|
72
74
|
process_manager_connection_request(manager_ip_address, manager_data)
|
73
75
|
end
|
74
76
|
end
|
@@ -78,7 +80,13 @@ module Liri
|
|
78
80
|
def start_client_socket_to_process_tests(manager_ip_address, manager_data)
|
79
81
|
tcp_socket = TCPSocket.open(manager_ip_address, @tcp_port)
|
80
82
|
agent_ip_address = tcp_socket.addr[2]
|
81
|
-
tcp_socket.puts({ msg: 'get_source_code',
|
83
|
+
tcp_socket.puts({ msg: 'get_source_code', hardware_specs: @hardware_specs }.to_json)
|
84
|
+
|
85
|
+
# Las siguientes variables se usan para guardar momentaneamente los resultados mientras se hace un chequeo de que
|
86
|
+
# el Manager siga ejecutandose o que ya no haya procesado los mismos tests ya ejecutados por otro agente
|
87
|
+
tests_result_file_name = ""
|
88
|
+
tests_result_file_path = ""
|
89
|
+
tests_result = {}
|
82
90
|
|
83
91
|
while line = tcp_socket.gets
|
84
92
|
tcp_socket_data = JSON.parse(line.chop)
|
@@ -89,6 +97,7 @@ module Liri
|
|
89
97
|
end
|
90
98
|
|
91
99
|
if msg == 'proceed_get_source_code'
|
100
|
+
init_work_folders(manager_ip_address)
|
92
101
|
result = get_source_code(manager_ip_address, manager_data)
|
93
102
|
tcp_socket.puts({ msg: result }.to_json)
|
94
103
|
end
|
@@ -96,32 +105,35 @@ module Liri
|
|
96
105
|
if msg == 'process_tests'
|
97
106
|
tests_batch = tcp_socket_data
|
98
107
|
tests = get_tests(tests_batch, manager_ip_address)
|
99
|
-
raw_tests_result = @runner.run_tests(tests)
|
100
|
-
tests_batch_number = tests_batch['tests_batch_number']
|
101
|
-
tests_result_file_name = @tests_result.build_file_name(agent_ip_address, tests_batch_number)
|
102
|
-
tests_result_file_path = @tests_result.save(tests_result_file_name, raw_tests_result)
|
103
108
|
|
109
|
+
compressed_file_folder_path = @managers[manager_ip_address][:compressed_file_folder_path]
|
110
|
+
decompressed_file_folder_path = @managers[manager_ip_address][:decompressed_file_folder_path]
|
111
|
+
|
112
|
+
runner = Agent::Runner.new(Liri.unit_test_class, decompressed_file_folder_path)
|
113
|
+
raw_tests_result = runner.run_tests(tests)
|
114
|
+
batch_num = tests_batch['batch_num']
|
115
|
+
tests_result = Common::TestsResult.new(compressed_file_folder_path)
|
116
|
+
tests_result_file_name = tests_result.build_file_name(agent_ip_address, batch_num)
|
117
|
+
tests_result_file_path = tests_result.save(tests_result_file_name, raw_tests_result)
|
118
|
+
# TODO No se debería enviar el resultado si otro agente ya lo procesó, porque osinó reemplazaría el archivo de resultados
|
119
|
+
# ya procesado. ACTUALIZACION: Puede que esto ya se haya arreglado
|
104
120
|
send_tests_results_file(manager_ip_address, manager_data, tests_result_file_path)
|
105
|
-
|
106
|
-
tcp_socket.puts(
|
121
|
+
tests_result = { msg: 'processed_tests', batch_num: batch_num, tests_result_file_name: tests_result_file_name}
|
122
|
+
tcp_socket.puts(tests_result.to_json) # Envía el número de lote y el nombre del archivo de resultados.
|
107
123
|
end
|
108
124
|
end
|
109
125
|
|
110
|
-
Liri.logger.info("Finish connection with Manager #{manager_ip_address} in TCP port: #{@tcp_port}")
|
111
126
|
tcp_socket.close
|
112
|
-
Liri.clean_folder_content(@agent_folder_path)
|
113
|
-
|
114
127
|
unregister_manager(manager_ip_address)
|
115
128
|
rescue Errno::EADDRINUSE => e
|
116
129
|
Liri.logger.error("Exception(#{e}) Busy UDP port #{@udp_port}")
|
130
|
+
@processing = false
|
117
131
|
rescue Errno::ECONNRESET => e
|
118
132
|
tcp_socket.close
|
119
|
-
Liri.logger.error("Exception(#{e}) Closed connection in TCP port #{@tcp_port}")
|
120
|
-
Liri.logger.info("Finish connection with Manager #{manager_ip_address} in TCP port: #{@tcp_port}")
|
133
|
+
Liri.logger.error("Exception(#{e}) Closed connection in TCP port #{@tcp_port}", true)
|
121
134
|
unregister_manager(manager_ip_address)
|
122
135
|
rescue Errno::ECONNREFUSED => e
|
123
|
-
Liri.logger.error("Exception(#{e}) Rejected connection in TCP port #{@tcp_port}")
|
124
|
-
Liri.logger.info("Finish connection with Manager #{manager_ip_address} in TCP port: #{@tcp_port}")
|
136
|
+
Liri.logger.error("Exception(#{e}) Rejected connection in TCP port #{@tcp_port}", true)
|
125
137
|
unregister_manager(manager_ip_address)
|
126
138
|
end
|
127
139
|
|
@@ -140,25 +152,29 @@ module Liri
|
|
140
152
|
|
141
153
|
def get_source_code(manager_ip_address, manager_data)
|
142
154
|
puts ''
|
155
|
+
compressed_file_folder_path = @managers[manager_ip_address][:compressed_file_folder_path]
|
156
|
+
decompressed_file_folder_path = @managers[manager_ip_address][:decompressed_file_folder_path]
|
157
|
+
source_code = Liri::Common::SourceCode.new(decompressed_file_folder_path,compressed_file_folder_path, "", Liri.compression_class, Liri.unit_test_class)
|
158
|
+
|
143
159
|
Liri::Common::Benchmarking.start(start_msg: "Getting source code. Wait... ", stdout: true) do
|
144
160
|
puts ''
|
145
161
|
Net::SCP.start(manager_ip_address, manager_data.user, password: manager_data.password) do |scp|
|
146
|
-
scp.download!(manager_data.compressed_file_path,
|
162
|
+
scp.download!(manager_data.compressed_file_path, compressed_file_folder_path)
|
147
163
|
end
|
148
164
|
end
|
149
165
|
puts ''
|
150
166
|
|
151
167
|
downloaded_file_name = manager_data.compressed_file_path.split('/').last
|
152
|
-
downloaded_file_path = File.join(
|
168
|
+
downloaded_file_path = File.join(compressed_file_folder_path, '/', downloaded_file_name)
|
153
169
|
|
154
170
|
Liri::Common::Benchmarking.start(start_msg: "Uncompressing source code. Wait... ", stdout: true) do
|
155
|
-
|
156
|
-
@all_tests =
|
171
|
+
source_code.decompress_file(downloaded_file_path)
|
172
|
+
@all_tests = source_code.all_tests
|
157
173
|
end
|
158
174
|
puts ''
|
159
175
|
|
160
176
|
# Se cambia temporalmente la carpeta de trabajo a la carpeta de código fuente descomprimida
|
161
|
-
Dir.chdir(
|
177
|
+
Dir.chdir(decompressed_file_folder_path) do
|
162
178
|
# Se borra el directorio .git para evitar el siguiente error al ejecutar las pruebas: fatal: not a git repository (or any of the parent directories): .git
|
163
179
|
# Una mejor alternativa es no traer siquiera esa carpeta junto al código fuente excluyendo la carpeta .git al comprimir el código fuente.
|
164
180
|
# Por cuestiones de tiempo se procede a borrar la carpeta .git por ahora, aunque al parecer el error mostrado no afecta la ejecución del Agent
|
@@ -235,9 +251,8 @@ module Liri
|
|
235
251
|
tests_keys.map { |test_key| @all_tests[test_key] }
|
236
252
|
end
|
237
253
|
|
238
|
-
def
|
239
|
-
|
240
|
-
hardware_model.strip[0..14] # remove \n from string
|
254
|
+
def hardware_specs
|
255
|
+
"#{Common::Hardware.cpu} #{Common::Hardware.memory}GB"
|
241
256
|
end
|
242
257
|
|
243
258
|
def registered_manager?(manager_ip_address)
|
@@ -245,11 +260,29 @@ module Liri
|
|
245
260
|
end
|
246
261
|
|
247
262
|
def register_manager(manager_ip_address)
|
248
|
-
|
263
|
+
unless registered_manager?(manager_ip_address)
|
264
|
+
@managers[manager_ip_address] = {
|
265
|
+
manager_ip_address: @managers[manager_ip_address]
|
266
|
+
}
|
267
|
+
end
|
249
268
|
end
|
250
269
|
|
251
270
|
def unregister_manager(manager_ip_address)
|
252
271
|
@managers.remove!(manager_ip_address)
|
272
|
+
Liri.logger.info("Finish connection with Manager #{manager_ip_address} in TCP port: #{@tcp_port}")
|
273
|
+
end
|
274
|
+
|
275
|
+
def init_work_folders(manager_ip_address)
|
276
|
+
return if @managers[manager_ip_address][:compressed_file_folder_path]
|
277
|
+
|
278
|
+
compressed_file_folder_path = File.join(@agent_folder_path, '/', "#{DateTime.now.strftime("%d_%m_%y_%H_%M_%S")}_work")
|
279
|
+
Dir.mkdir(compressed_file_folder_path) unless Dir.exist?(compressed_file_folder_path)
|
280
|
+
decompressed_file_folder_path = File.join(compressed_file_folder_path, '/', Common::SourceCode::DECOMPRESSED_FOLDER_NAME)
|
281
|
+
|
282
|
+
@managers[manager_ip_address] = {
|
283
|
+
compressed_file_folder_path: compressed_file_folder_path,
|
284
|
+
decompressed_file_folder_path: decompressed_file_folder_path
|
285
|
+
}
|
253
286
|
end
|
254
287
|
end
|
255
288
|
end
|
data/lib/all_libraries.rb
CHANGED
@@ -19,9 +19,12 @@ require 'agent/agent'
|
|
19
19
|
require 'agent/runner'
|
20
20
|
|
21
21
|
require 'common/benchmarking'
|
22
|
+
require 'common/duration'
|
23
|
+
require 'common/hardware'
|
22
24
|
require 'common/log'
|
23
25
|
require 'common/manager_data'
|
24
26
|
require 'common/progressbar'
|
27
|
+
require 'common/tty_progressbar'
|
25
28
|
require 'common/setup'
|
26
29
|
require 'common/source_code'
|
27
30
|
require 'common/compressor/zip'
|
data/lib/common/benchmarking.rb
CHANGED
@@ -4,13 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# @author Rodrigo Fernández
|
6
6
|
|
7
|
-
require
|
8
|
-
require 'i18n' # requerimiento de la gema to_duration
|
9
|
-
require 'to_duration'
|
10
|
-
|
11
|
-
# Se configura la ubicación del archivo de internacionalización de la gema to_duration
|
12
|
-
I18n.load_path << Dir["#{File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'config/locales')}/*.yml"]
|
13
|
-
I18n.default_locale = :es
|
7
|
+
require "benchmark"
|
14
8
|
|
15
9
|
module Liri
|
16
10
|
module Common
|
@@ -23,7 +17,7 @@ module Liri
|
|
23
17
|
|
24
18
|
seconds = Benchmark.realtime(&block)
|
25
19
|
|
26
|
-
Liri.logger.info("#{end_msg}#{seconds.
|
20
|
+
Liri.logger.info("#{end_msg}#{Duration.humanize(seconds, times_round: Liri.times_round, times_round_type: Liri.times_round_type)}", stdout)
|
27
21
|
seconds
|
28
22
|
end
|
29
23
|
end
|
@@ -8,15 +8,16 @@ module Liri
|
|
8
8
|
module Compressor
|
9
9
|
class Zip
|
10
10
|
# Inicializa la carpeta a comprimir y la ubicación en donde se guardará el archivo comprimido
|
11
|
-
def initialize(input_dir, output_file)
|
11
|
+
def initialize(input_dir, output_file, ignored_folders)
|
12
12
|
@input_dir = input_dir
|
13
13
|
@output_file = output_file
|
14
|
+
@ignored_folders = ignored_folders.split(",")
|
14
15
|
end
|
15
16
|
|
16
17
|
# Comprime el directorio de entrada @input_dir en un archivo con extensión zip.
|
17
18
|
def compress
|
18
19
|
clear_output_file
|
19
|
-
entries = Dir.entries(@input_dir) - %w[. ..]
|
20
|
+
entries = Dir.entries(@input_dir) - (%w[. ..] + @ignored_folders)
|
20
21
|
|
21
22
|
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile|
|
22
23
|
write_entries(entries, '', zipfile)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# = duration.rb
|
4
|
+
#
|
5
|
+
# @author Rodrigo Fernández
|
6
|
+
|
7
|
+
require "chronic_duration"
|
8
|
+
|
9
|
+
module Liri
|
10
|
+
module Common
|
11
|
+
# == Módulo Duration
|
12
|
+
# Este módulo se encarga de convertir el tiempo en segundos a un formato legible
|
13
|
+
module Duration
|
14
|
+
class << self
|
15
|
+
def humanize(time, times_round:, times_round_type:)
|
16
|
+
# El time puede ser un BigDecimal y aunque se redondee puede responder con un formato 0.744e2, por eso
|
17
|
+
# es imporantes hacerle un to_f para convertirlo a 74.4 antes de proceder a humanizarlo
|
18
|
+
time = time.to_f
|
19
|
+
case times_round_type
|
20
|
+
when :floor then ChronicDuration.output(time.truncate(times_round), format: :short, keep_zero: true)
|
21
|
+
when :roof then ChronicDuration.output(time.round(times_round), format: :short, keep_zero: true)
|
22
|
+
else raise "Invalid times_round_type. Expected: floor or roof. Received: #{times_round_type}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# = hardware.rb
|
2
|
+
#
|
3
|
+
# @author Rodrigo Fernández
|
4
|
+
|
5
|
+
module Liri
|
6
|
+
module Common
|
7
|
+
# == Módulo Hardware
|
8
|
+
# Este módulo se encarga de obtener información del hardware
|
9
|
+
module Hardware
|
10
|
+
class << self
|
11
|
+
def cpu
|
12
|
+
cpu = %x|inxi -C|
|
13
|
+
cpu = cpu.to_s.match(/model(.+)bits/)
|
14
|
+
cpu = cpu[1].gsub("12", "")
|
15
|
+
cpu = cpu.gsub(":", "")
|
16
|
+
cpu.strip
|
17
|
+
rescue Errno::ENOENT
|
18
|
+
raise InxiCommandNotFoundError.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def memory
|
22
|
+
memory = %x|grep MemTotal /proc/meminfo|
|
23
|
+
memory = memory.to_s.match(/(\d+)/)
|
24
|
+
(memory[1].to_i * 0.000001).to_i
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/common/log.rb
CHANGED
@@ -14,6 +14,8 @@ module Liri
|
|
14
14
|
FOLDER_PATH = File.join(Dir.pwd, "/#{FOLDER_NAME}")
|
15
15
|
FILE_NAME = 'liri.log'
|
16
16
|
|
17
|
+
attr_reader :folder_path
|
18
|
+
|
17
19
|
def initialize(shift_age, folder_path:, file_name:, stdout: true)
|
18
20
|
@stdout = stdout
|
19
21
|
@shift_age = shift_age
|
@@ -27,37 +29,37 @@ module Liri
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def debug(text, stdout = false)
|
30
|
-
puts(text) if stdout
|
32
|
+
puts(ColorizeText.debug(text)) if stdout
|
31
33
|
@stdout_logger.debug(text) if @stdout
|
32
34
|
@file_logger.debug(text)
|
33
35
|
end
|
34
36
|
|
35
37
|
def info(text, stdout = false)
|
36
|
-
puts(text) if stdout
|
38
|
+
puts(ColorizeText.default(text)) if stdout
|
37
39
|
@stdout_logger.info(text) if @stdout
|
38
40
|
@file_logger.info(text)
|
39
41
|
end
|
40
42
|
|
41
43
|
def warn(text, stdout = false)
|
42
|
-
puts(text) if stdout
|
44
|
+
puts(ColorizeText.warn(text)) if stdout
|
43
45
|
@stdout_logger.warn(text) if @stdout
|
44
46
|
@file_logger.warn(text)
|
45
47
|
end
|
46
48
|
|
47
49
|
def error(text, stdout = false)
|
48
|
-
puts(text) if stdout
|
50
|
+
puts(ColorizeText.error(text)) if stdout
|
49
51
|
@stdout_logger.error(text) if @stdout
|
50
52
|
@file_logger.error(text)
|
51
53
|
end
|
52
54
|
|
53
55
|
def fatal(text, stdout = false)
|
54
|
-
puts(text) if stdout
|
56
|
+
puts(ColorizeText.fatal(text)) if stdout
|
55
57
|
@stdout_logger.fatal(text) if @stdout
|
56
58
|
@file_logger.fatal(text)
|
57
59
|
end
|
58
60
|
|
59
61
|
def unknown(text, stdout = false)
|
60
|
-
puts(text) if stdout
|
62
|
+
puts(ColorizeText.unknown(text)) if stdout
|
61
63
|
@stdout_logger.unknown(text) if @stdout
|
62
64
|
@file_logger.unknown(text)
|
63
65
|
end
|
@@ -65,12 +67,12 @@ module Liri
|
|
65
67
|
private
|
66
68
|
def create_stdout_logger
|
67
69
|
@stdout_logger = Logger.new(STDOUT, @shift_age)
|
68
|
-
@stdout_logger.formatter = Liri::Common::LogFormatter.colorize(Liri.setup.log.stdout.colorize)
|
70
|
+
@stdout_logger.formatter = Liri::Common::LogFormatter.colorize(Liri.setup.general.log.stdout.colorize)
|
69
71
|
end
|
70
72
|
|
71
73
|
def create_file_logger
|
72
74
|
@file_logger = Logger.new(@file_path, @shift_age)
|
73
|
-
@file_logger.formatter = Liri::Common::LogFormatter.colorize(Liri.setup.log.file.colorize)
|
75
|
+
@file_logger.formatter = Liri::Common::LogFormatter.colorize(Liri.setup.general.log.file.colorize)
|
74
76
|
end
|
75
77
|
|
76
78
|
def create_log_folder
|
@@ -78,18 +80,58 @@ module Liri
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
83
|
+
class ColorizeText
|
84
|
+
COLORS = {
|
85
|
+
DEBUG: '0;36', # cyan
|
86
|
+
ERROR: '0;31', # red
|
87
|
+
INFO: '0;32', # green
|
88
|
+
WARN: '0;33', # orange
|
89
|
+
FATAL: '0;35', # pink
|
90
|
+
ANY: '0;36', # cyan
|
91
|
+
DEFAULT: '1;0' # white
|
92
|
+
}
|
93
|
+
|
94
|
+
class << self
|
95
|
+
def default(text)
|
96
|
+
colorize(text, :DEFAULT)
|
97
|
+
end
|
98
|
+
|
99
|
+
def debug(text)
|
100
|
+
colorize(text, :DEBUG)
|
101
|
+
end
|
102
|
+
|
103
|
+
def info(text)
|
104
|
+
colorize(text, :INFO)
|
105
|
+
end
|
106
|
+
|
107
|
+
def warn(text)
|
108
|
+
colorize(text, :WARN)
|
109
|
+
end
|
110
|
+
|
111
|
+
def error(text)
|
112
|
+
colorize(text, :ERROR)
|
113
|
+
end
|
114
|
+
|
115
|
+
def fatal(text)
|
116
|
+
colorize(text, :FATAL)
|
117
|
+
end
|
118
|
+
|
119
|
+
def unknown(text)
|
120
|
+
colorize(text, :ANY)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def colorize(text, color)
|
126
|
+
"\e[#{COLORS[color]}m#{text}\e[0m"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
81
131
|
class LogFormatter
|
82
132
|
DATETIME_FORMAT = "%d-%m-%Y %H:%M"
|
83
133
|
|
84
|
-
SEVERITY_COLORS =
|
85
|
-
DEBUG: '0;36', # cyan
|
86
|
-
ERROR: '0;31', # red
|
87
|
-
INFO: '0;32', # green
|
88
|
-
WARN: '0;33', # orange
|
89
|
-
FATAL: '0;35', # pink
|
90
|
-
ANY: '0;36', # cyan
|
91
|
-
DEFAULT: '1;0' # white
|
92
|
-
}
|
134
|
+
SEVERITY_COLORS = ColorizeText::COLORS
|
93
135
|
|
94
136
|
class << self
|
95
137
|
def colorize(type)
|
data/lib/common/progressbar.rb
CHANGED
@@ -12,16 +12,16 @@ module Liri
|
|
12
12
|
module Progressbar
|
13
13
|
class << self
|
14
14
|
def start(params = {})
|
15
|
-
@
|
15
|
+
@progressing = true
|
16
16
|
progressbar = ProgressBar.create(params)
|
17
17
|
Thread.new do
|
18
|
-
while @
|
18
|
+
while @progressing
|
19
19
|
progressbar.increment
|
20
20
|
sleep(0.1)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
yield
|
24
|
-
@
|
24
|
+
@progressing = false
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/common/source_code.rb
CHANGED
@@ -8,7 +8,7 @@ module Liri
|
|
8
8
|
DECOMPRESSED_FOLDER_NAME = 'decompressed'
|
9
9
|
attr_reader :folder_path, :compressed_file_folder_path, :compressed_file_path, :decompressed_file_folder_path
|
10
10
|
|
11
|
-
def initialize(folder_path, compressed_file_folder_path, compression_class, unit_test_class)
|
11
|
+
def initialize(folder_path, compressed_file_folder_path, ignored_folders, compression_class, unit_test_class)
|
12
12
|
@folder_path = folder_path
|
13
13
|
@folder_name = @folder_path.split('/').last
|
14
14
|
@compressed_file_folder_path = compressed_file_folder_path
|
@@ -17,7 +17,7 @@ module Liri
|
|
17
17
|
# Inicializa un compresor acorde a compression_class, la siguiente línea en realidad hace lo siguiente:
|
18
18
|
# @compressor = Liri::Common::Compressor::Zip.new(input_dir, output_file)
|
19
19
|
# compression_class en este caso es Zip pero podría ser otro si existiera la implementación, por ejemplo Rar
|
20
|
-
@compressor = Object.const_get(compression_class).new(@folder_path, @compressed_file_path)
|
20
|
+
@compressor = Object.const_get(compression_class).new(@folder_path, @compressed_file_path, ignored_folders)
|
21
21
|
# Inicializa un ejecutor de pruebas acorde a unit_test_class, la siguiente línea en realidad hace lo siguiente:
|
22
22
|
# @unit_test = Liri::Common::UnitTest::Rspec.new(source_code_folder_path)
|
23
23
|
# unit_test_class en este caso es Rspec pero podría ser otro si existiera la implementación, por ejemplo UnitTest
|