scout-gear 7.3.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +20 -9
  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 +26 -23
  8. data/lib/scout/config.rb +1 -1
  9. data/lib/scout/log/color.rb +4 -1
  10. data/lib/scout/log/progress/report.rb +1 -1
  11. data/lib/scout/log/progress/util.rb +58 -54
  12. data/lib/scout/log/progress.rb +1 -1
  13. data/lib/scout/log/trap.rb +107 -0
  14. data/lib/scout/log.rb +56 -21
  15. data/lib/scout/meta_extension.rb +13 -6
  16. data/lib/scout/misc/digest.rb +1 -1
  17. data/lib/scout/misc/format.rb +12 -0
  18. data/lib/scout/misc/insist.rb +1 -1
  19. data/lib/scout/misc/monitor.rb +11 -0
  20. data/lib/scout/misc/system.rb +10 -0
  21. data/lib/scout/named_array.rb +65 -3
  22. data/lib/scout/open/lock/lockfile.rb +587 -0
  23. data/lib/scout/open/lock.rb +28 -2
  24. data/lib/scout/open/remote.rb +4 -0
  25. data/lib/scout/open/stream.rb +90 -15
  26. data/lib/scout/open/util.rb +13 -3
  27. data/lib/scout/path/find.rb +9 -1
  28. data/lib/scout/path/util.rb +35 -0
  29. data/lib/scout/persist/serialize.rb +18 -5
  30. data/lib/scout/persist.rb +28 -12
  31. data/lib/scout/resource/path.rb +53 -0
  32. data/lib/scout/resource/produce.rb +0 -8
  33. data/lib/scout/resource/util.rb +2 -1
  34. data/lib/scout/tmpfile.rb +7 -8
  35. data/lib/scout/tsv/attach.rb +177 -0
  36. data/lib/scout/tsv/change_id.rb +40 -0
  37. data/lib/scout/tsv/dumper.rb +72 -46
  38. data/lib/scout/tsv/index.rb +69 -13
  39. data/lib/scout/tsv/open.rb +138 -84
  40. data/lib/scout/tsv/parser.rb +135 -80
  41. data/lib/scout/tsv/path.rb +1 -2
  42. data/lib/scout/tsv/persist/adapter.rb +15 -45
  43. data/lib/scout/tsv/persist/fix_width_table.rb +3 -0
  44. data/lib/scout/tsv/persist/tokyocabinet.rb +4 -1
  45. data/lib/scout/tsv/persist.rb +4 -0
  46. data/lib/scout/tsv/transformer.rb +141 -0
  47. data/lib/scout/tsv/traverse.rb +96 -92
  48. data/lib/scout/tsv/util/filter.rb +9 -0
  49. data/lib/scout/tsv/util/reorder.rb +81 -0
  50. data/lib/scout/tsv/util/select.rb +78 -33
  51. data/lib/scout/tsv/util/unzip.rb +86 -0
  52. data/lib/scout/tsv/util.rb +60 -11
  53. data/lib/scout/tsv.rb +26 -3
  54. data/lib/scout/work_queue/socket.rb +6 -1
  55. data/lib/scout/work_queue/worker.rb +5 -2
  56. data/lib/scout/work_queue.rb +15 -8
  57. data/lib/scout/workflow/definition.rb +21 -2
  58. data/lib/scout/workflow/step/dependencies.rb +24 -4
  59. data/lib/scout/workflow/step/info.rb +36 -5
  60. data/lib/scout/workflow/step/provenance.rb +8 -7
  61. data/lib/scout/workflow/step/status.rb +45 -0
  62. data/lib/scout/workflow/step.rb +100 -34
  63. data/lib/scout/workflow/task/inputs.rb +14 -20
  64. data/lib/scout/workflow/task.rb +81 -46
  65. data/lib/scout/workflow/usage.rb +8 -6
  66. data/scout-gear.gemspec +24 -20
  67. data/scout_commands/workflow/task +34 -7
  68. data/test/scout/open/test_stream.rb +60 -58
  69. data/test/scout/path/test_find.rb +10 -1
  70. data/test/scout/resource/test_produce.rb +15 -0
  71. data/test/scout/test_meta_extension.rb +25 -0
  72. data/test/scout/test_named_array.rb +18 -0
  73. data/test/scout/test_persist.rb +6 -0
  74. data/test/scout/test_tsv.rb +212 -2
  75. data/test/scout/test_work_queue.rb +21 -19
  76. data/test/scout/tsv/persist/test_adapter.rb +1 -1
  77. data/test/scout/tsv/persist/test_tokyocabinet.rb +29 -1
  78. data/test/scout/tsv/test_attach.rb +227 -0
  79. data/test/scout/tsv/test_change_id.rb +98 -0
  80. data/test/scout/tsv/test_dumper.rb +1 -1
  81. data/test/scout/tsv/test_index.rb +35 -3
  82. data/test/scout/tsv/test_open.rb +160 -2
  83. data/test/scout/tsv/test_parser.rb +19 -2
  84. data/test/scout/tsv/test_persist.rb +2 -0
  85. data/test/scout/tsv/test_transformer.rb +108 -0
  86. data/test/scout/tsv/test_traverse.rb +88 -3
  87. data/test/scout/tsv/test_util.rb +1 -0
  88. data/test/scout/tsv/util/test_reorder.rb +94 -0
  89. data/test/scout/tsv/util/test_select.rb +25 -11
  90. data/test/scout/tsv/util/test_unzip.rb +112 -0
  91. data/test/scout/work_queue/test_socket.rb +0 -1
  92. data/test/scout/workflow/step/test_status.rb +31 -0
  93. data/test/scout/workflow/task/test_inputs.rb +14 -14
  94. data/test/scout/workflow/test_step.rb +3 -3
  95. data/test/scout/workflow/test_task.rb +168 -32
  96. data/test/scout/workflow/test_usage.rb +33 -6
  97. metadata +20 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7273030ac34bd180620d9075ee85b26d8a9883831a5925fc911915f1edeeecf3
4
- data.tar.gz: 4e445acb896844240c0024b7754cffee93af71feb62f9c4251fda70aee79121a
3
+ metadata.gz: 48f6bb392f3391e2816e701887bfd98617b1a68bc533c8b6de3307f25c84906d
4
+ data.tar.gz: 476858f63deaa7fa9fc531c7872bdaefa1d6b3ed32cdacbe41f53d1d170fcc87
5
5
  SHA512:
6
- metadata.gz: '029a8eb23eda77c7e0c11ac2966e1e8ebf3eae479bbee0c76e113f5b839c655e97e0fec5025cc3c251795afcfc92ac3395a79b68c8eb99158d1cee8e2310f002'
7
- data.tar.gz: 04ed4bcabfa7c41b80ba520074404bfb09c723ecdb8d02a2052f73fe86759bab7fdadff31f0f66284ed4938ebe5a1cad56fb94182b3edcc0de6325decdcb84f6
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 {
@@ -32,7 +32,6 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
32
32
  filesystem.rb
33
33
  monitor.rb
34
34
  system.rb
35
- helper.rb
36
35
  }
37
36
  named_array.rb
38
37
  indiferent_hash.rb
@@ -50,6 +49,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
50
49
  report.rb
51
50
  util.rb
52
51
  }
52
+ trap.rb
53
53
  }
54
54
  tmpfile.rb
55
55
  simple_opt.rb
@@ -71,6 +71,9 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
71
71
  open.rb
72
72
  open=open{
73
73
  lock.rb
74
+ lock=lock{
75
+ lockfile.rb
76
+ }
74
77
  stream.rb
75
78
  remote.rb
76
79
  util.rb
@@ -99,6 +102,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
99
102
  step.rb
100
103
  step=step{
101
104
  info.rb
105
+ status.rb
102
106
  load.rb
103
107
  file.rb
104
108
  config.rb
@@ -122,8 +126,17 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
122
126
  }
123
127
  tsv.rb
124
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
+ }
125
137
  parser.rb
126
138
  dumper.rb
139
+ transformer.rb
127
140
  persist.rb
128
141
  persist=persist{
129
142
  adapter.rb
@@ -133,12 +146,8 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
133
146
  }
134
147
  index.rb
135
148
  traverse.rb
136
- util.rb
137
- util=util{
138
- process.rb
139
- select.rb
140
- filter.rb
141
- }
149
+ attach.rb
150
+ change_id.rb
142
151
  path.rb
143
152
  open.rb
144
153
  }
@@ -309,6 +318,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
309
318
 
310
319
  workflow.rb
311
320
  workflow=workflow{
321
+ refactor.rb
312
322
  annotate.rb
313
323
 
314
324
  definition.rb
@@ -390,6 +400,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
390
400
 
391
401
  tsv.rb
392
402
  tsv=tsv{
403
+ refactor.rb
393
404
  parser.rb
394
405
  dumper.rb
395
406
 
@@ -513,7 +524,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
513
524
  test_path.rb
514
525
  }
515
526
  workflow=workflow{
516
- _test_soap.rb
527
+ test_soap.rb
517
528
  test_doc.rb
518
529
  test_step.rb
519
530
  test_task.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.3.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
@@ -141,7 +141,11 @@ module ConcurrentStream
141
141
  close unless closed?
142
142
  ensure
143
143
  @joined = true
144
- lock.unlock if lock and lock.locked?
144
+ begin
145
+ lock.unlock if lock && lock.locked?
146
+ rescue
147
+ Log.exception $!
148
+ end
145
149
  raise stream_exception if stream_exception
146
150
  end
147
151
  end
@@ -152,21 +156,17 @@ module ConcurrentStream
152
156
  name += " - file:#{filename}" if filename
153
157
  Log.low "Aborting threads (#{name}) - #{@threads.collect{|t| Log.fingerprint(t) } * ", "}"
154
158
 
155
- @threads.each do |t|
159
+ threads = @threads.dup
160
+ @threads.clear
161
+ threads.each do |t|
156
162
  next if t == Thread.current
163
+ next if t["aborted"]
164
+ t["aborted"] = true
165
+ exception = exception.nil? ? Aborted.new : exception
157
166
  Log.debug "Aborting thread #{Log.fingerprint(t)} with exception: #{exception}"
158
- t.raise((exception.nil? ? Aborted.new : exception))
167
+ t.raise(exception)
168
+ t.join
159
169
  end
160
-
161
- @threads.each do |t|
162
- next if t == Thread.current
163
- begin
164
- t.join
165
- rescue Aborted
166
- rescue Exception
167
- Log.debug "Thread (#{name}) exception: #{$!.message}"
168
- end
169
- end
170
170
  end
171
171
 
172
172
  def abort_pids
@@ -217,12 +217,11 @@ module ConcurrentStream
217
217
  begin
218
218
  super(*args)
219
219
  rescue
220
- Log.exception $!
221
220
  self.abort
222
221
  self.join
223
222
  stream_raise_exception $!
224
223
  ensure
225
- self.join if self.closed? or self.eof?
224
+ self.join if ! @stream_exception && (self.closed? || self.eof?)
226
225
  end
227
226
  else
228
227
  super(*args)
@@ -232,15 +231,19 @@ module ConcurrentStream
232
231
  def read(*args)
233
232
  begin
234
233
  super(*args)
235
- rescue
236
- raise stream_exception if stream_exception
237
- raise $!
234
+ rescue Exception
235
+ @stream_exception ||= $!
236
+ raise @stream_exception
238
237
  ensure
239
- begin
240
- close unless closed?
241
- rescue Exception
242
- raise $! if ConcurrentStreamProcessFailed === $!
243
- 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
244
247
  end
245
248
  end
246
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)
@@ -134,7 +134,7 @@ module Log
134
134
  attr_accessor :nocolor
135
135
  end
136
136
 
137
- self.nocolor = ENV["RBBT_NOCOLOR"] == 'true'
137
+ self.nocolor = ENV["SCOUT_NOCOLOR"] == 'true'
138
138
 
139
139
  WHITE, DARK, GREEN, YELLOW, RED = Color::SOLARIZED.values_at :base0, :base00, :green, :yellow, :magenta
140
140
 
@@ -152,6 +152,9 @@ module Log
152
152
  :start => cyan,
153
153
  :done => green,
154
154
  :error => red,
155
+ :time => cyan,
156
+ :task => yellow,
157
+ :workflow => yellow,
155
158
  })
156
159
  HIGHLIGHT = "\033[1m"
157
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
@@ -98,69 +98,73 @@ module Log
98
98
  end
99
99
 
100
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
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
109
127
  else
110
128
  nil
111
129
  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) or Open.bgzip?(obj)
121
- CMD.cmd("wc -l '#{obj.path}'").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
130
  end
131
+ rescue Exception
132
+ nil
130
133
  end
131
- rescue Exception
132
- Log.exception $!
133
- nil
134
134
  end
135
- end
136
135
 
137
- def self.get_obj_bar(bar, obj)
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, nil)
145
- when Numeric
146
- max = guess_obj_max(obj)
147
- Log::ProgressBar.new_bar(bar)
148
- when Hash
149
- max = Misc.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)
136
+ def self.get_obj_bar(obj, bar = nil)
137
+ return nil if bar.nil? || bar == false
138
+ case bar
139
+ when String
156
140
  max = guess_obj_max(obj)
157
- Log::ProgressBar.new_bar(max, {:desc => bar.status, :file => bar.file(:progress)})
158
- else
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)
159
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
160
161
  end
161
162
  end
162
- end
163
- end
164
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
168
+ end
165
169
  end
166
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
data/lib/scout/log.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  require_relative 'log/color'
2
2
  require_relative 'log/fingerprint'
3
3
  require_relative 'log/progress'
4
+ require_relative 'log/trap'
4
5
 
5
6
  require 'io/console'
6
7
 
7
8
  module Log
9
+ class << self
10
+ attr_accessor :severity
11
+ attr_writer :tty_size, :logfile
12
+ end
13
+
8
14
  SEVERITY_NAMES ||= begin
9
15
  names = %w(DEBUG LOW MEDIUM HIGH INFO WARN ERROR NONE )
10
16
  names.each_with_index do |name,i|
@@ -12,13 +18,37 @@ module Log
12
18
  end
13
19
  names
14
20
  end
21
+ def self.default_severity
22
+ @@default_severity ||= begin
23
+ file = File.join(ENV["HOME"], '.scout/etc/log_severity')
24
+ if File.exist? file
25
+ File.open(file) do |f|
26
+ SEVERITY_NAMES.index f.read.strip
27
+ end
28
+ else
29
+ INFO
30
+ end
31
+ end
32
+ @@default_severity
33
+ end
15
34
 
16
- class << self
17
- attr_accessor :severity
18
- attr_writer :tty_size, :logfile
35
+ case ENV['SCOUT_LOG']
36
+ when 'DEBUG'
37
+ self.severity = DEBUG
38
+ when 'LOW'
39
+ self.severity = LOW
40
+ when 'MEDIUM'
41
+ self.severity = MEDIUM
42
+ when 'HIGH'
43
+ self.severity = HIGH
44
+ when nil
45
+ self.severity = default_severity
46
+ else
47
+ self.severity = default_severity
19
48
  end
20
49
 
21
50
 
51
+
22
52
  def self.tty_size
23
53
  @tty_size = begin
24
54
  IO.console.winsize.last
@@ -109,7 +139,11 @@ module Log
109
139
 
110
140
  sev_str = severity.to_s
111
141
 
112
- prefix = time << color(severity) << "[" << sev_str << "]" << color(0)
142
+ if ENV["SCOUT_DEBUG_PID"] == "true"
143
+ prefix = time << "[" << Process.pid.to_s << "]" << color(severity) << "[" << sev_str << "]" << color(0)
144
+ else
145
+ prefix = time << color(severity) << "[" << sev_str << "]" << color(0)
146
+ end
113
147
  message = "" << highlight << message << color(0) if severity >= INFO
114
148
  str = prefix << " " << message.to_s
115
149
 
@@ -187,7 +221,7 @@ module Log
187
221
  def self.exception(e)
188
222
  stack = caller
189
223
  backtrace = e.backtrace || []
190
- if ENV["RBBT_ORIGINAL_STACK"] == 'true'
224
+ if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
191
225
  error([e.class.to_s, e.message].compact * ": " )
192
226
  error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace)*"\n")
193
227
  else
@@ -243,7 +277,7 @@ module Log
243
277
  end
244
278
 
245
279
  def self.stack(stack)
246
- if ENV["RBBT_ORIGINAL_STACK"] == 'true'
280
+ if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
247
281
  STDERR.puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)
248
282
  color_stack(stack).each do |line|
249
283
  STDERR.puts line
@@ -280,21 +314,6 @@ module Log
280
314
  $stack_counts = {}
281
315
  res
282
316
  end
283
-
284
- case ENV['RBBT_LOG']
285
- when 'DEBUG'
286
- self.severity = DEBUG
287
- when 'LOW'
288
- self.severity = LOW
289
- when 'MEDIUM'
290
- self.severity = MEDIUM
291
- when 'HIGH'
292
- self.severity = HIGH
293
- when nil
294
- self.severity = INFO
295
- else
296
- self.severity = ENV['RBBT_LOG'].to_i
297
- end
298
317
  end
299
318
 
300
319
  def ppp(message)
@@ -373,3 +392,19 @@ def sss(level, &block)
373
392
  end
374
393
  end
375
394
 
395
+ $scout_debug_log = false
396
+ def ccc(obj=nil, file = $stdout)
397
+ if block_given?
398
+ old_scout_debug_log = $scout_debug_log
399
+ $scout_debug_log = 'true'
400
+ begin
401
+ yield
402
+ ensure
403
+ $scout_debug_log = old_scout_debug_log
404
+ end
405
+ else
406
+ Log.log_obj_inspect(obj, :info, file) if $scout_debug_log
407
+ end
408
+ end
409
+
410
+