scout-gear 7.1.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +65 -2
  3. data/VERSION +1 -1
  4. data/bin/scout +5 -1
  5. data/lib/rbbt-scout.rb +5 -0
  6. data/lib/scout/concurrent_stream.rb +13 -8
  7. data/lib/scout/config.rb +168 -0
  8. data/lib/scout/exceptions.rb +5 -3
  9. data/lib/scout/indiferent_hash/options.rb +1 -0
  10. data/lib/scout/indiferent_hash.rb +4 -2
  11. data/lib/scout/log/color.rb +3 -2
  12. data/lib/scout/log/progress/report.rb +1 -0
  13. data/lib/scout/log/progress/util.rb +66 -1
  14. data/lib/scout/log/progress.rb +5 -3
  15. data/lib/scout/log.rb +3 -2
  16. data/lib/scout/misc/helper.rb +31 -0
  17. data/lib/scout/misc/monitor.rb +4 -1
  18. data/lib/scout/misc/system.rb +15 -0
  19. data/lib/scout/misc.rb +2 -0
  20. data/lib/scout/named_array.rb +68 -0
  21. data/lib/scout/open/stream.rb +58 -33
  22. data/lib/scout/path/find.rb +27 -3
  23. data/lib/scout/path/util.rb +7 -4
  24. data/lib/scout/persist/serialize.rb +7 -14
  25. data/lib/scout/persist.rb +46 -12
  26. data/lib/scout/resource/produce.rb +7 -94
  27. data/lib/scout/resource/software.rb +176 -0
  28. data/lib/scout/semaphore.rb +8 -1
  29. data/lib/scout/tsv/dumper.rb +112 -0
  30. data/lib/scout/tsv/index.rb +161 -0
  31. data/lib/scout/tsv/open.rb +128 -0
  32. data/lib/scout/tsv/parser.rb +230 -30
  33. data/lib/scout/tsv/path.rb +13 -0
  34. data/lib/scout/tsv/persist/adapter.rb +367 -0
  35. data/lib/scout/tsv/persist/fix_width_table.rb +324 -0
  36. data/lib/scout/tsv/persist/serialize.rb +117 -0
  37. data/lib/scout/tsv/persist/tokyocabinet.rb +113 -0
  38. data/lib/scout/tsv/persist.rb +13 -0
  39. data/lib/scout/tsv/traverse.rb +143 -0
  40. data/lib/scout/tsv/util/filter.rb +303 -0
  41. data/lib/scout/tsv/util/process.rb +73 -0
  42. data/lib/scout/tsv/util/select.rb +220 -0
  43. data/lib/scout/tsv/util.rb +82 -0
  44. data/lib/scout/tsv.rb +16 -3
  45. data/lib/scout/work_queue/worker.rb +4 -4
  46. data/lib/scout/work_queue.rb +22 -7
  47. data/lib/scout/workflow/definition.rb +101 -4
  48. data/lib/scout/workflow/step/config.rb +18 -0
  49. data/lib/scout/workflow/step/dependencies.rb +40 -0
  50. data/lib/scout/workflow/step/file.rb +15 -0
  51. data/lib/scout/workflow/step/info.rb +35 -4
  52. data/lib/scout/workflow/step/progress.rb +14 -0
  53. data/lib/scout/workflow/step/provenance.rb +148 -0
  54. data/lib/scout/workflow/step.rb +71 -17
  55. data/lib/scout/workflow/task.rb +10 -5
  56. data/lib/scout/workflow/usage.rb +3 -1
  57. data/lib/scout/workflow.rb +11 -3
  58. data/lib/scout-gear.rb +1 -0
  59. data/lib/scout.rb +1 -0
  60. data/scout-gear.gemspec +64 -10
  61. data/scout_commands/find +1 -1
  62. data/scout_commands/workflow/task +16 -9
  63. data/scout_commands/workflow/task_old +2 -2
  64. data/share/software/install_helpers +523 -0
  65. data/test/scout/log/test_progress.rb +0 -2
  66. data/test/scout/misc/test_system.rb +21 -0
  67. data/test/scout/open/test_stream.rb +160 -1
  68. data/test/scout/path/test_find.rb +14 -7
  69. data/test/scout/resource/test_software.rb +24 -0
  70. data/test/scout/test_config.rb +66 -0
  71. data/test/scout/test_meta_extension.rb +10 -0
  72. data/test/scout/test_named_array.rb +19 -0
  73. data/test/scout/test_persist.rb +96 -0
  74. data/test/scout/test_tmpfile.rb +1 -1
  75. data/test/scout/test_tsv.rb +50 -1
  76. data/test/scout/test_work_queue.rb +41 -13
  77. data/test/scout/tsv/persist/test_adapter.rb +44 -0
  78. data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
  79. data/test/scout/tsv/persist/test_tokyocabinet.rb +92 -0
  80. data/test/scout/tsv/test_dumper.rb +44 -0
  81. data/test/scout/tsv/test_index.rb +156 -0
  82. data/test/scout/tsv/test_open.rb +9 -0
  83. data/test/scout/tsv/test_parser.rb +114 -3
  84. data/test/scout/tsv/test_persist.rb +43 -0
  85. data/test/scout/tsv/test_traverse.rb +116 -0
  86. data/test/scout/tsv/test_util.rb +23 -0
  87. data/test/scout/tsv/util/test_filter.rb +188 -0
  88. data/test/scout/tsv/util/test_process.rb +47 -0
  89. data/test/scout/tsv/util/test_select.rb +44 -0
  90. data/test/scout/work_queue/test_worker.rb +66 -9
  91. data/test/scout/workflow/step/test_dependencies.rb +25 -0
  92. data/test/scout/workflow/step/test_info.rb +15 -17
  93. data/test/scout/workflow/step/test_load.rb +19 -21
  94. data/test/scout/workflow/step/test_provenance.rb +25 -0
  95. data/test/scout/workflow/test_step.rb +206 -10
  96. data/test/scout/workflow/test_task.rb +0 -3
  97. data/test/test_helper.rb +9 -1
  98. metadata +50 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d00b2f7d1a5156c6259729b245722979b34132ca3a66922110662fadfc56b65
4
- data.tar.gz: 057a511570907a68d6ee7d962705bfe3cc92325c1fc026b45c5ff0dfb0634f96
3
+ metadata.gz: 7273030ac34bd180620d9075ee85b26d8a9883831a5925fc911915f1edeeecf3
4
+ data.tar.gz: 4e445acb896844240c0024b7754cffee93af71feb62f9c4251fda70aee79121a
5
5
  SHA512:
6
- metadata.gz: 8ca8280c5f4ac63ca98cc8c2388700e29752ec37b008d3f9b54a7bab13569af24fc94afbbfc60d9e295ca81c9a2e5a64bdab83e6cab7c9dd6d531013d72f6954
7
- data.tar.gz: c056280d255116ed9a3c74ee8c1b4c367f30abf6ec60d278180534afc1728d104f89ac247fa0b1d7fb751692b869e2cf73a6a8ac8b6bef8f07e411a59e476409
6
+ metadata.gz: '029a8eb23eda77c7e0c11ac2966e1e8ebf3eae479bbee0c76e113f5b839c655e97e0fec5025cc3c251795afcfc92ac3395a79b68c8eb99158d1cee8e2310f002'
7
+ data.tar.gz: 04ed4bcabfa7c41b80ba520074404bfb09c723ecdb8d02a2052f73fe86759bab7fdadff31f0f66284ed4938ebe5a1cad56fb94182b3edcc0de6325decdcb84f6
data/.vimproject CHANGED
@@ -18,6 +18,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
18
18
  lib=lib {
19
19
  scout-gear.rb
20
20
  workflow-scout.rb
21
+ rbbt-scout.rb
21
22
  scout.rb
22
23
  scout=scout{
23
24
  meta_extension.rb
@@ -30,7 +31,10 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
30
31
  digest.rb
31
32
  filesystem.rb
32
33
  monitor.rb
34
+ system.rb
35
+ helper.rb
33
36
  }
37
+ named_array.rb
34
38
  indiferent_hash.rb
35
39
  indiferent_hash=indiferent_hash{
36
40
  case_insensitive.rb
@@ -77,10 +81,12 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
77
81
  produce=produce{
78
82
  rake.rb
79
83
  }
84
+ software.rb
80
85
  scout.rb
81
86
  util.rb
82
87
  path.rb
83
88
  }
89
+ config.rb
84
90
  persist.rb
85
91
  persist=persist{
86
92
  serialize.rb
@@ -94,6 +100,11 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
94
100
  step=step{
95
101
  info.rb
96
102
  load.rb
103
+ file.rb
104
+ config.rb
105
+ dependencies.rb
106
+ provenance.rb
107
+ progress.rb
97
108
  }
98
109
  task.rb
99
110
  task=task{
@@ -112,21 +123,70 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
112
123
  tsv.rb
113
124
  tsv=tsv{
114
125
  parser.rb
126
+ dumper.rb
127
+ persist.rb
128
+ persist=persist{
129
+ adapter.rb
130
+ serialize.rb
131
+ tokyocabinet.rb
132
+ fix_width_table.rb
133
+ }
134
+ index.rb
135
+ traverse.rb
136
+ util.rb
137
+ util=util{
138
+ process.rb
139
+ select.rb
140
+ filter.rb
141
+ }
142
+ path.rb
143
+ open.rb
115
144
  }
116
145
  }
117
146
  }
118
147
  test=test {
119
148
  test_helper.rb
149
+ test_scout-gear.rb
120
150
  scout=scout{
151
+ test_cmd.rb
152
+ test_concurrent_stream.rb
153
+ test_config.rb
121
154
  test_indiferent_hash.rb
155
+ test_log.rb
156
+ test_meta_extension.rb
157
+ test_misc.rb
158
+ test_named_array.rb
159
+ test_open.rb
160
+ test_path.rb
161
+ test_persist.rb
162
+ test_resource.rb
163
+ test_semaphore.rb
164
+ test_tmpfile.rb
165
+ test_tsv.rb
166
+ test_work_queue.rb
167
+ test_workflow.rb
168
+ workflow=workflow{
169
+ test_definition.rb
170
+ test_documentation.rb
171
+ test_step.rb
172
+ test_task.rb
173
+ test_usage.rb
174
+ test_util.rb
175
+ }
122
176
  indiferent_hash=indiferent_hash{
177
+ test_case_insensitive.rb
123
178
  test_options.rb
124
179
  }
125
- test_log.rb
126
- test_tmpfile.rb
180
+ }
181
+ }
182
+ share=share{
183
+ software=software{
184
+ install_helpers
127
185
  }
128
186
  }
129
187
 
188
+
189
+
130
190
  modules=modules{
131
191
  rbbt-util=rbbt-util filter="*.rb *.rake Rakefile *.rdoc *.R *.sh *.js *.haml *.sass *.txt *.conf LICENSE" {
132
192
  Migration-1.9.txt
@@ -386,6 +446,9 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
386
446
  resource.rb
387
447
  resource=resource{
388
448
  path.rb
449
+ path=path{
450
+ refactor.rb
451
+ }
389
452
  util.rb
390
453
  with_key.rb
391
454
  rake.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.1.0
1
+ 7.3.0
data/bin/scout CHANGED
@@ -37,6 +37,11 @@ if dev_dir
37
37
  $LOAD_PATH.unshift f
38
38
  end
39
39
  end
40
+ ['rbbt-*/lib'].each do |pattern|
41
+ Dir.glob(File.join(File.expand_path(dev_dir), pattern)).each do |f|
42
+ $LOAD_PATH.unshift f
43
+ end
44
+ end
40
45
  end
41
46
 
42
47
  Log.nocolor = true if ARGV.include? "--nocolor"
@@ -112,7 +117,6 @@ def commands(prev)
112
117
  end
113
118
 
114
119
  def scout_usage(prev = nil)
115
- puts
116
120
  puts SOPT.doc
117
121
 
118
122
  if prev
data/lib/rbbt-scout.rb ADDED
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.join(__dir__, '../modules/rbbt-util/lib')
2
+ module Rbbt
3
+ extend Resource
4
+ self.pkgdir = 'rbbt'
5
+ end
@@ -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
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 = IndiferentHash.process_options options, :threads, :pids, :callback, :abort_callback, :filename, :autojoin, :lockfile, :no_fail, :pair
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 ||= []
@@ -24,6 +24,7 @@ module ConcurrentStream
24
24
  stream.no_fail = no_fail unless no_fail.nil?
25
25
  stream.std_err = ""
26
26
 
27
+ stream.next = next_stream unless next_stream.nil?
27
28
  stream.pair = pair unless pair.nil?
28
29
 
29
30
  callback = block if block_given?
@@ -53,7 +54,7 @@ module ConcurrentStream
53
54
 
54
55
  stream.filename = filename.nil? ? stream.inspect.split(":").last[0..-2] : filename
55
56
 
56
- stream.lockfile = lockfile unless lockfile.nil?
57
+ stream.lock = lock unless lock.nil?
57
58
 
58
59
  stream.aborted = false
59
60
 
@@ -61,7 +62,7 @@ module ConcurrentStream
61
62
  end
62
63
 
63
64
  def annotate(stream)
64
- 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)
65
66
  stream
66
67
  end
67
68
 
@@ -135,11 +136,12 @@ module ConcurrentStream
135
136
  begin
136
137
  join_threads
137
138
  join_pids
139
+ raise stream_exception if stream_exception
138
140
  join_callback
139
141
  close unless closed?
140
142
  ensure
141
143
  @joined = true
142
- lockfile.unlock if lockfile and lockfile.locked?
144
+ lock.unlock if lock and lock.locked?
143
145
  raise stream_exception if stream_exception
144
146
  end
145
147
  end
@@ -159,7 +161,7 @@ module ConcurrentStream
159
161
  @threads.each do |t|
160
162
  next if t == Thread.current
161
163
  begin
162
- t.join unless t == Thread.current
164
+ t.join
163
165
  rescue Aborted
164
166
  rescue Exception
165
167
  Log.debug "Thread (#{name}) exception: #{$!.message}"
@@ -204,8 +206,8 @@ module ConcurrentStream
204
206
  ensure
205
207
  close unless closed?
206
208
 
207
- if lockfile and lockfile.locked?
208
- lockfile.unlock
209
+ if lock and lock.locked?
210
+ lock.unlock
209
211
  end
210
212
  end
211
213
  end
@@ -230,6 +232,9 @@ module ConcurrentStream
230
232
  def read(*args)
231
233
  begin
232
234
  super(*args)
235
+ rescue
236
+ raise stream_exception if stream_exception
237
+ raise $!
233
238
  ensure
234
239
  begin
235
240
  close unless closed?
@@ -0,0 +1,168 @@
1
+ require_relative 'path'
2
+ require_relative 'resource'
3
+ require_relative 'resource/scout'
4
+
5
+ module Scout::Config
6
+
7
+ CACHE = IndiferentHash.setup({})
8
+
9
+ GOT_KEYS=[]
10
+
11
+ def self.add_entry(key, value, tokens)
12
+ tokens = [tokens] unless Array === tokens
13
+ tokens << "key:#{key}" unless tokens.include?("key:#{key}")
14
+ CACHE[key.to_s] ||= []
15
+ CACHE[key.to_s] << [tokens, value]
16
+ end
17
+
18
+ def self.load_file(file)
19
+ Log.debug "Loading config file: #{ file }"
20
+ TSV.traverse file, :type => :array do |line|
21
+ next if line =~ /^#/
22
+ key, value, *tokens = line.strip.split(/\s/)
23
+
24
+ self.add_entry(key, value, tokens) if key
25
+ end
26
+ end
27
+
28
+ def self.load_config
29
+ Scout.etc.config.find_all.reverse.each do |file|
30
+ self.load_file(file)
31
+ end
32
+ end
33
+
34
+ def self.set(values, *tokens)
35
+ if not Hash === values
36
+ values = {values => tokens.shift}
37
+ end
38
+
39
+ values.each do |key,value|
40
+ add_entry key, value, tokens
41
+ end
42
+ end
43
+
44
+ def self.token_priority(token)
45
+ token, _sep, priority = token.to_s.partition("::")
46
+
47
+ if priority.nil? || priority.empty?
48
+ type, _sep, rest = token.partition(":")
49
+ priority = case type
50
+ when "workflow"
51
+ 4
52
+ when "task"
53
+ 3
54
+ when "file"
55
+ 2
56
+ when "line"
57
+ 1
58
+ when "key"
59
+ 20
60
+ else
61
+ 10
62
+ end
63
+ else
64
+ priority = priority.to_i
65
+ end
66
+
67
+ [token, priority]
68
+ end
69
+
70
+ def self.match(entries, give_token)
71
+ priorities = {}
72
+ entries.each do |tokens, value|
73
+ best_prio = nil
74
+ tokens = [tokens] unless Array === tokens
75
+ tokens.each do |tok|
76
+ tok, prio = token_priority tok
77
+ next unless tok == give_token
78
+
79
+ best_prio = prio if best_prio.nil? or best_prio > prio
80
+ next if prio > best_prio
81
+
82
+ priorities[prio] ||= []
83
+ priorities[prio].unshift value
84
+ end
85
+ end if entries
86
+ priorities
87
+ end
88
+
89
+ # For equal priorities the matching prioritizes tokens ealier in the list
90
+ def self.get(key, *tokens)
91
+ options = tokens.pop if Hash === tokens.last
92
+ default = options.nil? ? nil : options[:default]
93
+
94
+ tokens = ["key:" + key] if tokens.empty?
95
+
96
+ tokens = tokens.flatten
97
+ file, _sep, line = caller.reject{|l|
98
+ l =~ /rbbt\/(?:resource\.rb|workflow\.rb)/ or
99
+ l =~ /rbbt\/resource\/path\.rb/ or
100
+ l =~ /rbbt\/util\/misc\.rb/ or
101
+ l =~ /accessor\.rb/ or
102
+ l =~ /progress-monitor\.rb/
103
+ }.first.partition(":")
104
+
105
+ File.expand_path(file)
106
+
107
+ tokens << ("file:" << file)
108
+ tokens << ("line:" << file << ":" << line.sub(/:in \`.*/,''))
109
+
110
+ entries = CACHE[key.to_s]
111
+ priorities = {}
112
+ tokens.each do |token|
113
+ token_prio = match entries, token.to_s
114
+ token_prio.each do |prio, values|
115
+ priorities[prio] ||= []
116
+ priorities[prio].concat(values)
117
+ end
118
+ end
119
+
120
+ value = priorities.empty? ? default : priorities.collect{|p| p }.sort_by{|p,v| p}.first.last.first
121
+ value = false if value == 'false'
122
+
123
+ Log.debug "Value #{value.inspect} for config key '#{ key }': #{tokens * ", "}"
124
+ GOT_KEYS << [key, value, tokens]
125
+
126
+ if String === value && m = value.match(/^env:(.*)/)
127
+ variable = m.captures.first
128
+ ENV[variable]
129
+ elsif value == 'nil'
130
+ nil
131
+ else
132
+ value
133
+ end
134
+ end
135
+
136
+ def self.with_config
137
+ saved_config = {}
138
+ CACHE.each do |k,v|
139
+ saved_config[k] = v.dup
140
+ end
141
+ saved_got_keys = GOT_KEYS.dup
142
+ begin
143
+ yield
144
+ ensure
145
+ CACHE.replace(saved_config)
146
+ GOT_KEYS.replace(saved_got_keys)
147
+ end
148
+ end
149
+
150
+ def self.process_config(config)
151
+ if Misc.is_filename?(config) && File.exist?(config)
152
+ Scout::Config.load_file(config)
153
+ elsif Scout.etc.config_profile[config].exists?
154
+ Scout::Config.load_file(Scout.etc.config_profile[config].find)
155
+ else
156
+ key, value, *tokens = config.split(/\s/)
157
+ tokens = tokens.collect do |tok|
158
+ tok, _sep, prio = tok.partition("::")
159
+ prio = "0" if prio.nil? or prio.empty?
160
+ [tok, prio] * "::"
161
+ end
162
+ Scout::Config.set({key => value}, *tokens)
163
+ end
164
+ end
165
+
166
+
167
+ self.load_config
168
+ end
@@ -85,13 +85,14 @@ class DoneProcessing < Exception
85
85
  end
86
86
 
87
87
  class WorkerException < ScoutException
88
- attr_accessor :exception, :pid
89
- def initialize(exception, pid)
90
- @exception = exception
88
+ attr_accessor :worker_exception, :pid
89
+ def initialize(worker_exception, pid)
90
+ @worker_exception = worker_exception
91
91
  @pid = pid
92
92
  end
93
93
  end
94
94
 
95
+ class SemaphoreInterrupted < TryAgain; end
95
96
 
96
97
  #class OpenGzipError < StandardError; end
97
98
  #
@@ -137,3 +138,4 @@ end
137
138
  #
138
139
  #
139
140
  #
141
+ class ResourceNotFound < ScoutException; end
@@ -29,6 +29,7 @@ module IndiferentHash
29
29
 
30
30
  def self.pull_keys(hash, prefix)
31
31
  new = {}
32
+ prefix = prefix.to_s
32
33
  hash.keys.each do |key|
33
34
  if key.to_s =~ /#{ prefix }_(.*)/
34
35
  case
@@ -58,9 +58,11 @@ module IndiferentHash
58
58
  def delete(key)
59
59
  case key
60
60
  when Symbol, Module
61
- super(key) || super(key.to_s)
61
+ v = super(key)
62
+ v.nil? ? super(key.to_s) : v
62
63
  when String
63
- super(key) || super(key.to_sym)
64
+ v = super(key)
65
+ v.nil? ? super(key.to_sym) : v
64
66
  else
65
67
  super(key)
66
68
  end
@@ -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)
@@ -185,8 +184,10 @@ module Log
185
184
  :red
186
185
  when :waiting, :queued
187
186
  :yellow
188
- when :started, :start, :streamming
187
+ when :started, :streamming
189
188
  :cyan
189
+ when :start
190
+ :title
190
191
  else
191
192
  :cyan
192
193
  end
@@ -2,6 +2,7 @@ require 'yaml'
2
2
  module Log
3
3
  class ProgressBar
4
4
  def print(io, str)
5
+ return if self.severity && self.severity < Log.severity
5
6
  return if Log.no_bar
6
7
  STDERR.print str
7
8
  Log.logfile.puts str unless Log.logfile.nil?
@@ -81,7 +81,7 @@ module Log
81
81
  Log::ProgressBar.remove_bar self, error
82
82
  end
83
83
 
84
- def self.with_bar(max, options = {})
84
+ def self.with_bar(max = nil, options = {})
85
85
  bar = new_bar(max, options)
86
86
  begin
87
87
  error = false
@@ -96,6 +96,71 @@ 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) 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
+ end
130
+ end
131
+ rescue Exception
132
+ Log.exception $!
133
+ nil
134
+ end
135
+ end
136
+
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)
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
99
163
  end
164
+
100
165
  end
101
166
 
@@ -15,20 +15,22 @@ module Log
15
15
 
16
16
  class << self
17
17
  attr_accessor :default_file
18
+ attr_accessor :default_severity
18
19
  end
19
20
 
20
21
  attr_accessor :max, :ticks, :frequency, :depth, :desc, :file, :bytes, :process, :callback, :severity
21
22
 
22
23
  def initialize(max = nil, options = {})
23
- depth, desc, file, bytes, frequency, process, callback =
24
- IndiferentHash.process_options options, :depth, :desc, :file, :bytes, :frequency, :process, :callback,
25
- :depth => 0, :frequency => 2
24
+ depth, desc, file, bytes, frequency, process, callback, severity =
25
+ IndiferentHash.process_options options, :depth, :desc, :file, :bytes, :frequency, :process, :callback, :severity,
26
+ :depth => 0, :frequency => 2, :severity => Log::ProgressBar.default_severity
26
27
 
27
28
  max = nil if TrueClass === max
28
29
 
29
30
  @max = max
30
31
  @ticks = 0
31
32
  @frequency = frequency
33
+ @severity = severity
32
34
  @last_time = nil
33
35
  @last_count = nil
34
36
  @last_percent = nil
data/lib/scout/log.rb CHANGED
@@ -186,11 +186,12 @@ module Log
186
186
 
187
187
  def self.exception(e)
188
188
  stack = caller
189
+ backtrace = e.backtrace || []
189
190
  if ENV["RBBT_ORIGINAL_STACK"] == 'true'
190
191
  error([e.class.to_s, e.message].compact * ": " )
191
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(e.backtrace)*"\n")
192
+ error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace)*"\n")
192
193
  else
193
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(e.backtrace.reverse)*"\n")
194
+ error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace.reverse)*"\n")
194
195
  error([e.class.to_s, e.message].compact * ": " )
195
196
  end
196
197
  end
@@ -0,0 +1,31 @@
1
+ module Misc
2
+ def self.intersect_sorted_arrays(a1, a2)
3
+ e1, e2 = a1.shift, a2.shift
4
+ intersect = []
5
+ while true
6
+ break if e1.nil? or e2.nil?
7
+ case e1 <=> e2
8
+ when 0
9
+ intersect << e1
10
+ e1, e2 = a1.shift, a2.shift
11
+ when -1
12
+ e1 = a1.shift while not e1.nil? and e1 < e2
13
+ when 1
14
+ e2 = a2.shift
15
+ e2 = a2.shift while not e2.nil? and e2 < e1
16
+ end
17
+ end
18
+ intersect
19
+ end
20
+
21
+ def self.counts(array)
22
+ counts = {}
23
+ array.each do |e|
24
+ counts[e] ||= 0
25
+ counts[e] += 1
26
+ end
27
+
28
+ counts
29
+ end
30
+
31
+ end
@@ -1,4 +1,7 @@
1
1
  module Misc
2
+ def self.pid_alive?(pid)
3
+ !! Process.kill(0, pid) rescue false
4
+ end
2
5
  def self.benchmark(repeats = 1, message = nil)
3
6
  require 'benchmark'
4
7
  res = nil
@@ -11,7 +14,7 @@ module Misc
11
14
  if message
12
15
  puts "#{message }: #{ repeats } repeats"
13
16
  else
14
- puts "Benchmark for #{ repeats } repeats"
17
+ puts "Benchmark for #{ repeats } repeats (#{caller.first})"
15
18
  end
16
19
  puts measure
17
20
  rescue Exception
@@ -0,0 +1,15 @@
1
+ module Misc
2
+ def self.env_add(var, value, sep = ":", prepend = true)
3
+ if ENV[var].nil?
4
+ ENV[var] = value
5
+ elsif ENV[var] =~ /(#{sep}|^)#{Regexp.quote value}(#{sep}|$)/
6
+ return
7
+ else
8
+ if prepend
9
+ ENV[var] = value + sep + ENV[var]
10
+ else
11
+ ENV[var] += sep + value
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/scout/misc.rb CHANGED
@@ -3,6 +3,8 @@ require_relative 'misc/insist'
3
3
  require_relative 'misc/digest'
4
4
  require_relative 'misc/filesystem'
5
5
  require_relative 'misc/monitor'
6
+ require_relative 'misc/system'
7
+ require_relative 'misc/helper'
6
8
 
7
9
  module Misc
8
10
  end