scout-gear 8.0.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vimproject +48 -9
- data/Rakefile +6 -1
- data/VERSION +1 -1
- data/bin/scout +16 -4
- data/doc/lib/scout/path.md +35 -0
- data/doc/lib/scout/workflow/task.md +13 -0
- data/lib/rbbt-scout.rb +2 -1
- data/lib/scout/cmd.rb +32 -29
- data/lib/scout/concurrent_stream.rb +36 -19
- data/lib/scout/exceptions.rb +10 -0
- data/lib/scout/indiferent_hash.rb +17 -0
- data/lib/scout/log/color.rb +11 -11
- data/lib/scout/log/progress/report.rb +8 -5
- data/lib/scout/log/progress/util.rb +3 -0
- data/lib/scout/log/trap.rb +3 -3
- data/lib/scout/log.rb +67 -36
- data/lib/scout/meta_extension.rb +34 -0
- data/lib/scout/misc/digest.rb +11 -2
- data/lib/scout/misc/filesystem.rb +2 -3
- data/lib/scout/misc/format.rb +12 -7
- data/lib/scout/misc/monitor.rb +11 -0
- data/lib/scout/misc/system.rb +48 -0
- data/lib/scout/named_array.rb +8 -0
- data/lib/scout/offsite/ssh.rb +174 -0
- data/lib/scout/offsite/step.rb +100 -0
- data/lib/scout/offsite/sync.rb +55 -0
- data/lib/scout/offsite.rb +3 -0
- data/lib/scout/open/lock.rb +5 -24
- data/lib/scout/open/remote.rb +12 -1
- data/lib/scout/open/stream.rb +109 -122
- data/lib/scout/open/util.rb +9 -0
- data/lib/scout/open.rb +12 -11
- data/lib/scout/path/find.rb +15 -10
- data/lib/scout/path/util.rb +5 -0
- data/lib/scout/path.rb +1 -1
- data/lib/scout/persist/serialize.rb +4 -4
- data/lib/scout/persist.rb +1 -1
- data/lib/scout/resource/open.rb +8 -0
- data/lib/scout/resource/path.rb +16 -9
- data/lib/scout/resource/software.rb +4 -2
- data/lib/scout/resource/util.rb +10 -4
- data/lib/scout/resource.rb +2 -0
- data/lib/scout/tsv/dumper.rb +5 -1
- data/lib/scout/tsv/index.rb +28 -86
- data/lib/scout/tsv/open.rb +35 -14
- data/lib/scout/tsv/parser.rb +22 -5
- data/lib/scout/tsv/persist/tokyocabinet.rb +2 -0
- data/lib/scout/tsv/stream.rb +204 -0
- data/lib/scout/tsv/transformer.rb +11 -0
- data/lib/scout/tsv.rb +9 -2
- data/lib/scout/work_queue/worker.rb +2 -2
- data/lib/scout/work_queue.rb +37 -12
- data/lib/scout/workflow/definition.rb +2 -1
- data/lib/scout/workflow/deployment/orchestrator.rb +254 -0
- data/lib/scout/workflow/deployment.rb +1 -0
- data/lib/scout/workflow/step/dependencies.rb +46 -14
- data/lib/scout/workflow/step/file.rb +5 -0
- data/lib/scout/workflow/step/info.rb +13 -3
- data/lib/scout/workflow/step/inputs.rb +5 -0
- data/lib/scout/workflow/step/load.rb +1 -1
- data/lib/scout/workflow/step/provenance.rb +1 -0
- data/lib/scout/workflow/step/status.rb +27 -9
- data/lib/scout/workflow/step.rb +82 -30
- data/lib/scout/workflow/task/dependencies.rb +116 -0
- data/lib/scout/workflow/task/inputs.rb +36 -17
- data/lib/scout/workflow/task.rb +12 -109
- data/lib/scout/workflow/usage.rb +57 -41
- data/lib/scout/workflow.rb +19 -13
- data/lib/scout-gear.rb +2 -0
- data/lib/scout.rb +6 -0
- data/scout-gear.gemspec +38 -7
- data/scout_commands/doc +37 -0
- data/scout_commands/find +1 -0
- data/scout_commands/offsite +30 -0
- data/scout_commands/resource/produce +66 -0
- data/scout_commands/template +52 -0
- data/scout_commands/update +29 -0
- data/scout_commands/workflow/info +15 -3
- data/scout_commands/workflow/install +105 -0
- data/scout_commands/workflow/task +46 -6
- data/share/software/install_helpers +2 -2
- data/share/templates/command +25 -0
- data/share/templates/workflow.rb +14 -0
- data/test/scout/offsite/test_ssh.rb +15 -0
- data/test/scout/offsite/test_step.rb +32 -0
- data/test/scout/offsite/test_sync.rb +36 -0
- data/test/scout/offsite/test_task.rb +0 -0
- data/test/scout/resource/test_path.rb +6 -0
- data/test/scout/test_named_array.rb +6 -0
- data/test/scout/test_persist.rb +3 -2
- data/test/scout/test_tsv.rb +17 -0
- data/test/scout/test_work_queue.rb +64 -42
- data/test/scout/tsv/persist/test_adapter.rb +1 -1
- data/test/scout/tsv/test_index.rb +14 -0
- data/test/scout/tsv/test_parser.rb +35 -0
- data/test/scout/tsv/test_stream.rb +200 -0
- data/test/scout/tsv/test_transformer.rb +12 -0
- data/test/scout/workflow/deployment/test_orchestrator.rb +272 -0
- data/test/scout/workflow/step/test_dependencies.rb +68 -0
- data/test/scout/workflow/step/test_info.rb +17 -0
- data/test/scout/workflow/step/test_status.rb +0 -1
- data/test/scout/workflow/task/test_dependencies.rb +357 -0
- data/test/scout/workflow/task/test_inputs.rb +52 -0
- data/test/scout/workflow/test_definition.rb +18 -0
- data/test/scout/workflow/test_documentation.rb +24 -0
- data/test/scout/workflow/test_step.rb +109 -0
- data/test/scout/workflow/test_task.rb +0 -287
- data/test/test_scout.rb +9 -0
- metadata +89 -5
- data/scout_commands/workflow/task_old +0 -706
data/lib/scout/log/color.rb
CHANGED
@@ -10,8 +10,8 @@ module Colorize
|
|
10
10
|
|
11
11
|
def self.colors
|
12
12
|
@colors ||= IndiferentHash.setup(Hash[<<-EOF.split("\n").collect{|l| l.split(" ")}])
|
13
|
-
green #00cd00
|
14
|
-
red #cd0000
|
13
|
+
green #00cd00
|
14
|
+
red #cd0000
|
15
15
|
yellow #ffd700
|
16
16
|
blue #0000cd
|
17
17
|
path blue
|
@@ -49,26 +49,26 @@ EOF
|
|
49
49
|
when "black"
|
50
50
|
'#fff'
|
51
51
|
when 'green'
|
52
|
-
colors["green3"]
|
52
|
+
colors["green3"]
|
53
53
|
when 'red'
|
54
|
-
colors["red3"]
|
54
|
+
colors["red3"]
|
55
55
|
when 'yellow'
|
56
|
-
colors["gold1"]
|
56
|
+
colors["gold1"]
|
57
57
|
when 'blue'
|
58
|
-
colors["RoyalBlue"]
|
58
|
+
colors["RoyalBlue"]
|
59
59
|
else
|
60
60
|
colors[color.to_s] || color.to_s
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def self.continuous(array, start = "#40324F", eend = "#EABD5D", percent = false)
|
64
|
+
def self.continuous(array, start = "#40324F", eend = "#EABD5D", percent = false)
|
65
65
|
start_color = Color.new from_name(start)
|
66
66
|
end_color = Color.new from_name(eend)
|
67
67
|
|
68
68
|
if percent
|
69
69
|
array = array.collect{|v| n = v.to_f; n = n > 100 ? 100 : n; n < 0.001 ? 0.001 : n}
|
70
70
|
else
|
71
|
-
array = array.collect{|v| v.to_f }
|
71
|
+
array = array.collect{|v| v.to_f }
|
72
72
|
end
|
73
73
|
max = array.max
|
74
74
|
min = array.min
|
@@ -157,7 +157,7 @@ module Log
|
|
157
157
|
:workflow => yellow,
|
158
158
|
})
|
159
159
|
HIGHLIGHT = "\033[1m"
|
160
|
-
|
160
|
+
|
161
161
|
def self.uncolor(str)
|
162
162
|
"" << Term::ANSIColor.uncolor(str)
|
163
163
|
end
|
@@ -167,7 +167,7 @@ module Log
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def self.color(color, str = nil, reset = false)
|
170
|
-
return str.dup || "" if nocolor
|
170
|
+
return str.dup || "" if nocolor
|
171
171
|
|
172
172
|
if (color == :integer || color == :float) && Numeric === str
|
173
173
|
color = if str < 0
|
@@ -179,7 +179,7 @@ module Log
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
if color == :status
|
182
|
+
if color == :status
|
183
183
|
color = case str.to_sym
|
184
184
|
when :done
|
185
185
|
:green
|
@@ -4,8 +4,7 @@ module Log
|
|
4
4
|
def print(io, str)
|
5
5
|
return if self.severity && self.severity < Log.severity
|
6
6
|
return if Log.no_bar
|
7
|
-
|
8
|
-
Log.logfile.puts str unless Log.logfile.nil?
|
7
|
+
Log.log_write str
|
9
8
|
Log::LAST.replace "progress"
|
10
9
|
end
|
11
10
|
|
@@ -57,9 +56,12 @@ module Log
|
|
57
56
|
thr = short_mean
|
58
57
|
else
|
59
58
|
thr = begin
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
d = Time.now - @start
|
60
|
+
if d == 0
|
61
|
+
1
|
62
|
+
else
|
63
|
+
(@ticks || 1) / d
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -159,6 +161,7 @@ module Log
|
|
159
161
|
def save
|
160
162
|
info = {:start => @start, :last_time => @last_time, :last_count => @last_count, :last_percent => @last_percent, :desc => @desc, :ticks => @ticks, :max => @max, :mean => @mean}
|
161
163
|
info.delete_if{|k,v| v.nil?}
|
164
|
+
FileUtils.mkdir_p File.dirname(file) unless File.exist?(File.dirname(file))
|
162
165
|
File.write(file, info.to_yaml)
|
163
166
|
end
|
164
167
|
|
@@ -74,6 +74,7 @@ module Log
|
|
74
74
|
BAR_MUTEX.synchronize do
|
75
75
|
REMOVE << bar
|
76
76
|
end
|
77
|
+
cleanup_bars
|
77
78
|
Log::LAST.replace "remove_bar" if Log::LAST == "progress"
|
78
79
|
end
|
79
80
|
|
@@ -128,6 +129,8 @@ module Log
|
|
128
129
|
nil
|
129
130
|
end
|
130
131
|
end
|
132
|
+
rescue Interrupt
|
133
|
+
raise $!
|
131
134
|
rescue Exception
|
132
135
|
nil
|
133
136
|
end
|
data/lib/scout/log/trap.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Log
|
2
2
|
def self.trap_std(msg = "STDOUT", msge = "STDERR", severity = 0, severity_err = nil)
|
3
|
-
sout, sin =
|
4
|
-
soute, sine =
|
3
|
+
sout, sin = Open.pipe
|
4
|
+
soute, sine = Open.pipe
|
5
5
|
backup_stderr = STDERR.dup
|
6
6
|
backup_stdout = STDOUT.dup
|
7
7
|
old_logfile = Log.logfile
|
@@ -38,7 +38,7 @@ module Log
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.trap_stderr(msg = "STDERR", severity = 0)
|
41
|
-
sout, sin =
|
41
|
+
sout, sin = Open.pipe
|
42
42
|
backup_stderr = STDERR.dup
|
43
43
|
old_logfile = Log.logfile
|
44
44
|
Log.logfile(backup_stderr)
|
data/lib/scout/log.rb
CHANGED
@@ -12,9 +12,9 @@ module Log
|
|
12
12
|
end
|
13
13
|
|
14
14
|
SEVERITY_NAMES ||= begin
|
15
|
-
names = %w(DEBUG LOW MEDIUM HIGH INFO WARN ERROR NONE )
|
15
|
+
names = %w(DEBUG LOW MEDIUM HIGH INFO WARN ERROR NONE )
|
16
16
|
names.each_with_index do |name,i|
|
17
|
-
eval "#{ name } = #{ i }"
|
17
|
+
eval "#{ name } = #{ i }"
|
18
18
|
end
|
19
19
|
names
|
20
20
|
end
|
@@ -32,14 +32,14 @@ module Log
|
|
32
32
|
@@default_severity
|
33
33
|
end
|
34
34
|
|
35
|
-
case ENV['SCOUT_LOG']
|
36
|
-
when 'DEBUG'
|
35
|
+
case ENV['SCOUT_LOG']
|
36
|
+
when 'DEBUG'
|
37
37
|
self.severity = DEBUG
|
38
|
-
when 'LOW'
|
38
|
+
when 'LOW'
|
39
39
|
self.severity = LOW
|
40
|
-
when 'MEDIUM'
|
40
|
+
when 'MEDIUM'
|
41
41
|
self.severity = MEDIUM
|
42
|
-
when 'HIGH'
|
42
|
+
when 'HIGH'
|
43
43
|
self.severity = HIGH
|
44
44
|
when nil
|
45
45
|
self.severity = default_severity
|
@@ -50,23 +50,29 @@ module Log
|
|
50
50
|
|
51
51
|
|
52
52
|
def self.tty_size
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
@@tty_size ||= Log.ignore_stderr do
|
54
|
+
size = begin
|
55
|
+
IO.console.winsize.last
|
56
|
+
rescue Exception
|
57
|
+
begin
|
58
|
+
res = `tput li`
|
59
|
+
res = nil if res == ""
|
60
|
+
res || ENV["TTY_SIZE"] || 80
|
61
|
+
rescue Exception
|
62
|
+
ENV["TTY_SIZE"] || 80
|
63
|
+
end
|
64
|
+
end
|
65
|
+
size = size.to_i if String === size
|
66
|
+
size
|
67
|
+
end
|
62
68
|
end
|
63
69
|
|
64
70
|
|
65
71
|
def self.last_caller(stack)
|
66
72
|
line = nil
|
67
73
|
pos ||= 0
|
68
|
-
while line.nil? or line =~ /scout\/log\.rb/ and stack.any?
|
69
|
-
line = stack.shift
|
74
|
+
while line.nil? or line =~ /scout\/log\.rb/ and stack.any?
|
75
|
+
line = stack.shift
|
70
76
|
end
|
71
77
|
line ||= caller.first
|
72
78
|
line.gsub('`', "'")
|
@@ -129,9 +135,36 @@ module Log
|
|
129
135
|
out.puts Log.return_line << " " * (Log.tty_size || 80) << Log.return_line unless nocolor
|
130
136
|
end
|
131
137
|
|
138
|
+
MUTEX = Mutex.new
|
139
|
+
def self.log_write(str)
|
140
|
+
MUTEX.synchronize do
|
141
|
+
if logfile.nil?
|
142
|
+
begin
|
143
|
+
STDERR.write str
|
144
|
+
rescue
|
145
|
+
end
|
146
|
+
else
|
147
|
+
logfile.write str
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.log_puts(str)
|
153
|
+
MUTEX.synchronize do
|
154
|
+
if logfile.nil?
|
155
|
+
begin
|
156
|
+
STDERR.puts str
|
157
|
+
rescue
|
158
|
+
end
|
159
|
+
else
|
160
|
+
logfile.puts str
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
132
165
|
LAST = "log"
|
133
166
|
def self.logn(message = nil, severity = MEDIUM, &block)
|
134
|
-
return if severity < self.severity
|
167
|
+
return if severity < self.severity
|
135
168
|
message ||= block.call if block_given?
|
136
169
|
return if message.nil?
|
137
170
|
|
@@ -147,17 +180,14 @@ module Log
|
|
147
180
|
message = "" << highlight << message << color(0) if severity >= INFO
|
148
181
|
str = prefix << " " << message.to_s
|
149
182
|
|
150
|
-
|
151
|
-
|
152
|
-
else
|
153
|
-
logfile.write str
|
154
|
-
end
|
183
|
+
log_write str
|
184
|
+
|
155
185
|
Log::LAST.replace "log"
|
156
186
|
nil
|
157
187
|
end
|
158
188
|
|
159
189
|
def self.log(message = nil, severity = MEDIUM, &block)
|
160
|
-
return if severity < self.severity
|
190
|
+
return if severity < self.severity
|
161
191
|
message ||= block.call if block_given?
|
162
192
|
return if message.nil?
|
163
193
|
message = message + "\n" unless message[-1] == "\n"
|
@@ -241,6 +271,7 @@ module Log
|
|
241
271
|
line = line.sub('`',"'")
|
242
272
|
color = :green if line =~ /workflow/
|
243
273
|
color = :blue if line =~ /scout-/
|
274
|
+
color = :cyan if line =~ /rbbt-/
|
244
275
|
if color
|
245
276
|
Log.color color, line
|
246
277
|
else
|
@@ -250,9 +281,9 @@ module Log
|
|
250
281
|
end
|
251
282
|
|
252
283
|
def self.tsv(tsv, example = false)
|
253
|
-
|
254
|
-
|
255
|
-
|
284
|
+
log_puts Log.color :magenta, "TSV log: " << Log.last_caller(caller).gsub('`',"'")
|
285
|
+
log_puts Log.color(:blue, "=> "<< Log.fingerprint(tsv), true)
|
286
|
+
log_puts Log.color(:cyan, "=> " << tsv.summary)
|
256
287
|
if example && ! tsv.empty?
|
257
288
|
key = case example
|
258
289
|
when TrueClass, :first, "first"
|
@@ -266,11 +297,11 @@ module Log
|
|
266
297
|
values = tsv[key]
|
267
298
|
values = [values] if tsv.type == :flat || tsv.type == :single
|
268
299
|
if values.nil?
|
269
|
-
|
300
|
+
log_puts Log.color(:blue, "Key (#{tsv.key_field}) not present: ") + key
|
270
301
|
else
|
271
|
-
|
302
|
+
log_puts Log.color(:blue, "Key (#{tsv.key_field}): ") + key
|
272
303
|
tsv.fields.zip(values).each do |field,value|
|
273
|
-
|
304
|
+
log_puts Log.color(:magenta, field + ": ") + (Array === value ? value * ", " : value.to_s)
|
274
305
|
end
|
275
306
|
end
|
276
307
|
end
|
@@ -278,14 +309,14 @@ module Log
|
|
278
309
|
|
279
310
|
def self.stack(stack)
|
280
311
|
if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
|
281
|
-
|
312
|
+
log_puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
|
282
313
|
color_stack(stack).each do |line|
|
283
|
-
|
314
|
+
log_puts line
|
284
315
|
end
|
285
316
|
else
|
286
|
-
|
317
|
+
log_puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
|
287
318
|
color_stack(stack.reverse).each do |line|
|
288
|
-
|
319
|
+
log_puts line
|
289
320
|
end
|
290
321
|
end
|
291
322
|
end
|
@@ -293,7 +324,7 @@ module Log
|
|
293
324
|
def self.count_stack
|
294
325
|
if ! $count_stacks
|
295
326
|
Log.debug "Counting stacks at: " << caller.first
|
296
|
-
return
|
327
|
+
return
|
297
328
|
end
|
298
329
|
$stack_counts ||= {}
|
299
330
|
head = $count_stacks_head
|
data/lib/scout/meta_extension.rb
CHANGED
@@ -62,5 +62,39 @@ module MetaExtension
|
|
62
62
|
end
|
63
63
|
base.setup(other, *attr_values)
|
64
64
|
end
|
65
|
+
|
66
|
+
base.define_method(:purge) do
|
67
|
+
new = self.dup
|
68
|
+
|
69
|
+
if new.instance_variables.include?(:@extension_attrs)
|
70
|
+
new.instance_variable_get(:@extension_attrs).each do |a|
|
71
|
+
new.remove_instance_variable("@#{a}")
|
72
|
+
end
|
73
|
+
new.remove_instance_variable("@extension_attrs")
|
74
|
+
end
|
75
|
+
|
76
|
+
new
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.is_extended?(obj)
|
81
|
+
obj.respond_to?(:extension_attr_hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.purge(obj)
|
85
|
+
case obj
|
86
|
+
when nil
|
87
|
+
nil
|
88
|
+
when Array
|
89
|
+
obj.collect{|e| purge(e) }
|
90
|
+
when Hash
|
91
|
+
new = {}
|
92
|
+
obj.each do |k,v|
|
93
|
+
new[k] = purge(v)
|
94
|
+
end
|
95
|
+
new
|
96
|
+
else
|
97
|
+
is_extended?(obj) ? obj.purge : obj
|
98
|
+
end
|
65
99
|
end
|
66
100
|
end
|
data/lib/scout/misc/digest.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Misc
|
2
|
+
MAX_ARRAY_DIGEST_LENGTH = 100_000
|
2
3
|
def self.digest_str(obj)
|
3
4
|
if obj.respond_to?(:digest_str)
|
4
5
|
obj.digest_str
|
@@ -9,12 +10,19 @@ module Misc
|
|
9
10
|
if Path === obj || ! Open.exists?(obj)
|
10
11
|
'\'' << obj << '\''
|
11
12
|
else
|
12
|
-
Misc.file_md5(obj)
|
13
|
+
"File MD5: #{Misc.file_md5(obj)}"
|
13
14
|
end
|
14
15
|
when Integer, Symbol
|
15
16
|
obj.to_s
|
16
17
|
when Array
|
17
|
-
|
18
|
+
if obj.length > MAX_ARRAY_DIGEST_LENGTH
|
19
|
+
length = obj.length
|
20
|
+
mid = length/2
|
21
|
+
sample_pos = [1, 2, mid, length-2, length-1]
|
22
|
+
"[#{length}:" << obj.values_at(*sample_pos).inject(""){|acc,o| acc.empty? ? Misc.digest_str(o) : acc << ', ' << Misc.digest_str(o) } << ']'
|
23
|
+
else
|
24
|
+
'[' << obj.inject(""){|acc,o| acc.empty? ? Misc.digest_str(o) : acc << ', ' << Misc.digest_str(o) } << ']'
|
25
|
+
end
|
18
26
|
when Hash
|
19
27
|
'{' << obj.inject(""){|acc,p| s = Misc.digest_str(p.first) << "=" << Misc.digest_str(p.last); acc.empty? ? s : acc << ', ' << s } << '}'
|
20
28
|
when Integer
|
@@ -46,6 +54,7 @@ module Misc
|
|
46
54
|
|
47
55
|
def self.file_md5(file)
|
48
56
|
file = file.find if Path === file
|
57
|
+
file = File.expand_path(file)
|
49
58
|
#md5file = file + '.md5'
|
50
59
|
Persist.persist("MD5:#{file}", :string) do
|
51
60
|
Digest::MD5.file(file).hexdigest
|
@@ -16,11 +16,10 @@ module Misc
|
|
16
16
|
|
17
17
|
basedir += "/" unless basedir.slice(-2,-1) == "/"
|
18
18
|
|
19
|
-
if path.
|
20
|
-
return path
|
19
|
+
if path.start_with?(basedir)
|
20
|
+
return path.slice(basedir.length, basedir.length)
|
21
21
|
else
|
22
22
|
return nil
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
data/lib/scout/misc/format.rb
CHANGED
@@ -38,10 +38,10 @@ module Misc
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
|
41
|
+
MAX_TTY_LINE_WIDTH = 100
|
42
42
|
def self.format_paragraph(text, size = nil, indent = nil, offset = nil)
|
43
|
-
size ||= Log.tty_size ||
|
44
|
-
size =
|
43
|
+
size ||= Log.tty_size || MAX_TTY_LINE_WIDTH
|
44
|
+
size = MAX_TTY_LINE_WIDTH if size > MAX_TTY_LINE_WIDTH
|
45
45
|
indent ||= 0
|
46
46
|
offset ||= 0
|
47
47
|
|
@@ -75,9 +75,14 @@ module Misc
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.format_definition_list_item(dt, dd, indent = nil, size = nil, color = :yellow)
|
78
|
-
size
|
79
|
-
|
80
|
-
|
78
|
+
if size.nil?
|
79
|
+
base_size = MAX_TTY_LINE_WIDTH
|
80
|
+
base_indent = indent || (base_size / 3)
|
81
|
+
size = base_size - base_indent
|
82
|
+
end
|
83
|
+
|
84
|
+
indent ||= base_indent || size / 3
|
85
|
+
|
81
86
|
dd = "" if dd.nil?
|
82
87
|
dt = Log.color color, dt if color
|
83
88
|
dt = dt.to_s unless dd.empty?
|
@@ -96,8 +101,8 @@ module Misc
|
|
96
101
|
end
|
97
102
|
|
98
103
|
def self.format_definition_list(defs, indent = nil, size = nil, color = :yellow, sep = "\n\n")
|
99
|
-
size ||= Log.tty_size || MAX_WIDTH
|
100
104
|
indent ||= 30
|
105
|
+
size ||= (Log.tty_size || MAX_TTY_LINE_WIDTH) - indent
|
101
106
|
entries = []
|
102
107
|
defs.each do |dt,dd|
|
103
108
|
text = format_definition_list_item(dt,dd,indent, size,color)
|
data/lib/scout/misc/monitor.rb
CHANGED
@@ -2,6 +2,7 @@ module Misc
|
|
2
2
|
def self.pid_alive?(pid)
|
3
3
|
!! Process.kill(0, pid) rescue false
|
4
4
|
end
|
5
|
+
|
5
6
|
def self.benchmark(repeats = 1, message = nil)
|
6
7
|
require 'benchmark'
|
7
8
|
res = nil
|
@@ -52,4 +53,14 @@ module Misc
|
|
52
53
|
end
|
53
54
|
eend - start
|
54
55
|
end
|
56
|
+
|
57
|
+
def self.wait_for_interrupt
|
58
|
+
while true
|
59
|
+
begin
|
60
|
+
sleep 1
|
61
|
+
rescue Interrupt
|
62
|
+
break
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
55
66
|
end
|
data/lib/scout/misc/system.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
+
require 'sys/proctable'
|
2
|
+
|
1
3
|
module Misc
|
4
|
+
|
5
|
+
def self.hostname
|
6
|
+
@@hostname ||= begin
|
7
|
+
`hostname`.strip
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.children(ppid = nil)
|
12
|
+
ppid ||= Process.pid
|
13
|
+
Sys::ProcTable.ps.select{ |pe| pe.ppid == ppid }
|
14
|
+
end
|
15
|
+
|
2
16
|
def self.env_add(var, value, sep = ":", prepend = true)
|
3
17
|
if ENV[var].nil?
|
4
18
|
ENV[var] = value
|
@@ -22,4 +36,38 @@ module Misc
|
|
22
36
|
ENV[var] = old_value
|
23
37
|
end
|
24
38
|
end
|
39
|
+
|
40
|
+
def self.update_git(gem_name = 'scout-gear')
|
41
|
+
gem_name = 'scout-gear' if gem_name.nil?
|
42
|
+
dir = File.join(__dir__, '../../../../', gem_name)
|
43
|
+
return unless Open.exist?(dir)
|
44
|
+
Misc.in_dir dir do
|
45
|
+
begin
|
46
|
+
begin
|
47
|
+
CMD.cmd_log('git pull')
|
48
|
+
rescue
|
49
|
+
raise "Could not update #{gem_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
begin
|
53
|
+
CMD.cmd_log('git submodule update')
|
54
|
+
rescue
|
55
|
+
raise "Could not update #{gem_name} submodules"
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
begin
|
60
|
+
CMD.cmd_log('rake install')
|
61
|
+
rescue
|
62
|
+
raise "Could not install updated #{gem_name}"
|
63
|
+
end
|
64
|
+
rescue
|
65
|
+
Log.warn $!.message
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.processors
|
71
|
+
Etc.nprocessors
|
72
|
+
end
|
25
73
|
end
|