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.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +48 -9
  3. data/Rakefile +6 -1
  4. data/VERSION +1 -1
  5. data/bin/scout +16 -4
  6. data/doc/lib/scout/path.md +35 -0
  7. data/doc/lib/scout/workflow/task.md +13 -0
  8. data/lib/rbbt-scout.rb +2 -1
  9. data/lib/scout/cmd.rb +32 -29
  10. data/lib/scout/concurrent_stream.rb +36 -19
  11. data/lib/scout/exceptions.rb +10 -0
  12. data/lib/scout/indiferent_hash.rb +17 -0
  13. data/lib/scout/log/color.rb +11 -11
  14. data/lib/scout/log/progress/report.rb +8 -5
  15. data/lib/scout/log/progress/util.rb +3 -0
  16. data/lib/scout/log/trap.rb +3 -3
  17. data/lib/scout/log.rb +67 -36
  18. data/lib/scout/meta_extension.rb +34 -0
  19. data/lib/scout/misc/digest.rb +11 -2
  20. data/lib/scout/misc/filesystem.rb +2 -3
  21. data/lib/scout/misc/format.rb +12 -7
  22. data/lib/scout/misc/monitor.rb +11 -0
  23. data/lib/scout/misc/system.rb +48 -0
  24. data/lib/scout/named_array.rb +8 -0
  25. data/lib/scout/offsite/ssh.rb +174 -0
  26. data/lib/scout/offsite/step.rb +100 -0
  27. data/lib/scout/offsite/sync.rb +55 -0
  28. data/lib/scout/offsite.rb +3 -0
  29. data/lib/scout/open/lock.rb +5 -24
  30. data/lib/scout/open/remote.rb +12 -1
  31. data/lib/scout/open/stream.rb +109 -122
  32. data/lib/scout/open/util.rb +9 -0
  33. data/lib/scout/open.rb +12 -11
  34. data/lib/scout/path/find.rb +15 -10
  35. data/lib/scout/path/util.rb +5 -0
  36. data/lib/scout/path.rb +1 -1
  37. data/lib/scout/persist/serialize.rb +4 -4
  38. data/lib/scout/persist.rb +1 -1
  39. data/lib/scout/resource/open.rb +8 -0
  40. data/lib/scout/resource/path.rb +16 -9
  41. data/lib/scout/resource/software.rb +4 -2
  42. data/lib/scout/resource/util.rb +10 -4
  43. data/lib/scout/resource.rb +2 -0
  44. data/lib/scout/tsv/dumper.rb +5 -1
  45. data/lib/scout/tsv/index.rb +28 -86
  46. data/lib/scout/tsv/open.rb +35 -14
  47. data/lib/scout/tsv/parser.rb +22 -5
  48. data/lib/scout/tsv/persist/tokyocabinet.rb +2 -0
  49. data/lib/scout/tsv/stream.rb +204 -0
  50. data/lib/scout/tsv/transformer.rb +11 -0
  51. data/lib/scout/tsv.rb +9 -2
  52. data/lib/scout/work_queue/worker.rb +2 -2
  53. data/lib/scout/work_queue.rb +37 -12
  54. data/lib/scout/workflow/definition.rb +2 -1
  55. data/lib/scout/workflow/deployment/orchestrator.rb +254 -0
  56. data/lib/scout/workflow/deployment.rb +1 -0
  57. data/lib/scout/workflow/step/dependencies.rb +46 -14
  58. data/lib/scout/workflow/step/file.rb +5 -0
  59. data/lib/scout/workflow/step/info.rb +13 -3
  60. data/lib/scout/workflow/step/inputs.rb +5 -0
  61. data/lib/scout/workflow/step/load.rb +1 -1
  62. data/lib/scout/workflow/step/provenance.rb +1 -0
  63. data/lib/scout/workflow/step/status.rb +27 -9
  64. data/lib/scout/workflow/step.rb +82 -30
  65. data/lib/scout/workflow/task/dependencies.rb +116 -0
  66. data/lib/scout/workflow/task/inputs.rb +36 -17
  67. data/lib/scout/workflow/task.rb +12 -109
  68. data/lib/scout/workflow/usage.rb +57 -41
  69. data/lib/scout/workflow.rb +19 -13
  70. data/lib/scout-gear.rb +2 -0
  71. data/lib/scout.rb +6 -0
  72. data/scout-gear.gemspec +38 -7
  73. data/scout_commands/doc +37 -0
  74. data/scout_commands/find +1 -0
  75. data/scout_commands/offsite +30 -0
  76. data/scout_commands/resource/produce +66 -0
  77. data/scout_commands/template +52 -0
  78. data/scout_commands/update +29 -0
  79. data/scout_commands/workflow/info +15 -3
  80. data/scout_commands/workflow/install +105 -0
  81. data/scout_commands/workflow/task +46 -6
  82. data/share/software/install_helpers +2 -2
  83. data/share/templates/command +25 -0
  84. data/share/templates/workflow.rb +14 -0
  85. data/test/scout/offsite/test_ssh.rb +15 -0
  86. data/test/scout/offsite/test_step.rb +32 -0
  87. data/test/scout/offsite/test_sync.rb +36 -0
  88. data/test/scout/offsite/test_task.rb +0 -0
  89. data/test/scout/resource/test_path.rb +6 -0
  90. data/test/scout/test_named_array.rb +6 -0
  91. data/test/scout/test_persist.rb +3 -2
  92. data/test/scout/test_tsv.rb +17 -0
  93. data/test/scout/test_work_queue.rb +64 -42
  94. data/test/scout/tsv/persist/test_adapter.rb +1 -1
  95. data/test/scout/tsv/test_index.rb +14 -0
  96. data/test/scout/tsv/test_parser.rb +35 -0
  97. data/test/scout/tsv/test_stream.rb +200 -0
  98. data/test/scout/tsv/test_transformer.rb +12 -0
  99. data/test/scout/workflow/deployment/test_orchestrator.rb +272 -0
  100. data/test/scout/workflow/step/test_dependencies.rb +68 -0
  101. data/test/scout/workflow/step/test_info.rb +17 -0
  102. data/test/scout/workflow/step/test_status.rb +0 -1
  103. data/test/scout/workflow/task/test_dependencies.rb +357 -0
  104. data/test/scout/workflow/task/test_inputs.rb +52 -0
  105. data/test/scout/workflow/test_definition.rb +18 -0
  106. data/test/scout/workflow/test_documentation.rb +24 -0
  107. data/test/scout/workflow/test_step.rb +109 -0
  108. data/test/scout/workflow/test_task.rb +0 -287
  109. data/test/test_scout.rb +9 -0
  110. metadata +89 -5
  111. data/scout_commands/workflow/task_old +0 -706
@@ -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
- STDERR.print str
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
- (@ticks || 1) / (Time.now - @start)
61
- rescue
62
- 1
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
@@ -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 = Misc.pipe
4
- soute, sine = Misc.pipe
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 = Misc.pipe
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
- @tty_size = begin
54
- IO.console.winsize.last
55
- rescue
56
- begin
57
- `tput li`
58
- rescue
59
- 80
60
- end
61
- end
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
- if logfile.nil?
151
- STDERR.write str
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
- STDERR.puts Log.color :magenta, "TSV log: " << Log.last_caller(caller).gsub('`',"'")
254
- STDERR.puts Log.color(:blue, "=> "<< Log.fingerprint(tsv), true)
255
- STDERR.puts Log.color(:cyan, "=> " << tsv.summary)
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
- STDERR.puts Log.color(:blue, "Key (#{tsv.key_field}) not present: ") + key
300
+ log_puts Log.color(:blue, "Key (#{tsv.key_field}) not present: ") + key
270
301
  else
271
- STDERR.puts Log.color(:blue, "Key (#{tsv.key_field}): ") + key
302
+ log_puts Log.color(:blue, "Key (#{tsv.key_field}): ") + key
272
303
  tsv.fields.zip(values).each do |field,value|
273
- STDERR.puts Log.color(:magenta, field + ": ") + (Array === value ? value * ", " : value.to_s)
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
- STDERR.puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
312
+ log_puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
282
313
  color_stack(stack).each do |line|
283
- STDERR.puts line
314
+ log_puts line
284
315
  end
285
316
  else
286
- STDERR.puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
317
+ log_puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
287
318
  color_stack(stack.reverse).each do |line|
288
- STDERR.puts line
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
@@ -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
@@ -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
- '[' << obj.inject(""){|acc,o| acc.empty? ? Misc.digest_str(o) : acc << ', ' << Misc.digest_str(o) } << ']'
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.index(basedir) == 0
20
- return path[basedir.length..-1]
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
@@ -38,10 +38,10 @@ module Misc
38
38
 
39
39
 
40
40
 
41
- MAX_WIDTH = 100
41
+ MAX_TTY_LINE_WIDTH = 100
42
42
  def self.format_paragraph(text, size = nil, indent = nil, offset = nil)
43
- size ||= Log.tty_size || MAX_WIDTH
44
- size = MAX_WIDTH if size > MAX_WIDTH
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 ||= Log.tty_size || MAX_WIDTH
79
- size = MAX_WIDTH if size > MAX_WIDTH
80
- indent ||= size / 3
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)
@@ -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
@@ -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
@@ -127,4 +127,12 @@ module NamedArray
127
127
  end
128
128
  source
129
129
  end
130
+
131
+ def method_missing(name, *args)
132
+ if identify_name(name)
133
+ return self[name]
134
+ else
135
+ return super(name, *args)
136
+ end
137
+ end
130
138
  end