scout-gear 7.2.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +51 -6
  3. data/VERSION +1 -1
  4. data/bin/scout +6 -3
  5. data/lib/rbbt-scout.rb +1 -0
  6. data/lib/scout/cmd.rb +1 -1
  7. data/lib/scout/concurrent_stream.rb +33 -29
  8. data/lib/scout/config.rb +1 -1
  9. data/lib/scout/exceptions.rb +1 -0
  10. data/lib/scout/log/color.rb +4 -2
  11. data/lib/scout/log/progress/report.rb +1 -1
  12. data/lib/scout/log/progress/util.rb +71 -2
  13. data/lib/scout/log/progress.rb +1 -1
  14. data/lib/scout/log/trap.rb +107 -0
  15. data/lib/scout/log.rb +56 -21
  16. data/lib/scout/meta_extension.rb +13 -6
  17. data/lib/scout/misc/digest.rb +1 -1
  18. data/lib/scout/misc/format.rb +12 -0
  19. data/lib/scout/misc/helper.rb +31 -0
  20. data/lib/scout/misc/insist.rb +1 -1
  21. data/lib/scout/misc/monitor.rb +12 -1
  22. data/lib/scout/misc/system.rb +10 -0
  23. data/lib/scout/misc.rb +1 -0
  24. data/lib/scout/named_array.rb +65 -3
  25. data/lib/scout/open/lock/lockfile.rb +587 -0
  26. data/lib/scout/open/lock.rb +28 -2
  27. data/lib/scout/open/remote.rb +4 -0
  28. data/lib/scout/open/stream.rb +111 -42
  29. data/lib/scout/open/util.rb +13 -3
  30. data/lib/scout/path/find.rb +9 -1
  31. data/lib/scout/path/util.rb +35 -0
  32. data/lib/scout/persist/serialize.rb +18 -5
  33. data/lib/scout/persist.rb +60 -30
  34. data/lib/scout/resource/path.rb +53 -0
  35. data/lib/scout/resource/produce.rb +0 -8
  36. data/lib/scout/resource/util.rb +2 -1
  37. data/lib/scout/semaphore.rb +8 -1
  38. data/lib/scout/tmpfile.rb +7 -8
  39. data/lib/scout/tsv/attach.rb +177 -0
  40. data/lib/scout/tsv/change_id.rb +40 -0
  41. data/lib/scout/tsv/dumper.rb +85 -54
  42. data/lib/scout/tsv/index.rb +188 -20
  43. data/lib/scout/tsv/open.rb +182 -0
  44. data/lib/scout/tsv/parser.rb +200 -118
  45. data/lib/scout/tsv/path.rb +5 -6
  46. data/lib/scout/tsv/persist/adapter.rb +26 -37
  47. data/lib/scout/tsv/persist/fix_width_table.rb +327 -0
  48. data/lib/scout/tsv/persist/serialize.rb +117 -0
  49. data/lib/scout/tsv/persist/tokyocabinet.rb +6 -3
  50. data/lib/scout/tsv/persist.rb +4 -2
  51. data/lib/scout/tsv/transformer.rb +141 -0
  52. data/lib/scout/tsv/traverse.rb +136 -37
  53. data/lib/scout/tsv/util/filter.rb +312 -0
  54. data/lib/scout/tsv/util/process.rb +73 -0
  55. data/lib/scout/tsv/util/reorder.rb +81 -0
  56. data/lib/scout/tsv/util/select.rb +265 -0
  57. data/lib/scout/tsv/util/unzip.rb +86 -0
  58. data/lib/scout/tsv/util.rb +126 -19
  59. data/lib/scout/tsv.rb +28 -5
  60. data/lib/scout/work_queue/socket.rb +6 -1
  61. data/lib/scout/work_queue/worker.rb +5 -2
  62. data/lib/scout/work_queue.rb +15 -8
  63. data/lib/scout/workflow/definition.rb +29 -2
  64. data/lib/scout/workflow/step/dependencies.rb +24 -4
  65. data/lib/scout/workflow/step/info.rb +40 -5
  66. data/lib/scout/workflow/step/progress.rb +14 -0
  67. data/lib/scout/workflow/step/provenance.rb +8 -7
  68. data/lib/scout/workflow/step/status.rb +45 -0
  69. data/lib/scout/workflow/step.rb +104 -33
  70. data/lib/scout/workflow/task/inputs.rb +14 -20
  71. data/lib/scout/workflow/task.rb +86 -47
  72. data/lib/scout/workflow/usage.rb +10 -6
  73. data/scout-gear.gemspec +30 -3
  74. data/scout_commands/workflow/task +37 -9
  75. data/scout_commands/workflow/task_old +2 -2
  76. data/test/scout/open/test_stream.rb +61 -59
  77. data/test/scout/path/test_find.rb +10 -1
  78. data/test/scout/resource/test_produce.rb +15 -0
  79. data/test/scout/test_meta_extension.rb +25 -0
  80. data/test/scout/test_named_array.rb +18 -0
  81. data/test/scout/test_persist.rb +67 -0
  82. data/test/scout/test_tmpfile.rb +1 -1
  83. data/test/scout/test_tsv.rb +222 -3
  84. data/test/scout/test_work_queue.rb +21 -18
  85. data/test/scout/tsv/persist/test_adapter.rb +11 -1
  86. data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
  87. data/test/scout/tsv/persist/test_tokyocabinet.rb +29 -1
  88. data/test/scout/tsv/test_attach.rb +227 -0
  89. data/test/scout/tsv/test_change_id.rb +98 -0
  90. data/test/scout/tsv/test_dumper.rb +1 -1
  91. data/test/scout/tsv/test_index.rb +127 -3
  92. data/test/scout/tsv/test_open.rb +167 -0
  93. data/test/scout/tsv/test_parser.rb +45 -3
  94. data/test/scout/tsv/test_persist.rb +9 -0
  95. data/test/scout/tsv/test_transformer.rb +108 -0
  96. data/test/scout/tsv/test_traverse.rb +195 -3
  97. data/test/scout/tsv/test_util.rb +24 -0
  98. data/test/scout/tsv/util/test_filter.rb +188 -0
  99. data/test/scout/tsv/util/test_process.rb +47 -0
  100. data/test/scout/tsv/util/test_reorder.rb +94 -0
  101. data/test/scout/tsv/util/test_select.rb +58 -0
  102. data/test/scout/tsv/util/test_unzip.rb +112 -0
  103. data/test/scout/work_queue/test_socket.rb +0 -1
  104. data/test/scout/work_queue/test_worker.rb +63 -6
  105. data/test/scout/workflow/step/test_load.rb +3 -3
  106. data/test/scout/workflow/step/test_status.rb +31 -0
  107. data/test/scout/workflow/task/test_inputs.rb +14 -14
  108. data/test/scout/workflow/test_step.rb +13 -13
  109. data/test/scout/workflow/test_task.rb +168 -32
  110. data/test/scout/workflow/test_usage.rb +33 -6
  111. data/test/test_helper.rb +3 -1
  112. metadata +29 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de499ccbdffd888298324a025b253f0dd0e359d279d6abe8331acd91fd00cc57
4
- data.tar.gz: 9643053080da23a98209ebefbcd3b3043b7031374a405ffed112460f1ddcf411
3
+ metadata.gz: 48f6bb392f3391e2816e701887bfd98617b1a68bc533c8b6de3307f25c84906d
4
+ data.tar.gz: 476858f63deaa7fa9fc531c7872bdaefa1d6b3ed32cdacbe41f53d1d170fcc87
5
5
  SHA512:
6
- metadata.gz: 73afbf6aeb4032380fc45e2f60e2e9335d763c6837ef3bb8247c83bfaf2cd962a6fdfba767788b988e00f685d0e9bc19927a4e794fc092296cc088f23d4565ee
7
- data.tar.gz: 309e86afe466c649800fd212fd22e9e183a5e92ba558d88ec0258690a15437952ead3e968c3693b89c036dc2fa9e27f4d129f6be6c001031dc38ab071361ba99
6
+ metadata.gz: c61501c8cc79b57b64cb8613efc8b00fb84908bf0d55b008c6a6a39b99ea6bffa53630a8e134c07a49cb7bc4145ec181df057b6ba1eebfd2d722b2aa2d2e63d0
7
+ data.tar.gz: 100356a04cd34eba627239668747023ee5be4455ebbee715df39dbe04e9c8dfcac7007ce310e4622cf0c7e16ee9159e6fc2d4eefcaa486c24519c7f99185facf
data/.vimproject CHANGED
@@ -9,10 +9,10 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
9
9
  find
10
10
  glob
11
11
  workflow=workflow{
12
- task_old
13
12
  task
14
13
  list
15
14
  info
15
+ task_old
16
16
  }
17
17
  }
18
18
  lib=lib {
@@ -49,6 +49,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
49
49
  report.rb
50
50
  util.rb
51
51
  }
52
+ trap.rb
52
53
  }
53
54
  tmpfile.rb
54
55
  simple_opt.rb
@@ -70,6 +71,9 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
70
71
  open.rb
71
72
  open=open{
72
73
  lock.rb
74
+ lock=lock{
75
+ lockfile.rb
76
+ }
73
77
  stream.rb
74
78
  remote.rb
75
79
  util.rb
@@ -98,11 +102,13 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
98
102
  step.rb
99
103
  step=step{
100
104
  info.rb
105
+ status.rb
101
106
  load.rb
102
107
  file.rb
103
108
  config.rb
104
109
  dependencies.rb
105
110
  provenance.rb
111
+ progress.rb
106
112
  }
107
113
  task.rb
108
114
  task=task{
@@ -120,29 +126,66 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
120
126
  }
121
127
  tsv.rb
122
128
  tsv=tsv{
129
+ util.rb
130
+ util=util{
131
+ process.rb
132
+ select.rb
133
+ process.rb
134
+ unzip.rb
135
+ reorder.rb
136
+ }
123
137
  parser.rb
124
138
  dumper.rb
139
+ transformer.rb
125
140
  persist.rb
126
- index.rb
127
141
  persist=persist{
128
142
  adapter.rb
143
+ serialize.rb
129
144
  tokyocabinet.rb
145
+ fix_width_table.rb
130
146
  }
147
+ index.rb
131
148
  traverse.rb
132
- util.rb
149
+ attach.rb
150
+ change_id.rb
133
151
  path.rb
152
+ open.rb
134
153
  }
135
154
  }
136
155
  }
137
156
  test=test {
138
157
  test_helper.rb
158
+ test_scout-gear.rb
139
159
  scout=scout{
160
+ test_cmd.rb
161
+ test_concurrent_stream.rb
162
+ test_config.rb
140
163
  test_indiferent_hash.rb
164
+ test_log.rb
165
+ test_meta_extension.rb
166
+ test_misc.rb
167
+ test_named_array.rb
168
+ test_open.rb
169
+ test_path.rb
170
+ test_persist.rb
171
+ test_resource.rb
172
+ test_semaphore.rb
173
+ test_tmpfile.rb
174
+ test_tsv.rb
175
+ test_work_queue.rb
176
+ test_workflow.rb
177
+ workflow=workflow{
178
+ test_definition.rb
179
+ test_documentation.rb
180
+ test_step.rb
181
+ test_task.rb
182
+ test_usage.rb
183
+ test_util.rb
184
+ }
141
185
  indiferent_hash=indiferent_hash{
186
+ test_case_insensitive.rb
142
187
  test_options.rb
143
188
  }
144
- test_log.rb
145
- test_tmpfile.rb
146
189
  }
147
190
  }
148
191
  share=share{
@@ -275,6 +318,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
275
318
 
276
319
  workflow.rb
277
320
  workflow=workflow{
321
+ refactor.rb
278
322
  annotate.rb
279
323
 
280
324
  definition.rb
@@ -356,6 +400,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
356
400
 
357
401
  tsv.rb
358
402
  tsv=tsv{
403
+ refactor.rb
359
404
  parser.rb
360
405
  dumper.rb
361
406
 
@@ -479,7 +524,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
479
524
  test_path.rb
480
525
  }
481
526
  workflow=workflow{
482
- _test_soap.rb
527
+ test_soap.rb
483
528
  test_doc.rb
484
529
  test_step.rb
485
530
  test_task.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.0
1
+ 8.0.0
data/bin/scout CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.join(__dir__, '../lib')
4
4
 
5
+ ENV["SCOUT_NOCOLOR"] = "true" if ARGV.include? "--nocolor"
6
+
7
+ ENV["SCOUT_NO_PROGRESS"] = "true" if ARGV.include? "--nobar"
8
+
5
9
  require 'scout-gear'
6
10
 
7
11
  class CmdStop < Exception
@@ -44,7 +48,6 @@ if dev_dir
44
48
  end
45
49
  end
46
50
 
47
- Log.nocolor = true if ARGV.include? "--nocolor"
48
51
 
49
52
  require 'scout/simple_opt'
50
53
 
@@ -66,11 +69,11 @@ Log.nocolor = true if options[:nocolor]
66
69
  locate = options.delete :locate_file
67
70
 
68
71
  if options[:log_file]
69
- Log.logfile(options[:log_file])
72
+ Log.logfile(options.delete(:log_file))
70
73
  end
71
74
 
72
75
  if options[:log]
73
- Log.severity = options[:log].to_i
76
+ Log.severity = options.delete(:log).to_i
74
77
  else
75
78
  global_severity = Log.get_level(Scout.etc.log_severity.read.strip) if Scout.etc.log_severity.exists?
76
79
  if ENV["SCOUT_LOG"]
data/lib/rbbt-scout.rb CHANGED
@@ -2,4 +2,5 @@ $LOAD_PATH.unshift File.join(__dir__, '../modules/rbbt-util/lib')
2
2
  module Rbbt
3
3
  extend Resource
4
4
  self.pkgdir = 'rbbt'
5
+ self.path_maps = Path.path_maps.merge(:rbbt_lib => File.expand_path(File.join(__dir__, '../modules/rbbt-util/', '{TOPLEVEL}','{SUBPATH}')))
5
6
  end
data/lib/scout/cmd.rb CHANGED
@@ -272,7 +272,7 @@ module CMD
272
272
  sout.close unless sout.closed?
273
273
 
274
274
  status = wait_thr.value
275
- if not status.success? and not no_fail
275
+ if status && ! status.success? && ! no_fail
276
276
  if !err.empty?
277
277
  raise ProcessFailed.new pid, "#{cmd} failed with error status #{status.exitstatus}.\n#{err}"
278
278
  else
@@ -9,11 +9,11 @@ module AbortedStream
9
9
  end
10
10
 
11
11
  module ConcurrentStream
12
- attr_accessor :threads, :pids, :callback, :abort_callback, :filename, :joined, :aborted, :autojoin, :lockfile, :no_fail, :pair, :thread, :stream_exception, :log, :std_err, :next
12
+ attr_accessor :threads, :pids, :callback, :abort_callback, :filename, :joined, :aborted, :autojoin, :lock, :no_fail, :pair, :thread, :stream_exception, :log, :std_err, :next
13
13
 
14
14
  def self.setup(stream, options = {}, &block)
15
15
 
16
- threads, pids, callback, abort_callback, filename, autojoin, lockfile, no_fail, pair, next_stream = IndiferentHash.process_options options, :threads, :pids, :callback, :abort_callback, :filename, :autojoin, :lockfile, :no_fail, :pair, :next
16
+ threads, pids, callback, abort_callback, filename, autojoin, lock, no_fail, pair, next_stream = IndiferentHash.process_options options, :threads, :pids, :callback, :abort_callback, :filename, :autojoin, :lock, :no_fail, :pair, :next
17
17
  stream.extend ConcurrentStream unless ConcurrentStream === stream
18
18
 
19
19
  stream.threads ||= []
@@ -54,7 +54,7 @@ module ConcurrentStream
54
54
 
55
55
  stream.filename = filename.nil? ? stream.inspect.split(":").last[0..-2] : filename
56
56
 
57
- stream.lockfile = lockfile unless lockfile.nil?
57
+ stream.lock = lock unless lock.nil?
58
58
 
59
59
  stream.aborted = false
60
60
 
@@ -62,7 +62,7 @@ module ConcurrentStream
62
62
  end
63
63
 
64
64
  def annotate(stream)
65
- ConcurrentStream.setup(stream, :threads => threads, :pids => pids, :callback => callback, :abort_callback => abort_callback, :filename => filename, :autojoin => autojoin, :lockfile => lockfile)
65
+ ConcurrentStream.setup(stream, :threads => threads, :pids => pids, :callback => callback, :abort_callback => abort_callback, :filename => filename, :autojoin => autojoin, :lock => lock)
66
66
  stream
67
67
  end
68
68
 
@@ -136,11 +136,16 @@ module ConcurrentStream
136
136
  begin
137
137
  join_threads
138
138
  join_pids
139
+ raise stream_exception if stream_exception
139
140
  join_callback
140
141
  close unless closed?
141
142
  ensure
142
143
  @joined = true
143
- lockfile.unlock if lockfile and lockfile.locked?
144
+ begin
145
+ lock.unlock if lock && lock.locked?
146
+ rescue
147
+ Log.exception $!
148
+ end
144
149
  raise stream_exception if stream_exception
145
150
  end
146
151
  end
@@ -151,21 +156,17 @@ module ConcurrentStream
151
156
  name += " - file:#{filename}" if filename
152
157
  Log.low "Aborting threads (#{name}) - #{@threads.collect{|t| Log.fingerprint(t) } * ", "}"
153
158
 
154
- @threads.each do |t|
159
+ threads = @threads.dup
160
+ @threads.clear
161
+ threads.each do |t|
155
162
  next if t == Thread.current
163
+ next if t["aborted"]
164
+ t["aborted"] = true
165
+ exception = exception.nil? ? Aborted.new : exception
156
166
  Log.debug "Aborting thread #{Log.fingerprint(t)} with exception: #{exception}"
157
- t.raise((exception.nil? ? Aborted.new : exception))
167
+ t.raise(exception)
168
+ t.join
158
169
  end
159
-
160
- @threads.each do |t|
161
- next if t == Thread.current
162
- begin
163
- t.join unless t == Thread.current
164
- rescue Aborted
165
- rescue Exception
166
- Log.debug "Thread (#{name}) exception: #{$!.message}"
167
- end
168
- end
169
170
  end
170
171
 
171
172
  def abort_pids
@@ -205,8 +206,8 @@ module ConcurrentStream
205
206
  ensure
206
207
  close unless closed?
207
208
 
208
- if lockfile and lockfile.locked?
209
- lockfile.unlock
209
+ if lock and lock.locked?
210
+ lock.unlock
210
211
  end
211
212
  end
212
213
  end
@@ -216,12 +217,11 @@ module ConcurrentStream
216
217
  begin
217
218
  super(*args)
218
219
  rescue
219
- Log.exception $!
220
220
  self.abort
221
221
  self.join
222
222
  stream_raise_exception $!
223
223
  ensure
224
- self.join if self.closed? or self.eof?
224
+ self.join if ! @stream_exception && (self.closed? || self.eof?)
225
225
  end
226
226
  else
227
227
  super(*args)
@@ -231,15 +231,19 @@ module ConcurrentStream
231
231
  def read(*args)
232
232
  begin
233
233
  super(*args)
234
- rescue
235
- raise stream_exception if stream_exception
236
- raise $!
234
+ rescue Exception
235
+ @stream_exception ||= $!
236
+ raise @stream_exception
237
237
  ensure
238
- begin
239
- close unless closed?
240
- rescue Exception
241
- raise $! if ConcurrentStreamProcessFailed === $!
242
- end if autojoin && ! closed? && eof?
238
+ if ! @stream_exception && autojoin && ! closed?
239
+ begin
240
+ done = eof?
241
+ rescue Exception
242
+ self.abort($!)
243
+ raise $!
244
+ end
245
+ close if done
246
+ end
243
247
  end
244
248
  end
245
249
 
data/lib/scout/config.rb CHANGED
@@ -148,7 +148,7 @@ module Scout::Config
148
148
  end
149
149
 
150
150
  def self.process_config(config)
151
- if Misc.is_filename?(config) && File.exist?(config)
151
+ if Path.is_filename?(config) && File.exist?(config)
152
152
  Scout::Config.load_file(config)
153
153
  elsif Scout.etc.config_profile[config].exists?
154
154
  Scout::Config.load_file(Scout.etc.config_profile[config].find)
@@ -92,6 +92,7 @@ class WorkerException < ScoutException
92
92
  end
93
93
  end
94
94
 
95
+ class SemaphoreInterrupted < TryAgain; end
95
96
 
96
97
  #class OpenGzipError < StandardError; end
97
98
  #
@@ -2,7 +2,6 @@ require_relative 'color_class'
2
2
  require_relative '../indiferent_hash'
3
3
 
4
4
  require 'term/ansicolor'
5
- require 'colorist'
6
5
 
7
6
  module Colorize
8
7
  def self.colors=(colors)
@@ -135,7 +134,7 @@ module Log
135
134
  attr_accessor :nocolor
136
135
  end
137
136
 
138
- self.nocolor = ENV["RBBT_NOCOLOR"] == 'true'
137
+ self.nocolor = ENV["SCOUT_NOCOLOR"] == 'true'
139
138
 
140
139
  WHITE, DARK, GREEN, YELLOW, RED = Color::SOLARIZED.values_at :base0, :base00, :green, :yellow, :magenta
141
140
 
@@ -153,6 +152,9 @@ module Log
153
152
  :start => cyan,
154
153
  :done => green,
155
154
  :error => red,
155
+ :time => cyan,
156
+ :task => yellow,
157
+ :workflow => yellow,
156
158
  })
157
159
  HIGHLIGHT = "\033[1m"
158
160
 
@@ -229,7 +229,7 @@ module Log
229
229
  done_msg << Log.color(:magenta, " · " << desc)
230
230
  print(io, Log.up_lines(@depth) << done_msg << Log.down_lines(@depth))
231
231
 
232
- File.rm file if file and File.exist?(file)
232
+ FileUtils.rm file if file and File.exist?(file)
233
233
 
234
234
  begin
235
235
  @callback.call self
@@ -29,7 +29,7 @@ module Log
29
29
 
30
30
  def self.new_bar(max, options = {})
31
31
  options, max = max, nil if Hash === max
32
- max = options[:max] if max.nil?
32
+ max = options[:max] if options && max.nil?
33
33
  cleanup_bars
34
34
  BAR_MUTEX.synchronize do
35
35
  Log::LAST.replace "new_bar" if Log::LAST == "progress"
@@ -82,7 +82,7 @@ module Log
82
82
  end
83
83
 
84
84
  def self.with_bar(max = nil, options = {})
85
- bar = new_bar(max, options)
85
+ bar = options.include?(:bar) ? options[:bar] : new_bar(max, options)
86
86
  begin
87
87
  error = false
88
88
  keep = false
@@ -96,6 +96,75 @@ module Log
96
96
  remove_bar(bar, error) if bar && ! keep
97
97
  end
98
98
  end
99
+
100
+ def self.guess_obj_max(obj)
101
+ begin
102
+ case obj
103
+ when (defined? Step and Step)
104
+ if obj.done?
105
+ path = obj.path
106
+ path = path.find if path.respond_to? :find
107
+ if File.exist? path
108
+ CMD.cmd("wc -l '#{path}'").read.to_i
109
+ else
110
+ nil
111
+ end
112
+ else
113
+ nil
114
+ end
115
+ when TSV
116
+ obj.length
117
+ when Array, Hash
118
+ obj.size
119
+ when File
120
+ return nil if Open.gzip?(obj.filename) or Open.bgzip?(obj.filename) or Open.remote?(obj.filename)
121
+ CMD.cmd("wc -l '#{obj.filename}'").read.to_i
122
+ when Path, String
123
+ obj = obj.find if Path === obj
124
+ if File.exist? obj
125
+ return nil if Open.gzip?(obj) or Open.bgzip?(obj)
126
+ CMD.cmd("wc -l '#{obj}'").read.to_i
127
+ else
128
+ nil
129
+ end
130
+ end
131
+ rescue Exception
132
+ nil
133
+ end
134
+ end
135
+
136
+ def self.get_obj_bar(obj, bar = nil)
137
+ return nil if bar.nil? || bar == false
138
+ case bar
139
+ when String
140
+ max = guess_obj_max(obj)
141
+ Log::ProgressBar.new_bar(max, {:desc => bar})
142
+ when TrueClass
143
+ max = guess_obj_max(obj)
144
+ Log::ProgressBar.new_bar(max)
145
+ when Numeric
146
+ max = guess_obj_max(obj)
147
+ Log::ProgressBar.new_bar(bar)
148
+ when Hash
149
+ max = IndiferentHash.process_options(bar, :max) || max
150
+ Log::ProgressBar.new_bar(max, bar)
151
+ when Log::ProgressBar
152
+ bar.max ||= guess_obj_max(obj)
153
+ bar
154
+ else
155
+ if (defined? Step and Step === bar)
156
+ max = guess_obj_max(obj)
157
+ Log::ProgressBar.new_bar(max, {:desc => bar.status, :file => bar.file(:progress)})
158
+ else
159
+ bar
160
+ end
161
+ end
162
+ end
163
+
164
+ def self.with_obj_bar(obj, bar = true, &block)
165
+ bar = get_obj_bar(obj, bar)
166
+ with_bar nil, bar: bar, &block
167
+ end
99
168
  end
100
169
  end
101
170
 
@@ -8,7 +8,7 @@ module Log
8
8
 
9
9
  def self.no_bar
10
10
  @@no_bar = false unless defined?(@@no_bar)
11
- @@no_bar || ENV["RBBT_NO_PROGRESS"] == "true"
11
+ @@no_bar || ENV["SCOUT_NO_PROGRESS"] == "true"
12
12
  end
13
13
 
14
14
  class ProgressBar
@@ -0,0 +1,107 @@
1
+ module Log
2
+ def self.trap_std(msg = "STDOUT", msge = "STDERR", severity = 0, severity_err = nil)
3
+ sout, sin = Misc.pipe
4
+ soute, sine = Misc.pipe
5
+ backup_stderr = STDERR.dup
6
+ backup_stdout = STDOUT.dup
7
+ old_logfile = Log.logfile
8
+ Log.logfile(backup_stderr)
9
+
10
+ severity_err ||= severity
11
+ th_log = Thread.new do
12
+ while line = sout.gets
13
+ Log.logn "#{msg}: " + line, severity
14
+ end
15
+ end
16
+
17
+ th_loge = Thread.new do
18
+ while line = soute.gets
19
+ Log.logn "#{msge}: " + line, severity_err
20
+ end
21
+ end
22
+
23
+ begin
24
+ STDOUT.reopen(sin)
25
+ STDERR.reopen(sine)
26
+ yield
27
+ ensure
28
+ STDERR.reopen backup_stderr
29
+ STDOUT.reopen backup_stdout
30
+ sin.close
31
+ sine.close
32
+ th_log.join
33
+ th_loge.join
34
+ backup_stdout.close
35
+ backup_stderr.close
36
+ Log.logfile = old_logfile
37
+ end
38
+ end
39
+
40
+ def self.trap_stderr(msg = "STDERR", severity = 0)
41
+ sout, sin = Misc.pipe
42
+ backup_stderr = STDERR.dup
43
+ old_logfile = Log.logfile
44
+ Log.logfile(backup_stderr)
45
+
46
+ th_log = Thread.new do
47
+ while line = sout.gets
48
+ Log.logn "#{msg}: " + line, severity
49
+ end
50
+ end
51
+
52
+ begin
53
+ STDERR.reopen(sin)
54
+ yield
55
+ sin.close
56
+ ensure
57
+ STDERR.reopen backup_stderr
58
+ th_log.join
59
+ backup_stderr.close
60
+ Log.logfile = old_logfile
61
+ end
62
+ end
63
+
64
+ def self._ignore_stderr
65
+ begin
66
+ File.open('/dev/null', 'w') do |f|
67
+ backup_stderr = STDERR.dup
68
+ STDERR.reopen(f)
69
+ begin
70
+ yield
71
+ ensure
72
+ STDERR.reopen backup_stderr
73
+ backup_stderr.close
74
+ end
75
+ end
76
+ rescue Errno::ENOENT
77
+ yield
78
+ end
79
+ end
80
+
81
+
82
+ def self.ignore_stderr(&block)
83
+ _ignore_stderr &block
84
+ end
85
+
86
+ def self._ignore_stdout
87
+ begin
88
+ File.open('/dev/null', 'w') do |f|
89
+ backup_stdout = STDOUT.dup
90
+ STDOUT.reopen(f)
91
+ begin
92
+ yield
93
+ ensure
94
+ STDOUT.reopen backup_stdout
95
+ backup_stdout.close
96
+ end
97
+ end
98
+ rescue Errno::ENOENT
99
+ yield
100
+ end
101
+ end
102
+
103
+
104
+ def self.ignore_stdout(&block)
105
+ _ignore_stdout &block
106
+ end
107
+ end