rbbt-util 5.26.77 → 5.26.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -49,32 +49,57 @@ class Step
49
49
  end
50
50
  end
51
51
 
52
+ def self.job_files_for_archive(files)
53
+ job_files = Set.new
54
+
55
+ jobs = files.collect do |file|
56
+ if Step === file
57
+ file
58
+ else
59
+ file = file.sub(/\.info$/,'')
60
+ Step.new(File.expand_path(file))
61
+ end
62
+ end.uniq
63
+
64
+ jobs.each do |step|
65
+ next unless File.exists?(step.path)
66
+ job_files << step.path
67
+ job_files << step.info_file if File.exists?(step.info_file)
68
+ job_files << step.files_dir if Dir.glob(step.files_dir + '/*').any?
69
+ rec_dependencies = Set.new
70
+ deps = [step.path]
71
+ seen = Set.new
72
+ while deps.any?
73
+ path = deps.shift
74
+ dep = Step.new path
75
+ seen << dep.path
76
+ dep.info[:dependencies].each do |task, name, path|
77
+ dep = Step.new path
78
+ next if seen.include? dep.path
79
+ deps << dep.path
80
+ rec_dependencies << dep.path
81
+ end if dep.info[:dependencies]
82
+ end
83
+
84
+ rec_dependencies.each do |path|
85
+ next unless File.exists?(path)
86
+ job_files << dep.files_dir if Dir.glob(dep.files_dir + '/*').any?
87
+ job_files << dep.info_file if File.exists?(dep.info_file)
88
+ job_files << path
89
+ end
90
+ end
91
+
92
+ job_files.to_a
93
+ end
94
+
52
95
  def self.archive(files, target = nil)
53
96
  target = self.path + '.tar.gz' if target.nil?
54
- target = File.expand_path(target)
97
+ target = File.expand_path(target) if String === target
55
98
 
56
- jobs = files.collect{|file| file = file.sub(/\.info$/,''); Step.new(File.expand_path(file))}.uniq
99
+ job_files = job_files_for_archive files
57
100
  TmpFile.with_file do |tmpdir|
58
- jobs.each do |step|
59
- Step.link_job step.path, tmpdir
60
- rec_dependencies = Set.new
61
- deps = [step.path]
62
- seen = Set.new
63
- while deps.any?
64
- path = deps.shift
65
- dep = Step.new path
66
- seen << dep.path
67
- dep.info[:dependencies].each do |task, name, path|
68
- dep = Step.new path
69
- next if seen.include? dep.path
70
- deps << dep.path
71
- rec_dependencies << dep.path
72
- end if dep.info[:dependencies]
73
- end
74
-
75
- rec_dependencies.each do |path|
76
- Step.link_job path, tmpdir
77
- end
101
+ job_files.each do |file|
102
+ Step.link_job file, tmpdir
78
103
  end
79
104
 
80
105
  Misc.in_dir(tmpdir) do
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+ require 'rbbt/workflow/remote/ssh/get'
6
+
7
+ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
8
+
9
+ options = SOPT.setup <<EOF
10
+
11
+ RSync a directory, commonly ~/.rbbt/
12
+
13
+ $ rbbt migrate [options] <path> <search_path>
14
+
15
+ You can specify extra rsync options after --
16
+
17
+ -h--help Print this help
18
+ -t--test Do a verbose dry run
19
+ -p--print Print command
20
+ -d--delete Delete source file when moved
21
+ -s--source* Source server
22
+ -t--target* Target server
23
+ EOF
24
+ if options[:help]
25
+ if defined? rbbt_usage
26
+ rbbt_usage
27
+ else
28
+ puts SOPT.doc
29
+ end
30
+ exit 0
31
+ end
32
+
33
+ #excludes = %w(.save .crap .source tmp filecache open-remote workflows apps software jobs PCAWG)
34
+ excludes = %w(.save .crap .source tmp filecache open-remote)
35
+ excludes += (options[:exclude] || "").split(/,\s*/)
36
+ excludes_str = excludes.collect{|s| "--exclude '#{s}'" } * " "
37
+
38
+ test_str = options[:test] ? '-nv' : ''
39
+
40
+ path, search_path, _sep, *other = ARGV
41
+
42
+ resource = Rbbt
43
+
44
+ path, real_paths = if options[:source]
45
+ paths = SSHClient.run(options[:source], <<-EOF).split("\n")
46
+ require 'rbbt-util'
47
+ path = "#{path}"
48
+ if File.exists?(path)
49
+ path = #{resource.to_s}.identify(path)
50
+ else
51
+ path = Path.setup(path)
52
+ end
53
+ puts path.glob_all * "\n"
54
+ EOF
55
+ [path, paths.collect{|p| [options[:source], p] * ":"}]
56
+ else
57
+ if File.exists?(path)
58
+ path = resource.identify(path)
59
+ else
60
+ path = Path.setup(path)
61
+ end
62
+ [path, path.glob_all]
63
+ end
64
+
65
+ target = if options[:target]
66
+ target = SSHClient.run(options[:target], <<-EOF).split("\n").first
67
+ require 'rbbt-util'
68
+ path = "#{path}"
69
+ resource = #{resource.to_s}
70
+ search_path = "#{search_path}"
71
+ puts resource[path].find(search_path)
72
+ EOF
73
+ else
74
+ resource[path].find(search_path)
75
+ end
76
+
77
+ real_paths.each do |source|
78
+
79
+
80
+ if File.directory?(source)
81
+ source += "/" unless source[-1] == "/"
82
+ target += "/" unless target[-1] == "/"
83
+ end
84
+
85
+ next if source == target
86
+
87
+ if options[:target]
88
+ CMD.cmd("ssh #{options[:target]} mkdir -p '#{File.dirname(target)}'")
89
+ else
90
+ Open.mkdir File.dirname(target)
91
+ end
92
+
93
+ target = [options[:target], target] * ":" if options[:target]
94
+
95
+ cmd = "rsync -atAX #{test_str} #{excludes_str} #{source} #{target} #{other * " "}"
96
+
97
+ cmd << " && rm -Rf #{source}" if options[:delete]
98
+
99
+ if options[:print]
100
+ puts cmd
101
+ exit 0
102
+ else
103
+ CMD.cmd_log(cmd)
104
+ end
105
+ end
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+ require 'rbbt/workflow'
6
+ require 'rbbt/workflow/remote/ssh/get'
7
+
8
+ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
9
+
10
+ options = SOPT.setup <<EOF
11
+
12
+ RSync a directory, commonly ~/.rbbt/
13
+
14
+ $ rbbt migrate [options] <job_path> <search_path>
15
+
16
+ You can specify extra rsync options after --
17
+
18
+ -h--help Print this help
19
+ -t--test Do a verbose dry run
20
+ -p--print Print command
21
+ -d--delete Delete source file when moved
22
+ -s--source* Source server
23
+ -t--target* Target server
24
+ -r--recursive Recursively move all deps
25
+ EOF
26
+ if options[:help]
27
+ if defined? rbbt_usage
28
+ rbbt_usage
29
+ else
30
+ puts SOPT.doc
31
+ end
32
+ exit 0
33
+ end
34
+
35
+ excludes = %w(.save .crap .source tmp filecache open-remote)
36
+ excludes += (options[:exclude] || "").split(/,\s*/)
37
+ excludes_str = excludes.collect{|s| "--exclude '#{s}'" } * " "
38
+
39
+ test_str = options[:test] ? '-nv' : ''
40
+
41
+ path, search_path, _sep, *other = ARGV
42
+
43
+ resource = Rbbt
44
+
45
+ paths = if options[:source]
46
+ SSHClient.run(options[:source], <<-EOF).split("\n")
47
+ require 'rbbt-util'
48
+ require 'rbbt/workflow'
49
+
50
+ path = "#{path}"
51
+ if File.exists?(path)
52
+ path = #{resource.to_s}.identify(path)
53
+ else
54
+ path = Path.setup(path)
55
+ end
56
+ files = path.glob_all
57
+ if #{options[:recursive].to_s == 'true'}
58
+ files = Step.job_files_for_archive(files)
59
+ end
60
+ puts files * "\n"
61
+ EOF
62
+ else
63
+ if File.exists?(path)
64
+ path = resource.identify(path)
65
+ else
66
+ path = Path.setup(path)
67
+ end
68
+ files = path.glob_all
69
+ if options[:recursive]
70
+ files = Step.job_files_for_archive(files)
71
+ end
72
+ files
73
+ end
74
+
75
+ target = if options[:target]
76
+ target = SSHClient.run(options[:target], <<-EOF).split("\n").first
77
+ require 'rbbt-util'
78
+ path = "var/jobs"
79
+ resource = #{resource.to_s}
80
+ search_path = "#{search_path}"
81
+ puts resource[path].find(search_path)
82
+ EOF
83
+ else
84
+ resource['var/jobs'].find(search_path)
85
+ end
86
+
87
+ subpath_files = {}
88
+ paths.each do |source|
89
+ parts = source.split("/")
90
+ subpath = parts[0..-4] * "/"
91
+ source = parts[-3..-1] * "/"
92
+ subpath_files[subpath] ||= []
93
+ subpath_files[subpath] << source
94
+ end
95
+
96
+ subpath_files.each do |subpath, files|
97
+ if options[:target]
98
+ CMD.cmd("ssh #{options[:target]} mkdir -p '#{File.dirname(target)}'")
99
+ else
100
+ Open.mkdir File.dirname(target)
101
+ end
102
+
103
+ if options[:source]
104
+ source = [options[:source], subpath] * ":"
105
+ else
106
+ source = subpath
107
+ end
108
+ target = [options[:target], target] * ":" if options[:target]
109
+
110
+ files_and_dirs = Set.new(files )
111
+ files.each do |file|
112
+ parts = file.split("/")[0..-2]
113
+ while parts.any?
114
+ files_and_dirs << parts * "/"
115
+ parts.pop
116
+ end
117
+ end
118
+
119
+ TmpFile.with_file(files_and_dirs.to_a * "\n") do |tmp_include_file|
120
+ includes_str = "--include-from='#{tmp_include_file}'"
121
+ cmd = "rsync -atAXmPL --progress #{test_str} --include-from='#{tmp_include_file}' --exclude='*' #{source}/ #{target}/ #{other * " "}"
122
+
123
+ cmd << " && rm -Rf #{source}" if options[:delete]
124
+
125
+ if options[:print]
126
+ ppp Open.read(tmp_include_file)
127
+ puts cmd
128
+ else
129
+ CMD.cmd_log(cmd)
130
+ end
131
+ end
132
+ end
@@ -6,7 +6,7 @@ require 'rbbt-util'
6
6
  require 'fileutils'
7
7
  require 'rbbt/util/simpleopt'
8
8
  require 'rbbt/workflow/step'
9
- require 'rbbt/workflow/provenance'
9
+ require 'rbbt/workflow/util/provenance'
10
10
  require 'rbbt/util/misc'
11
11
 
12
12
  require 'rbbt-util'
@@ -230,6 +230,10 @@ Workflow.workdir = Path.setup(File.expand_path(options.delete(:workdir_all))) if
230
230
 
231
231
  workflow = Workflow.require_workflow workflow
232
232
 
233
+ if clean_task
234
+ ENV["RBBT_UPDATE"] = 'true'
235
+ end
236
+
233
237
  if options[:update_all_jobs]
234
238
  ENV["RBBT_UPDATE_ALL_JOBS"] = 'true'
235
239
  end
@@ -306,6 +310,7 @@ end
306
310
  #- get job
307
311
 
308
312
  job = workflow.job(task.name, name, job_options)
313
+ $job = job
309
314
 
310
315
  # clean job
311
316
  if clean
@@ -351,7 +356,7 @@ begin
351
356
 
352
357
  result_type = job.result_type
353
358
 
354
- res = JSON.parse(res.read) if (defined?(WorkflowRESTClient) and WorkflowRESTClient::RemoteStep === job) && %w(array float integer boolean).include?(result_type.to_s)
359
+ res = JSON.parse(res.read) if (defined?(WorkflowRemoteClient) and WorkflowRemoteClient::RemoteStep === job) && %w(array float integer boolean).include?(result_type.to_s)
355
360
 
356
361
  case
357
362
  when res.respond_to?(:gets)
@@ -377,7 +382,6 @@ begin
377
382
  end
378
383
 
379
384
  if options.delete(:provenance)
380
- require 'rbbt/workflow/provenance'
381
385
  if options.delete(:printpath)
382
386
  puts job.path
383
387
  else
@@ -387,7 +391,6 @@ begin
387
391
  end
388
392
 
389
393
  if tasks = options.delete(:prepare)
390
- require 'rbbt/workflow/prepare'
391
394
  tasks = tasks.split(",")
392
395
  prepare_cpus = (options[:prepare_cpus] || 1)
393
396
  puts Step.prepare_dependencies(job, tasks, prepare_cpus)
@@ -491,7 +494,7 @@ if job_file = options.delete(:job_file)
491
494
  end
492
495
 
493
496
  case res
494
- when (defined?(WorkflowRESTClient) and WorkflowRESTClient::RemoteStep)
497
+ when (defined?(WorkflowRemoteClient) and WorkflowRemoteClient::RemoteStep)
495
498
  res = job.result
496
499
  if res.respond_to? :gets
497
500
  begin
@@ -83,4 +83,9 @@ class TestTSV < Test::Unit::TestCase
83
83
  end
84
84
  end
85
85
 
86
+ def test_identify
87
+ assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
88
+ assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/share/databases/DATABASE/FILE'))
89
+ end
90
+
86
91
  end
@@ -159,7 +159,7 @@ for this dependency
159
159
 
160
160
  end
161
161
 
162
- TestWF.workdir = Rbbt.tmp.test.workflow
162
+ TestWF.workdir = Rbbt.tmp.test.jobs.TestWF
163
163
 
164
164
  class TestWorkflow < Test::Unit::TestCase
165
165
 
@@ -381,7 +381,8 @@ class TestWorkflow < Test::Unit::TestCase
381
381
  job = TestWF.job(:t3)
382
382
  job.step(:t1).clean
383
383
  Misc.with_env "RBBT_UPDATE_ALL_JOBS", "true" do
384
- assert job.checks.select{|d| d.task_name.to_s == "t1" }.any?
384
+ job = TestWF.job(:t3)
385
+ assert job.checks.select{|d| d.task_name.to_s == "t1" }.any?
385
386
  end
386
387
  end
387
388
 
@@ -415,4 +416,19 @@ class TestWorkflow < Test::Unit::TestCase
415
416
 
416
417
  end
417
418
 
419
+ def test_archive
420
+ job = TmpFile.with_file("Hi") do |file|
421
+ job = TestWF.job(:reverse_file, nil, :file => file)
422
+ job.run
423
+ job
424
+ end
425
+ TmpFile.with_file nil, true, :extension => 'tar.gz' do |targz|
426
+ Step.archive([job], targz)
427
+ TmpFile.with_file do |dir|
428
+ dir = Path.setup(dir)
429
+ Misc.untar targz, dir
430
+ assert dir.glob("**/*").collect{|f| File.basename(f)}.include? job.name
431
+ end
432
+ end
433
+ end
418
434
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.26.77
4
+ version: 5.26.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -319,19 +319,27 @@ files:
319
319
  - lib/rbbt/workflow.rb
320
320
  - lib/rbbt/workflow/accessor.rb
321
321
  - lib/rbbt/workflow/annotate.rb
322
- - lib/rbbt/workflow/archive.rb
323
322
  - lib/rbbt/workflow/definition.rb
324
323
  - lib/rbbt/workflow/doc.rb
325
324
  - lib/rbbt/workflow/examples.rb
326
- - lib/rbbt/workflow/prepare.rb
327
- - lib/rbbt/workflow/provenance.rb
325
+ - lib/rbbt/workflow/integration/nextflow.rb
326
+ - lib/rbbt/workflow/remote/client.rb
327
+ - lib/rbbt/workflow/remote/remote_step.rb
328
+ - lib/rbbt/workflow/remote/rest/adaptor.rb
329
+ - lib/rbbt/workflow/remote/rest/get.rb
330
+ - lib/rbbt/workflow/remote/ssh/adaptor.rb
331
+ - lib/rbbt/workflow/remote/ssh/get.rb
328
332
  - lib/rbbt/workflow/schedule.rb
329
333
  - lib/rbbt/workflow/soap.rb
330
334
  - lib/rbbt/workflow/step.rb
335
+ - lib/rbbt/workflow/step/accessor.rb
331
336
  - lib/rbbt/workflow/step/dependencies.rb
337
+ - lib/rbbt/workflow/step/prepare.rb
332
338
  - lib/rbbt/workflow/step/run.rb
333
339
  - lib/rbbt/workflow/task.rb
334
340
  - lib/rbbt/workflow/usage.rb
341
+ - lib/rbbt/workflow/util/archive.rb
342
+ - lib/rbbt/workflow/util/provenance.rb
335
343
  - share/Rlib/plot.R
336
344
  - share/Rlib/svg.R
337
345
  - share/Rlib/util.R
@@ -357,6 +365,8 @@ files:
357
365
  - share/rbbt_commands/file_server/list
358
366
  - share/rbbt_commands/file_server/remove
359
367
  - share/rbbt_commands/log
368
+ - share/rbbt_commands/migrate
369
+ - share/rbbt_commands/migrate_job
360
370
  - share/rbbt_commands/resource/exists
361
371
  - share/rbbt_commands/resource/find
362
372
  - share/rbbt_commands/resource/get