scout-gear 9.1.0 → 10.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vimproject +1 -78
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/scout/offsite/exceptions.rb +9 -0
- data/lib/scout/offsite/ssh.rb +1 -0
- data/lib/scout/semaphore.rb +2 -0
- data/lib/scout/tsv/open.rb +1 -1
- data/lib/scout/tsv/parser.rb +1 -1
- data/lib/scout/tsv/persist/adapter.rb +2 -2
- data/lib/scout/tsv/persist.rb +1 -0
- data/lib/scout/tsv/util/sort.rb +74 -0
- data/lib/scout/tsv/util.rb +1 -0
- data/lib/scout/tsv.rb +1 -1
- data/lib/scout/work_queue/exceptions.rb +18 -0
- data/lib/scout/work_queue.rb +1 -0
- data/lib/scout/workflow/definition.rb +1 -1
- data/lib/scout/workflow/step/config.rb +1 -1
- data/lib/scout/workflow/step/status.rb +1 -0
- data/lib/scout/workflow/step.rb +49 -49
- data/lib/scout/workflow/task/inputs.rb +1 -1
- data/lib/scout/workflow/task.rb +2 -2
- data/lib/scout/workflow.rb +2 -2
- data/lib/scout-gear.rb +1 -10
- data/scout-gear.gemspec +9 -97
- data/scout_commands/workflow/task +3 -3
- data/test/scout/tsv/test_open.rb +1 -1
- data/test/scout/tsv/util/test_sort.rb +23 -0
- data/test/scout/workflow/task/test_inputs.rb +0 -4
- metadata +8 -109
- data/lib/scout/cmd.rb +0 -347
- data/lib/scout/concurrent_stream.rb +0 -284
- data/lib/scout/config.rb +0 -168
- data/lib/scout/exceptions.rb +0 -151
- data/lib/scout/indiferent_hash/case_insensitive.rb +0 -30
- data/lib/scout/indiferent_hash/options.rb +0 -115
- data/lib/scout/indiferent_hash.rb +0 -96
- data/lib/scout/log/color.rb +0 -224
- data/lib/scout/log/color_class.rb +0 -269
- data/lib/scout/log/fingerprint.rb +0 -69
- data/lib/scout/log/progress/report.rb +0 -244
- data/lib/scout/log/progress/util.rb +0 -173
- data/lib/scout/log/progress.rb +0 -106
- data/lib/scout/log/trap.rb +0 -107
- data/lib/scout/log.rb +0 -441
- data/lib/scout/meta_extension.rb +0 -100
- data/lib/scout/misc/digest.rb +0 -63
- data/lib/scout/misc/filesystem.rb +0 -25
- data/lib/scout/misc/format.rb +0 -255
- data/lib/scout/misc/helper.rb +0 -31
- data/lib/scout/misc/insist.rb +0 -56
- data/lib/scout/misc/monitor.rb +0 -66
- data/lib/scout/misc/system.rb +0 -73
- data/lib/scout/misc.rb +0 -10
- data/lib/scout/named_array.rb +0 -138
- data/lib/scout/open/lock/lockfile.rb +0 -587
- data/lib/scout/open/lock.rb +0 -68
- data/lib/scout/open/remote.rb +0 -135
- data/lib/scout/open/stream.rb +0 -491
- data/lib/scout/open/util.rb +0 -244
- data/lib/scout/open.rb +0 -170
- data/lib/scout/path/find.rb +0 -204
- data/lib/scout/path/tmpfile.rb +0 -8
- data/lib/scout/path/util.rb +0 -127
- data/lib/scout/path.rb +0 -51
- data/lib/scout/persist/open.rb +0 -17
- data/lib/scout/persist/path.rb +0 -15
- data/lib/scout/persist/serialize.rb +0 -157
- data/lib/scout/persist.rb +0 -104
- data/lib/scout/resource/open.rb +0 -8
- data/lib/scout/resource/path.rb +0 -80
- data/lib/scout/resource/produce/rake.rb +0 -69
- data/lib/scout/resource/produce.rb +0 -151
- data/lib/scout/resource/scout.rb +0 -3
- data/lib/scout/resource/software.rb +0 -178
- data/lib/scout/resource/util.rb +0 -59
- data/lib/scout/resource.rb +0 -41
- data/lib/scout/simple_opt/accessor.rb +0 -54
- data/lib/scout/simple_opt/doc.rb +0 -126
- data/lib/scout/simple_opt/get.rb +0 -57
- data/lib/scout/simple_opt/parse.rb +0 -67
- data/lib/scout/simple_opt/setup.rb +0 -26
- data/lib/scout/simple_opt.rb +0 -5
- data/lib/scout/tmpfile.rb +0 -129
- data/test/scout/indiferent_hash/test_case_insensitive.rb +0 -16
- data/test/scout/indiferent_hash/test_options.rb +0 -46
- data/test/scout/log/test_progress.rb +0 -108
- data/test/scout/misc/test_digest.rb +0 -30
- data/test/scout/misc/test_filesystem.rb +0 -30
- data/test/scout/misc/test_insist.rb +0 -13
- data/test/scout/misc/test_system.rb +0 -21
- data/test/scout/open/test_lock.rb +0 -52
- data/test/scout/open/test_remote.rb +0 -25
- data/test/scout/open/test_stream.rb +0 -676
- data/test/scout/open/test_util.rb +0 -73
- data/test/scout/path/test_find.rb +0 -119
- data/test/scout/path/test_util.rb +0 -22
- data/test/scout/persist/test_open.rb +0 -37
- data/test/scout/persist/test_path.rb +0 -37
- data/test/scout/persist/test_serialize.rb +0 -114
- data/test/scout/resource/test_path.rb +0 -46
- data/test/scout/resource/test_produce.rb +0 -92
- data/test/scout/resource/test_software.rb +0 -24
- data/test/scout/resource/test_util.rb +0 -36
- data/test/scout/simple_opt/test_doc.rb +0 -16
- data/test/scout/simple_opt/test_get.rb +0 -11
- data/test/scout/simple_opt/test_parse.rb +0 -10
- data/test/scout/simple_opt/test_setup.rb +0 -77
- data/test/scout/test_cmd.rb +0 -85
- data/test/scout/test_concurrent_stream.rb +0 -29
- data/test/scout/test_config.rb +0 -66
- data/test/scout/test_indiferent_hash.rb +0 -26
- data/test/scout/test_log.rb +0 -32
- data/test/scout/test_meta_extension.rb +0 -80
- data/test/scout/test_misc.rb +0 -6
- data/test/scout/test_named_array.rb +0 -43
- data/test/scout/test_open.rb +0 -146
- data/test/scout/test_path.rb +0 -54
- data/test/scout/test_persist.rb +0 -186
- data/test/scout/test_resource.rb +0 -26
- data/test/scout/test_tmpfile.rb +0 -53
- /data/test/scout/{log/test_color.rb → test_offsite.rb} +0 -0
@@ -54,10 +54,10 @@ if help
|
|
54
54
|
exit 0
|
55
55
|
end
|
56
56
|
|
57
|
+
job_inputs = task.get_SOPT
|
58
|
+
|
57
59
|
if load_inputs
|
58
|
-
job_inputs = workflow.tasks[task_name].load_inputs(load_inputs)
|
59
|
-
else
|
60
|
-
job_inputs = task.get_SOPT
|
60
|
+
job_inputs = job_inputs.merge(workflow.tasks[task_name].load_inputs(load_inputs))
|
61
61
|
end
|
62
62
|
|
63
63
|
if override_deps
|
data/test/scout/tsv/test_open.rb
CHANGED
@@ -137,7 +137,7 @@ row2 aa bb cc
|
|
137
137
|
dumper = TSV::Dumper.new :key_field => "Key", :fields => ["Field"], type: :single
|
138
138
|
dumper.init
|
139
139
|
assert_raise ScoutException do
|
140
|
-
Log.with_severity
|
140
|
+
Log.with_severity 7 do
|
141
141
|
i = 0
|
142
142
|
TSV.traverse lines, :into => dumper, cpus: 3 do |l|
|
143
143
|
raise ScoutException if i > 10
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
require 'scout/tsv'
|
5
|
+
|
6
|
+
class TestClass < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_sort_by
|
9
|
+
content =<<-EOF
|
10
|
+
#ID ValueA ValueB Comment
|
11
|
+
row1 a B c
|
12
|
+
row2 A b C
|
13
|
+
EOF
|
14
|
+
|
15
|
+
TmpFile.with_file(content) do |filename|
|
16
|
+
tsv = TSV.open(File.open(filename), :type => :list, :sep => /\s/)
|
17
|
+
assert_equal %w(row2 row1), tsv.sort_by("ValueA").collect{|k,v| k}
|
18
|
+
assert_equal %w(row1 row2), tsv.sort_by("ValueB").collect{|k,v| k}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
@@ -219,14 +219,10 @@ class TestTaskInput < Test::Unit::TestCase
|
|
219
219
|
original_digest = task.process_inputs(inputs).last
|
220
220
|
|
221
221
|
TmpFile.with_file do |save_directory|
|
222
|
-
iii inputs
|
223
222
|
task.save_inputs(save_directory, inputs)
|
224
223
|
Open.rm(file1)
|
225
224
|
new_inputs = task.load_inputs(save_directory)
|
226
|
-
iii new_inputs
|
227
225
|
new_digest = task.process_inputs(new_inputs).last
|
228
|
-
iii new_digest
|
229
|
-
iii original_digest
|
230
226
|
assert_equal original_digest, new_digest
|
231
227
|
end
|
232
228
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout-gear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 10.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: scout-essentials
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sys-proctable
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: RubyInline
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,65 +145,12 @@ files:
|
|
159
145
|
- lib/rbbt-scout.rb
|
160
146
|
- lib/scout-gear.rb
|
161
147
|
- lib/scout.rb
|
162
|
-
- lib/scout/cmd.rb
|
163
|
-
- lib/scout/concurrent_stream.rb
|
164
|
-
- lib/scout/config.rb
|
165
|
-
- lib/scout/exceptions.rb
|
166
|
-
- lib/scout/indiferent_hash.rb
|
167
|
-
- lib/scout/indiferent_hash/case_insensitive.rb
|
168
|
-
- lib/scout/indiferent_hash/options.rb
|
169
|
-
- lib/scout/log.rb
|
170
|
-
- lib/scout/log/color.rb
|
171
|
-
- lib/scout/log/color_class.rb
|
172
|
-
- lib/scout/log/fingerprint.rb
|
173
|
-
- lib/scout/log/progress.rb
|
174
|
-
- lib/scout/log/progress/report.rb
|
175
|
-
- lib/scout/log/progress/util.rb
|
176
|
-
- lib/scout/log/trap.rb
|
177
|
-
- lib/scout/meta_extension.rb
|
178
|
-
- lib/scout/misc.rb
|
179
|
-
- lib/scout/misc/digest.rb
|
180
|
-
- lib/scout/misc/filesystem.rb
|
181
|
-
- lib/scout/misc/format.rb
|
182
|
-
- lib/scout/misc/helper.rb
|
183
|
-
- lib/scout/misc/insist.rb
|
184
|
-
- lib/scout/misc/monitor.rb
|
185
|
-
- lib/scout/misc/system.rb
|
186
|
-
- lib/scout/named_array.rb
|
187
148
|
- lib/scout/offsite.rb
|
149
|
+
- lib/scout/offsite/exceptions.rb
|
188
150
|
- lib/scout/offsite/ssh.rb
|
189
151
|
- lib/scout/offsite/step.rb
|
190
152
|
- lib/scout/offsite/sync.rb
|
191
|
-
- lib/scout/open.rb
|
192
|
-
- lib/scout/open/lock.rb
|
193
|
-
- lib/scout/open/lock/lockfile.rb
|
194
|
-
- lib/scout/open/remote.rb
|
195
|
-
- lib/scout/open/stream.rb
|
196
|
-
- lib/scout/open/util.rb
|
197
|
-
- lib/scout/path.rb
|
198
|
-
- lib/scout/path/find.rb
|
199
|
-
- lib/scout/path/tmpfile.rb
|
200
|
-
- lib/scout/path/util.rb
|
201
|
-
- lib/scout/persist.rb
|
202
|
-
- lib/scout/persist/open.rb
|
203
|
-
- lib/scout/persist/path.rb
|
204
|
-
- lib/scout/persist/serialize.rb
|
205
|
-
- lib/scout/resource.rb
|
206
|
-
- lib/scout/resource/open.rb
|
207
|
-
- lib/scout/resource/path.rb
|
208
|
-
- lib/scout/resource/produce.rb
|
209
|
-
- lib/scout/resource/produce/rake.rb
|
210
|
-
- lib/scout/resource/scout.rb
|
211
|
-
- lib/scout/resource/software.rb
|
212
|
-
- lib/scout/resource/util.rb
|
213
153
|
- lib/scout/semaphore.rb
|
214
|
-
- lib/scout/simple_opt.rb
|
215
|
-
- lib/scout/simple_opt/accessor.rb
|
216
|
-
- lib/scout/simple_opt/doc.rb
|
217
|
-
- lib/scout/simple_opt/get.rb
|
218
|
-
- lib/scout/simple_opt/parse.rb
|
219
|
-
- lib/scout/simple_opt/setup.rb
|
220
|
-
- lib/scout/tmpfile.rb
|
221
154
|
- lib/scout/tsv.rb
|
222
155
|
- lib/scout/tsv/attach.rb
|
223
156
|
- lib/scout/tsv/change_id.rb
|
@@ -239,8 +172,10 @@ files:
|
|
239
172
|
- lib/scout/tsv/util/process.rb
|
240
173
|
- lib/scout/tsv/util/reorder.rb
|
241
174
|
- lib/scout/tsv/util/select.rb
|
175
|
+
- lib/scout/tsv/util/sort.rb
|
242
176
|
- lib/scout/tsv/util/unzip.rb
|
243
177
|
- lib/scout/work_queue.rb
|
178
|
+
- lib/scout/work_queue/exceptions.rb
|
244
179
|
- lib/scout/work_queue/socket.rb
|
245
180
|
- lib/scout/work_queue/worker.rb
|
246
181
|
- lib/scout/workflow.rb
|
@@ -283,49 +218,12 @@ files:
|
|
283
218
|
- share/software/install_helpers
|
284
219
|
- share/templates/command
|
285
220
|
- share/templates/workflow.rb
|
286
|
-
- test/scout/indiferent_hash/test_case_insensitive.rb
|
287
|
-
- test/scout/indiferent_hash/test_options.rb
|
288
|
-
- test/scout/log/test_color.rb
|
289
|
-
- test/scout/log/test_progress.rb
|
290
|
-
- test/scout/misc/test_digest.rb
|
291
|
-
- test/scout/misc/test_filesystem.rb
|
292
|
-
- test/scout/misc/test_insist.rb
|
293
|
-
- test/scout/misc/test_system.rb
|
294
221
|
- test/scout/offsite/test_ssh.rb
|
295
222
|
- test/scout/offsite/test_step.rb
|
296
223
|
- test/scout/offsite/test_sync.rb
|
297
224
|
- test/scout/offsite/test_task.rb
|
298
|
-
- test/scout/
|
299
|
-
- test/scout/open/test_remote.rb
|
300
|
-
- test/scout/open/test_stream.rb
|
301
|
-
- test/scout/open/test_util.rb
|
302
|
-
- test/scout/path/test_find.rb
|
303
|
-
- test/scout/path/test_util.rb
|
304
|
-
- test/scout/persist/test_open.rb
|
305
|
-
- test/scout/persist/test_path.rb
|
306
|
-
- test/scout/persist/test_serialize.rb
|
307
|
-
- test/scout/resource/test_path.rb
|
308
|
-
- test/scout/resource/test_produce.rb
|
309
|
-
- test/scout/resource/test_software.rb
|
310
|
-
- test/scout/resource/test_util.rb
|
311
|
-
- test/scout/simple_opt/test_doc.rb
|
312
|
-
- test/scout/simple_opt/test_get.rb
|
313
|
-
- test/scout/simple_opt/test_parse.rb
|
314
|
-
- test/scout/simple_opt/test_setup.rb
|
315
|
-
- test/scout/test_cmd.rb
|
316
|
-
- test/scout/test_concurrent_stream.rb
|
317
|
-
- test/scout/test_config.rb
|
318
|
-
- test/scout/test_indiferent_hash.rb
|
319
|
-
- test/scout/test_log.rb
|
320
|
-
- test/scout/test_meta_extension.rb
|
321
|
-
- test/scout/test_misc.rb
|
322
|
-
- test/scout/test_named_array.rb
|
323
|
-
- test/scout/test_open.rb
|
324
|
-
- test/scout/test_path.rb
|
325
|
-
- test/scout/test_persist.rb
|
326
|
-
- test/scout/test_resource.rb
|
225
|
+
- test/scout/test_offsite.rb
|
327
226
|
- test/scout/test_semaphore.rb
|
328
|
-
- test/scout/test_tmpfile.rb
|
329
227
|
- test/scout/test_tsv.rb
|
330
228
|
- test/scout/test_work_queue.rb
|
331
229
|
- test/scout/test_workflow.rb
|
@@ -347,6 +245,7 @@ files:
|
|
347
245
|
- test/scout/tsv/util/test_process.rb
|
348
246
|
- test/scout/tsv/util/test_reorder.rb
|
349
247
|
- test/scout/tsv/util/test_select.rb
|
248
|
+
- test/scout/tsv/util/test_sort.rb
|
350
249
|
- test/scout/tsv/util/test_unzip.rb
|
351
250
|
- test/scout/work_queue/test_socket.rb
|
352
251
|
- test/scout/work_queue/test_worker.rb
|
data/lib/scout/cmd.rb
DELETED
@@ -1,347 +0,0 @@
|
|
1
|
-
require_relative 'indiferent_hash'
|
2
|
-
require_relative 'concurrent_stream'
|
3
|
-
require_relative 'log'
|
4
|
-
require_relative 'open/stream'
|
5
|
-
require 'stringio'
|
6
|
-
require 'open3'
|
7
|
-
|
8
|
-
module CMD
|
9
|
-
|
10
|
-
TOOLS = IndiferentHash.setup({})
|
11
|
-
def self.tool(tool, claim = nil, test = nil, cmd = nil, &block)
|
12
|
-
TOOLS[tool] = [claim, test, block, cmd]
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.conda(tool, env = nil, channel = 'bioconda')
|
16
|
-
if env
|
17
|
-
CMD.cmd("bash -l -c '(conda activate #{env} && conda install #{tool} -c #{channel})'")
|
18
|
-
else
|
19
|
-
CMD.cmd("bash -l -c 'conda install #{tool} -c #{channel}'")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def self.get_tool(tool)
|
25
|
-
return tool.to_s unless TOOLS[tool]
|
26
|
-
|
27
|
-
@@init_cmd_tool ||= IndiferentHash.setup({})
|
28
|
-
|
29
|
-
claim, test, block, cmd = TOOLS[tool]
|
30
|
-
cmd = tool.to_s if cmd.nil?
|
31
|
-
|
32
|
-
if !@@init_cmd_tool[tool]
|
33
|
-
|
34
|
-
begin
|
35
|
-
if test
|
36
|
-
CMD.cmd(test + " ")
|
37
|
-
else
|
38
|
-
CMD.cmd("#{cmd} --help")
|
39
|
-
end
|
40
|
-
rescue
|
41
|
-
if claim
|
42
|
-
claim.produce
|
43
|
-
else
|
44
|
-
block.call
|
45
|
-
end
|
46
|
-
end
|
47
|
-
version_txt = ""
|
48
|
-
version = nil
|
49
|
-
["--version", "-version", "--help", ""].each do |f|
|
50
|
-
begin
|
51
|
-
version_txt += CMD.cmd("#{cmd} #{f} 2>&1", :nofail => true).read
|
52
|
-
version = CMD.scan_version_text(version_txt, tool)
|
53
|
-
break if version
|
54
|
-
rescue
|
55
|
-
Log.exception $!
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
@@init_cmd_tool[tool] = version || true
|
60
|
-
|
61
|
-
return cmd if cmd
|
62
|
-
end
|
63
|
-
|
64
|
-
cmd
|
65
|
-
end
|
66
|
-
def self.scan_version_text(text, cmd = nil)
|
67
|
-
cmd = "NOCMDGIVE" if cmd.nil? || cmd.empty?
|
68
|
-
text = Misc.fixutf8 text
|
69
|
-
text.split("\n").each do |line|
|
70
|
-
next unless line =~ /\W#{cmd}\W/i
|
71
|
-
m = line.match(/(v(?:\d+\.)*\d+(?:-[a-z_]+)?)/i)
|
72
|
-
return m[1] if m
|
73
|
-
m = line.match(/((?:\d+\.)*\d+(?:-[a-z_]+)?v)/i)
|
74
|
-
return m[1] if m
|
75
|
-
next unless line =~ /\Wversion\W/i
|
76
|
-
m = line.match(/((?:\d+\.)*\d+(?:-[a-z_]+)?)/i)
|
77
|
-
return m[1] if m
|
78
|
-
end
|
79
|
-
m = text.match(/(?:version.*?|#{cmd}.*?|#{cmd.to_s.split(/[-_.]/).first}.*?|v)((?:\d+\.)*\d+(?:-[a-z_]+)?)/i)
|
80
|
-
return m[1] if m
|
81
|
-
m = text.match(/(?:#{cmd}.*(v.*|.*v))/i)
|
82
|
-
return m[1] if m
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
def self.versions
|
86
|
-
return {} unless defined? @@init_cmd_tool
|
87
|
-
@@init_cmd_tool.select{|k,v| v =~ /\d+\./ }
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.bash(cmd)
|
91
|
-
cmd = %Q(bash <<EOF\n#{cmd}\nEOF\n)
|
92
|
-
CMD.cmd(cmd, :autojoin => true)
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.process_cmd_options(options = {})
|
96
|
-
add_dashes = IndiferentHash.process_options options, :add_option_dashes
|
97
|
-
|
98
|
-
string = ""
|
99
|
-
options.each do |option, value|
|
100
|
-
raise "Invalid option key: #{option.inspect}" if option.to_s !~ /^[a-z_0-9\-=.]+$/i
|
101
|
-
#raise "Invalid option value: #{value.inspect}" if value.to_s.include? "'"
|
102
|
-
value = value.gsub("'","\\'") if value.to_s.include? "'"
|
103
|
-
|
104
|
-
option = "--" << option.to_s if add_dashes and option.to_s[0] != '-'
|
105
|
-
|
106
|
-
case
|
107
|
-
when value.nil? || FalseClass === value
|
108
|
-
next
|
109
|
-
when TrueClass === value
|
110
|
-
string << "#{option} "
|
111
|
-
else
|
112
|
-
if option.to_s.chars.to_a.last == "="
|
113
|
-
string << "#{option}'#{value}' "
|
114
|
-
else
|
115
|
-
string << "#{option} '#{value}' "
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
string.strip
|
121
|
-
end
|
122
|
-
|
123
|
-
def self.cmd(tool, cmd = nil, options = {}, &block)
|
124
|
-
options, cmd = cmd, nil if Hash === cmd
|
125
|
-
|
126
|
-
options = IndiferentHash.add_defaults options, :stderr => Log::DEBUG
|
127
|
-
in_content = options.delete(:in)
|
128
|
-
stderr = options.delete(:stderr)
|
129
|
-
post = options.delete(:post)
|
130
|
-
pipe = options.delete(:pipe)
|
131
|
-
log = options.delete(:log)
|
132
|
-
no_fail = options.delete(:no_fail)
|
133
|
-
no_fail = options.delete(:nofail) if no_fail.nil?
|
134
|
-
no_wait = options.delete(:no_wait)
|
135
|
-
xvfb = options.delete(:xvfb)
|
136
|
-
bar = options.delete(:progress_bar)
|
137
|
-
save_stderr = options.delete(:save_stderr)
|
138
|
-
autojoin = options.delete(:autojoin)
|
139
|
-
autojoin = no_wait if autojoin.nil?
|
140
|
-
|
141
|
-
dont_close_in = options.delete(:dont_close_in)
|
142
|
-
|
143
|
-
log = true if log.nil?
|
144
|
-
|
145
|
-
if cmd.nil? && ! Symbol === tool
|
146
|
-
cmd = tool
|
147
|
-
else
|
148
|
-
tool = get_tool(tool)
|
149
|
-
if cmd.nil?
|
150
|
-
cmd = tool
|
151
|
-
else
|
152
|
-
cmd = tool + ' ' + cmd
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
case xvfb
|
158
|
-
when TrueClass
|
159
|
-
cmd = "xvfb-run --server-args='-screen 0 1024x768x24' --auto-servernum #{cmd}"
|
160
|
-
when String
|
161
|
-
cmd = "xvfb-run --server-args='#{xvfb}' --auto-servernum --server-num=1 #{cmd}"
|
162
|
-
when String
|
163
|
-
end
|
164
|
-
|
165
|
-
if stderr == true
|
166
|
-
stderr = Log::HIGH
|
167
|
-
end
|
168
|
-
|
169
|
-
cmd_options = process_cmd_options options
|
170
|
-
if cmd =~ /'\{opt\}'/
|
171
|
-
cmd.sub!('\'{opt}\'', cmd_options)
|
172
|
-
else
|
173
|
-
cmd << " " << cmd_options
|
174
|
-
end
|
175
|
-
|
176
|
-
in_content = StringIO.new in_content if String === in_content
|
177
|
-
|
178
|
-
sin, sout, serr, wait_thr = begin
|
179
|
-
Open3.popen3(ENV, cmd)
|
180
|
-
rescue
|
181
|
-
Log.warn $!.message
|
182
|
-
raise ProcessFailed, nil, cmd unless no_fail
|
183
|
-
return
|
184
|
-
end
|
185
|
-
pid = wait_thr.pid
|
186
|
-
|
187
|
-
Log.debug{"CMD: [#{pid}] #{cmd}".strip if log}
|
188
|
-
|
189
|
-
if in_content.respond_to?(:read)
|
190
|
-
in_thread = Thread.new(Thread.current) do |parent|
|
191
|
-
begin
|
192
|
-
Thread.current.report_on_exception = false if no_fail
|
193
|
-
Thread.current["name"] = "CMD in"
|
194
|
-
while c = in_content.read(Open::BLOCK_SIZE)
|
195
|
-
sin << c
|
196
|
-
end
|
197
|
-
sin.close unless sin.closed?
|
198
|
-
|
199
|
-
unless dont_close_in
|
200
|
-
in_content.close unless in_content.closed?
|
201
|
-
in_content.join if in_content.respond_to? :join
|
202
|
-
end
|
203
|
-
rescue
|
204
|
-
Log.error "Error in CMD [#{pid}] #{cmd}: #{$!.message}" unless no_fail
|
205
|
-
raise $!
|
206
|
-
end
|
207
|
-
end
|
208
|
-
Thread.pass until in_thread["name"]
|
209
|
-
else
|
210
|
-
in_thread = nil
|
211
|
-
sin.close
|
212
|
-
end
|
213
|
-
|
214
|
-
pids = [pid]
|
215
|
-
|
216
|
-
if pipe
|
217
|
-
|
218
|
-
ConcurrentStream.setup sout, :pids => pids, :autojoin => autojoin, :no_fail => no_fail
|
219
|
-
|
220
|
-
sout.callback = post if post
|
221
|
-
|
222
|
-
if (Integer === stderr and log) || bar
|
223
|
-
err_thread = Thread.new do
|
224
|
-
Thread.current["name"] = "Error log: [#{pid}] #{ cmd }"
|
225
|
-
begin
|
226
|
-
while line = serr.gets
|
227
|
-
bar.process(line) if bar
|
228
|
-
sout.log = line
|
229
|
-
sout.std_err << line if save_stderr
|
230
|
-
Log.log "STDERR [#{pid}]: " + line, stderr if log
|
231
|
-
end
|
232
|
-
serr.close
|
233
|
-
rescue
|
234
|
-
Log.exception $!
|
235
|
-
raise $!
|
236
|
-
end
|
237
|
-
end
|
238
|
-
else
|
239
|
-
err_thread = Open.consume_stream(serr, true)
|
240
|
-
end
|
241
|
-
|
242
|
-
sout.threads = [in_thread, err_thread, wait_thr].compact
|
243
|
-
|
244
|
-
sout
|
245
|
-
else
|
246
|
-
|
247
|
-
if bar
|
248
|
-
err = ""
|
249
|
-
err_thread = Thread.new do
|
250
|
-
while not serr.eof?
|
251
|
-
line = serr.gets
|
252
|
-
bar.process(line)
|
253
|
-
err << line if Integer === stderr and log
|
254
|
-
end
|
255
|
-
serr.close
|
256
|
-
end
|
257
|
-
elsif log and Integer === stderr
|
258
|
-
err = ""
|
259
|
-
err_thread = Thread.new do
|
260
|
-
while not serr.eof?
|
261
|
-
err << serr.gets
|
262
|
-
end
|
263
|
-
serr.close
|
264
|
-
end
|
265
|
-
else
|
266
|
-
Open.consume_stream(serr, true)
|
267
|
-
err_thread = nil
|
268
|
-
err = ""
|
269
|
-
end
|
270
|
-
|
271
|
-
ConcurrentStream.setup sout, :pids => pids, :threads => [in_thread, err_thread].compact, :autojoin => autojoin, :no_fail => no_fail
|
272
|
-
|
273
|
-
begin
|
274
|
-
out = StringIO.new sout.read
|
275
|
-
sout.close unless sout.closed?
|
276
|
-
|
277
|
-
status = wait_thr.value
|
278
|
-
if status && ! status.success? && ! no_fail
|
279
|
-
if !err.empty?
|
280
|
-
raise ProcessFailed.new pid, "#{cmd} failed with error status #{status.exitstatus}.\n#{err}"
|
281
|
-
else
|
282
|
-
raise ProcessFailed.new pid, "#{cmd} failed with error status #{status.exitstatus}"
|
283
|
-
end
|
284
|
-
else
|
285
|
-
Log.log err, stderr if Integer === stderr and log
|
286
|
-
end
|
287
|
-
out
|
288
|
-
ensure
|
289
|
-
post.call if post
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
def self.cmd_pid(*args)
|
295
|
-
all_args = *args
|
296
|
-
|
297
|
-
bar = all_args.last[:progress_bar] if Hash === all_args.last
|
298
|
-
|
299
|
-
all_args << {} unless Hash === all_args.last
|
300
|
-
|
301
|
-
level = all_args.last[:log] || 0
|
302
|
-
level = 0 if TrueClass === level
|
303
|
-
level = 10 if FalseClass === level
|
304
|
-
level = level.to_i
|
305
|
-
|
306
|
-
all_args.last[:log] = true
|
307
|
-
all_args.last[:pipe] = true
|
308
|
-
|
309
|
-
io = cmd(*all_args)
|
310
|
-
pid = io.pids.first
|
311
|
-
|
312
|
-
line = "" if bar
|
313
|
-
starting = true
|
314
|
-
while c = io.getc
|
315
|
-
if starting
|
316
|
-
if pid
|
317
|
-
Log.logn "STDOUT [#{pid}]: ", level
|
318
|
-
else
|
319
|
-
Log.logn "STDOUT: ", level
|
320
|
-
end
|
321
|
-
starting = false
|
322
|
-
end
|
323
|
-
STDERR << c if Log.severity <= level
|
324
|
-
line << c if bar
|
325
|
-
if c == "\n"
|
326
|
-
bar.process(line) if bar
|
327
|
-
starting = true
|
328
|
-
line = "" if bar
|
329
|
-
end
|
330
|
-
end
|
331
|
-
begin
|
332
|
-
io.join
|
333
|
-
bar.remove if bar
|
334
|
-
rescue
|
335
|
-
bar.remove(true) if bar
|
336
|
-
raise $!
|
337
|
-
end
|
338
|
-
|
339
|
-
nil
|
340
|
-
end
|
341
|
-
|
342
|
-
def self.cmd_log(*args)
|
343
|
-
cmd_pid(*args)
|
344
|
-
nil
|
345
|
-
end
|
346
|
-
|
347
|
-
end
|