rbbt-util 5.44.1 → 6.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rbbt +67 -90
  3. data/etc/app.d/base.rb +2 -2
  4. data/etc/app.d/semaphores.rb +3 -3
  5. data/lib/rbbt/annotations/annotated_array.rb +207 -207
  6. data/lib/rbbt/annotations/refactor.rb +27 -0
  7. data/lib/rbbt/annotations/util.rb +282 -282
  8. data/lib/rbbt/annotations.rb +343 -320
  9. data/lib/rbbt/association/database.rb +200 -225
  10. data/lib/rbbt/association/index.rb +294 -291
  11. data/lib/rbbt/association/item.rb +227 -227
  12. data/lib/rbbt/association/open.rb +35 -34
  13. data/lib/rbbt/association/util.rb +0 -169
  14. data/lib/rbbt/association.rb +2 -4
  15. data/lib/rbbt/entity/identifiers.rb +119 -118
  16. data/lib/rbbt/entity/refactor.rb +12 -0
  17. data/lib/rbbt/entity.rb +319 -315
  18. data/lib/rbbt/hpc/batch.rb +72 -53
  19. data/lib/rbbt/hpc/lsf.rb +2 -2
  20. data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
  21. data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
  22. data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
  23. data/lib/rbbt/hpc/orchestrate.rb +19 -13
  24. data/lib/rbbt/hpc/slurm.rb +18 -18
  25. data/lib/rbbt/knowledge_base/entity.rb +13 -5
  26. data/lib/rbbt/knowledge_base/query.rb +2 -2
  27. data/lib/rbbt/knowledge_base/registry.rb +32 -31
  28. data/lib/rbbt/knowledge_base/traverse.rb +1 -1
  29. data/lib/rbbt/knowledge_base.rb +1 -1
  30. data/lib/rbbt/monitor.rb +36 -25
  31. data/lib/rbbt/persist/refactor.rb +166 -0
  32. data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
  33. data/lib/rbbt/persist/tsv.rb +187 -185
  34. data/lib/rbbt/persist.rb +556 -551
  35. data/lib/rbbt/refactor.rb +20 -0
  36. data/lib/rbbt/resource/path/refactor.rb +178 -0
  37. data/lib/rbbt/resource/path.rb +317 -497
  38. data/lib/rbbt/resource/util.rb +0 -48
  39. data/lib/rbbt/resource.rb +3 -390
  40. data/lib/rbbt/tsv/accessor.rb +2 -838
  41. data/lib/rbbt/tsv/attach.rb +303 -299
  42. data/lib/rbbt/tsv/change_id.rb +244 -245
  43. data/lib/rbbt/tsv/csv.rb +87 -85
  44. data/lib/rbbt/tsv/dumper.rb +2 -100
  45. data/lib/rbbt/tsv/excel.rb +26 -24
  46. data/lib/rbbt/tsv/field_index.rb +4 -1
  47. data/lib/rbbt/tsv/filter.rb +3 -2
  48. data/lib/rbbt/tsv/index.rb +2 -284
  49. data/lib/rbbt/tsv/manipulate.rb +750 -747
  50. data/lib/rbbt/tsv/marshal.rb +3 -3
  51. data/lib/rbbt/tsv/matrix.rb +2 -2
  52. data/lib/rbbt/tsv/parallel/through.rb +2 -1
  53. data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
  54. data/lib/rbbt/tsv/parser.rb +678 -678
  55. data/lib/rbbt/tsv/refactor.rb +195 -0
  56. data/lib/rbbt/tsv/stream.rb +253 -251
  57. data/lib/rbbt/tsv/util.rb +420 -420
  58. data/lib/rbbt/tsv.rb +210 -208
  59. data/lib/rbbt/util/R/eval.rb +4 -4
  60. data/lib/rbbt/util/R/plot.rb +62 -166
  61. data/lib/rbbt/util/R.rb +21 -18
  62. data/lib/rbbt/util/cmd.rb +2 -318
  63. data/lib/rbbt/util/color.rb +269 -269
  64. data/lib/rbbt/util/colorize.rb +89 -89
  65. data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
  66. data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
  67. data/lib/rbbt/util/concurrency/processes.rb +389 -386
  68. data/lib/rbbt/util/config.rb +169 -167
  69. data/lib/rbbt/util/iruby.rb +20 -0
  70. data/lib/rbbt/util/log/progress/report.rb +241 -241
  71. data/lib/rbbt/util/log/progress/util.rb +99 -99
  72. data/lib/rbbt/util/log/progress.rb +102 -102
  73. data/lib/rbbt/util/log/refactor.rb +49 -0
  74. data/lib/rbbt/util/log.rb +486 -532
  75. data/lib/rbbt/util/migrate.rb +1 -1
  76. data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
  77. data/lib/rbbt/util/misc/development.rb +12 -11
  78. data/lib/rbbt/util/misc/exceptions.rb +117 -112
  79. data/lib/rbbt/util/misc/format.rb +2 -230
  80. data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
  81. data/lib/rbbt/util/misc/inspect.rb +2 -476
  82. data/lib/rbbt/util/misc/lock.rb +109 -106
  83. data/lib/rbbt/util/misc/omics.rb +9 -1
  84. data/lib/rbbt/util/misc/pipes.rb +765 -793
  85. data/lib/rbbt/util/misc/refactor.rb +20 -0
  86. data/lib/rbbt/util/misc/ssw.rb +27 -17
  87. data/lib/rbbt/util/misc/system.rb +0 -15
  88. data/lib/rbbt/util/misc.rb +39 -20
  89. data/lib/rbbt/util/named_array/refactor.rb +4 -0
  90. data/lib/rbbt/util/named_array.rb +3 -220
  91. data/lib/rbbt/util/open/refactor.rb +7 -0
  92. data/lib/rbbt/util/open.rb +3 -857
  93. data/lib/rbbt/util/procpath.rb +6 -6
  94. data/lib/rbbt/util/python/paths.rb +27 -0
  95. data/lib/rbbt/util/python/run.rb +115 -0
  96. data/lib/rbbt/util/python/script.rb +110 -0
  97. data/lib/rbbt/util/python/util.rb +3 -3
  98. data/lib/rbbt/util/python.rb +22 -81
  99. data/lib/rbbt/util/semaphore.rb +152 -148
  100. data/lib/rbbt/util/simpleopt.rb +9 -8
  101. data/lib/rbbt/util/ssh/refactor.rb +19 -0
  102. data/lib/rbbt/util/ssh.rb +122 -118
  103. data/lib/rbbt/util/tar.rb +117 -115
  104. data/lib/rbbt/util/tmpfile.rb +69 -67
  105. data/lib/rbbt/util/version.rb +2 -0
  106. data/lib/rbbt/workflow/refactor/entity.rb +11 -0
  107. data/lib/rbbt/workflow/refactor/export.rb +66 -0
  108. data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
  109. data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
  110. data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
  111. data/lib/rbbt/workflow/refactor.rb +153 -0
  112. data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
  113. data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
  114. data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
  115. data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
  116. data/lib/rbbt/workflow/remote_workflow.rb +6 -1
  117. data/lib/rbbt/workflow/step/run.rb +766 -766
  118. data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
  119. data/lib/rbbt/workflow/step.rb +2 -362
  120. data/lib/rbbt/workflow/task.rb +118 -118
  121. data/lib/rbbt/workflow/usage.rb +289 -287
  122. data/lib/rbbt/workflow/util/archive.rb +6 -5
  123. data/lib/rbbt/workflow/util/data.rb +1 -1
  124. data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
  125. data/lib/rbbt/workflow/util/trace.rb +79 -44
  126. data/lib/rbbt/workflow.rb +4 -882
  127. data/lib/rbbt-util.rb +21 -13
  128. data/lib/rbbt.rb +16 -3
  129. data/python/rbbt/__init__.py +19 -1
  130. data/share/Rlib/plot.R +37 -37
  131. data/share/Rlib/svg.R +22 -5
  132. data/share/install/software/lib/install_helpers +1 -1
  133. data/share/rbbt_commands/hpc/list +2 -3
  134. data/share/rbbt_commands/hpc/orchestrate +4 -4
  135. data/share/rbbt_commands/hpc/tail +2 -0
  136. data/share/rbbt_commands/hpc/task +10 -7
  137. data/share/rbbt_commands/lsf/list +2 -3
  138. data/share/rbbt_commands/lsf/orchestrate +4 -4
  139. data/share/rbbt_commands/lsf/tail +2 -0
  140. data/share/rbbt_commands/lsf/task +10 -7
  141. data/share/rbbt_commands/migrate +1 -1
  142. data/share/rbbt_commands/pbs/list +2 -3
  143. data/share/rbbt_commands/pbs/orchestrate +4 -4
  144. data/share/rbbt_commands/pbs/tail +2 -0
  145. data/share/rbbt_commands/pbs/task +10 -7
  146. data/share/rbbt_commands/resource/produce +8 -1
  147. data/share/rbbt_commands/slurm/list +2 -3
  148. data/share/rbbt_commands/slurm/orchestrate +4 -4
  149. data/share/rbbt_commands/slurm/tail +2 -0
  150. data/share/rbbt_commands/slurm/task +10 -7
  151. data/share/rbbt_commands/system/clean +5 -5
  152. data/share/rbbt_commands/system/status +5 -5
  153. data/share/rbbt_commands/tsv/get +2 -3
  154. data/share/rbbt_commands/tsv/info +10 -13
  155. data/share/rbbt_commands/tsv/keys +18 -14
  156. data/share/rbbt_commands/tsv/slice +2 -2
  157. data/share/rbbt_commands/tsv/transpose +6 -2
  158. data/share/rbbt_commands/workflow/info +20 -24
  159. data/share/rbbt_commands/workflow/list +1 -1
  160. data/share/rbbt_commands/workflow/prov +20 -13
  161. data/share/rbbt_commands/workflow/server +11 -1
  162. data/share/rbbt_commands/workflow/task +76 -71
  163. data/share/rbbt_commands/workflow/write_info +26 -9
  164. data/share/software/opt/ssw/ssw.c +861 -0
  165. data/share/software/opt/ssw/ssw.h +130 -0
  166. data/share/workflow_config.ru +3 -3
  167. metadata +40 -2
@@ -1,148 +1,152 @@
1
- begin
2
- require 'inline'
3
- continue = true
4
- rescue Exception
5
- Log.warn "The RubyInline gem could not be loaded: semaphore synchronization will not work"
6
- continue = false
7
- end
8
-
9
- if continue
10
- module RbbtSemaphore
11
- inline(:C) do |builder|
12
- builder.prefix <<-EOF
13
- #include <unistd.h>
14
- #include <stdio.h>
15
- #include <stdlib.h>
16
- #include <semaphore.h>
17
- #include <time.h>
18
- #include <assert.h>
19
- #include <errno.h>
20
- #include <signal.h>
21
- #include <fcntl.h>
22
- EOF
23
-
24
- builder.c_singleton <<-EOF
25
- void create_semaphore(char* name, int value){
26
- sem_open(name, O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO, value);
27
- }
28
- EOF
29
- builder.c_singleton <<-EOF
30
- void delete_semaphore(char* name){
31
- sem_unlink(name);
32
- }
33
- EOF
34
-
35
- builder.c_singleton <<-EOF
36
- int wait_semaphore(char* name){
37
- int ret;
38
- sem_t* sem;
39
- sem = sem_open(name, 0);
40
- ret = sem_wait(sem);
41
- sem_close(sem);
42
- return(ret);
43
- }
44
- EOF
45
-
46
- builder.c_singleton <<-EOF
47
- void post_semaphore(char* name){
48
- sem_t* sem;
49
- sem = sem_open(name, 0);
50
- sem_post(sem);
51
- sem_close(sem);
52
- }
53
- EOF
54
- end
55
-
56
- SEM_MUTEX = Mutex.new
57
- def self.synchronize(sem)
58
- ret = RbbtSemaphore.wait_semaphore(sem)
59
- raise SemaphoreInterrupted if ret == -1
60
- begin
61
- yield
62
- ensure
63
- RbbtSemaphore.post_semaphore(sem)
64
- end
65
- end
66
-
67
- def self.with_semaphore(size, file = nil)
68
- if file.nil?
69
- file = "/" << Misc.digest(rand(1000000000000).to_s) if file.nil?
70
- else
71
- file = file.gsub('/', '_') if file
72
- end
73
-
74
- begin
75
- Log.debug "Creating semaphore (#{ size }): #{file}"
76
- RbbtSemaphore.create_semaphore(file, size)
77
- yield file
78
- ensure
79
- Log.debug "Removing semaphore #{ file }"
80
- RbbtSemaphore.delete_semaphore(file)
81
- end
82
- end
83
-
84
- def self.fork_each_on_semaphore(elems, size, file = nil)
85
-
86
- TSV.traverse elems, :cpus => size, :bar => "Fork each on semaphore: #{ Misc.fingerprint elems }", :into => Set.new do |elem|
87
- elems.annotate elem if elems.respond_to? :annotate
88
- begin
89
- yield elem
90
- rescue Interrupt
91
- Log.warn "Process #{Process.pid} was aborted"
92
- end
93
- nil
94
- end
95
- nil
96
- end
97
-
98
- def self.thread_each_on_semaphore(elems, size)
99
- mutex = Mutex.new
100
- count = 0
101
- cv = ConditionVariable.new
102
- wait_mutex = Mutex.new
103
-
104
- begin
105
-
106
- threads = []
107
- wait_mutex.synchronize do
108
- threads = elems.collect do |elem|
109
- Thread.new(elem) do |elem|
110
-
111
- continue = false
112
- mutex.synchronize do
113
- while not continue do
114
- if count < size
115
- continue = true
116
- count += 1
117
- end
118
- mutex.sleep 1 unless continue
119
- end
120
- end
121
-
122
- begin
123
- yield elem
124
- rescue Interrupt
125
- Log.error "Thread was aborted while processing: #{Misc.fingerprint elem}"
126
- raise $!
127
- ensure
128
- mutex.synchronize do
129
- count -= 1
130
- cv.signal if mutex.locked?
131
- end
132
- end
133
- end
134
- end
135
- end
136
-
137
- threads.each do |thread|
138
- thread.join
139
- end
140
- rescue Exception
141
- Log.exception $!
142
- Log.info "Ensuring threads are dead: #{threads.length}"
143
- threads.each do |thread| thread.kill end
144
- end
145
- end
146
- end
147
- end
148
-
1
+ require_relative '../refactor'
2
+ Rbbt.require_instead 'scout/semaphore'
3
+
4
+ RbbtSemaphore = ScoutSemaphore
5
+ #begin
6
+ # require 'inline'
7
+ # continue = true
8
+ #rescue Exception
9
+ # Log.warn "The RubyInline gem could not be loaded: semaphore synchronization will not work"
10
+ # continue = false
11
+ #end
12
+ #
13
+ #if continue
14
+ # module RbbtSemaphore
15
+ # inline(:C) do |builder|
16
+ # builder.prefix <<-EOF
17
+ # #include <unistd.h>
18
+ # #include <stdio.h>
19
+ # #include <stdlib.h>
20
+ # #include <semaphore.h>
21
+ # #include <time.h>
22
+ # #include <assert.h>
23
+ # #include <errno.h>
24
+ # #include <signal.h>
25
+ # #include <fcntl.h>
26
+ # EOF
27
+ #
28
+ # builder.c_singleton <<-EOF
29
+ # void create_semaphore(char* name, int value){
30
+ # sem_open(name, O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO, value);
31
+ # }
32
+ # EOF
33
+ # builder.c_singleton <<-EOF
34
+ # void delete_semaphore(char* name){
35
+ # sem_unlink(name);
36
+ # }
37
+ # EOF
38
+ #
39
+ # builder.c_singleton <<-EOF
40
+ # int wait_semaphore(char* name){
41
+ # int ret;
42
+ # sem_t* sem;
43
+ # sem = sem_open(name, 0);
44
+ # ret = sem_wait(sem);
45
+ # sem_close(sem);
46
+ # return(ret);
47
+ # }
48
+ # EOF
49
+ #
50
+ # builder.c_singleton <<-EOF
51
+ # void post_semaphore(char* name){
52
+ # sem_t* sem;
53
+ # sem = sem_open(name, 0);
54
+ # sem_post(sem);
55
+ # sem_close(sem);
56
+ # }
57
+ # EOF
58
+ # end
59
+ #
60
+ # SEM_MUTEX = Mutex.new
61
+ # def self.synchronize(sem)
62
+ # ret = RbbtSemaphore.wait_semaphore(sem)
63
+ # raise SemaphoreInterrupted if ret == -1
64
+ # begin
65
+ # yield
66
+ # ensure
67
+ # RbbtSemaphore.post_semaphore(sem)
68
+ # end
69
+ # end
70
+ #
71
+ # def self.with_semaphore(size, file = nil)
72
+ # if file.nil?
73
+ # file = "/" << Misc.digest(rand(1000000000000).to_s) if file.nil?
74
+ # else
75
+ # file = file.gsub('/', '_') if file
76
+ # end
77
+ #
78
+ # begin
79
+ # Log.debug "Creating semaphore (#{ size }): #{file}"
80
+ # RbbtSemaphore.create_semaphore(file, size)
81
+ # yield file
82
+ # ensure
83
+ # Log.debug "Removing semaphore #{ file }"
84
+ # RbbtSemaphore.delete_semaphore(file)
85
+ # end
86
+ # end
87
+ #
88
+ # def self.fork_each_on_semaphore(elems, size, file = nil)
89
+ #
90
+ # TSV.traverse elems, :cpus => size, :bar => "Fork each on semaphore: #{ Misc.fingerprint elems }", :into => Set.new do |elem|
91
+ # elems.annotate elem if elems.respond_to? :annotate
92
+ # begin
93
+ # yield elem
94
+ # rescue Interrupt
95
+ # Log.warn "Process #{Process.pid} was aborted"
96
+ # end
97
+ # nil
98
+ # end
99
+ # nil
100
+ # end
101
+ #
102
+ # def self.thread_each_on_semaphore(elems, size)
103
+ # mutex = Mutex.new
104
+ # count = 0
105
+ # cv = ConditionVariable.new
106
+ # wait_mutex = Mutex.new
107
+ #
108
+ # begin
109
+ #
110
+ # threads = []
111
+ # wait_mutex.synchronize do
112
+ # threads = elems.collect do |elem|
113
+ # Thread.new(elem) do |elem|
114
+ #
115
+ # continue = false
116
+ # mutex.synchronize do
117
+ # while not continue do
118
+ # if count < size
119
+ # continue = true
120
+ # count += 1
121
+ # end
122
+ # mutex.sleep 1 unless continue
123
+ # end
124
+ # end
125
+ #
126
+ # begin
127
+ # yield elem
128
+ # rescue Interrupt
129
+ # Log.error "Thread was aborted while processing: #{Misc.fingerprint elem}"
130
+ # raise $!
131
+ # ensure
132
+ # mutex.synchronize do
133
+ # count -= 1
134
+ # cv.signal if mutex.locked?
135
+ # end
136
+ # end
137
+ # end
138
+ # end
139
+ # end
140
+ #
141
+ # threads.each do |thread|
142
+ # thread.join
143
+ # end
144
+ # rescue Exception
145
+ # Log.exception $!
146
+ # Log.info "Ensuring threads are dead: #{threads.length}"
147
+ # threads.each do |thread| thread.kill end
148
+ # end
149
+ # end
150
+ # end
151
+ #end
152
+ #
@@ -1,8 +1,9 @@
1
- require 'rbbt/util/simpleopt/accessor'
2
- require 'rbbt/util/simpleopt/doc'
3
- require 'rbbt/util/simpleopt/parse'
4
- require 'rbbt/util/simpleopt/get'
5
- require 'rbbt/util/simpleopt/setup'
6
-
7
- module SOPT
8
- end
1
+ Rbbt.require_instead "scout/simple_opt"
2
+ #require 'rbbt/util/simpleopt/accessor'
3
+ #require 'rbbt/util/simpleopt/doc'
4
+ #require 'rbbt/util/simpleopt/parse'
5
+ #require 'rbbt/util/simpleopt/get'
6
+ #require 'rbbt/util/simpleopt/setup'
7
+ #
8
+ #module SOPT
9
+ #end
@@ -0,0 +1,19 @@
1
+
2
+ class SSHLine
3
+ def ruby(script)
4
+ @output = ""
5
+ @complete_output = false
6
+ script = "require 'rbbt-util'\n" << script
7
+ cmd = "ruby -I ~/git/rbbt6/lib/ -e \"#{script.gsub('"','\\"')}\"\n"
8
+ Log.debug "Running ruby on #{@host}:\n#{ script }"
9
+ @ch.send_data(cmd)
10
+ @ch.send_data("echo DONECMD: $?\n")
11
+ @ssh.loop{ !@complete_output }
12
+ if @exit_status.to_i == 0
13
+ return @output
14
+ else
15
+ raise SSHProcessFailed.new @host, "Ruby script:\n#{script}"
16
+ end
17
+ end
18
+ end
19
+
data/lib/rbbt/util/ssh.rb CHANGED
@@ -1,118 +1,122 @@
1
- require 'net/ssh'
2
-
3
- class SSHLine
4
-
5
- def initialize(host, user = nil)
6
- @host = host
7
- @user = user
8
-
9
- @ssh = Net::SSH.start(@host, @user)
10
-
11
- @ch = @ssh.open_channel do |ch|
12
- ch.exec 'bash -l'
13
- end
14
-
15
- @ch.on_data do |_,data|
16
- if m = data.match(/DONECMD: (\d+)\n/)
17
- @exit_status = m[1].to_i
18
- @output << data.sub(m[0],'')
19
- serve_output
20
- else
21
- @output << data
22
- end
23
- end
24
-
25
- @ch.on_extended_data do |_,c,err|
26
- STDERR.write err
27
- end
28
- end
29
-
30
- def send_cmd(command)
31
- @output = ""
32
- @complete_output = false
33
- @ch.send_data(command+"\necho DONECMD: $?\n")
34
- end
35
-
36
- def serve_output
37
- @complete_output = true
38
- end
39
-
40
- def run(command)
41
- send_cmd(command)
42
- @ssh.loop{ ! @complete_output}
43
- if @exit_status.to_i == 0
44
- return @output
45
- else
46
- raise SSHProcessFailed.new @host, command
47
- end
48
- end
49
-
50
- def ruby(script)
51
- @output = ""
52
- @complete_output = false
53
- cmd = "ruby -e \"#{script.gsub('"','\\"')}\"\n"
54
- Log.debug "Running ruby on #{@host}:\n#{ script }"
55
- @ch.send_data(cmd)
56
- @ch.send_data("echo DONECMD: $?\n")
57
- @ssh.loop{ !@complete_output }
58
- if @exit_status.to_i == 0
59
- return @output
60
- else
61
- raise SSHProcessFailed.new @host, "Ruby script:\n#{script}"
62
- end
63
- end
64
-
65
- def rbbt(script)
66
- rbbt_script =<<-EOF
67
- require 'rbbt-util'
68
- require 'rbbt/workflow'
69
-
70
- res = begin
71
- old_stdout = STDOUT.dup; STDOUT.reopen(STDERR)
72
- #{script}
73
- ensure
74
- STDOUT.reopen(old_stdout)
75
- end
76
-
77
- puts Marshal.dump(res)
78
- EOF
79
-
80
- m = ruby(rbbt_script)
81
- Marshal.load m
82
- end
83
-
84
- def workflow(workflow, script)
85
- preamble =<<-EOF
86
- wf = Workflow.require_workflow('#{workflow}')
87
- EOF
88
-
89
- rbbt(preamble + "\n" + script)
90
- end
91
-
92
- @connections = {}
93
- def self.open(host, user = nil)
94
- @connections[[host, user]] ||= SSHLine.new host, user
95
- end
96
-
97
- def self.run(server, cmd, options = nil)
98
- cmd = cmd * " " if Array === cmd
99
- cmd += " " + CMD.process_cmd_options(options) if options
100
- open(server).run(cmd)
101
- end
102
-
103
- def self.ruby(server, script)
104
- open(server).ruby(script)
105
- end
106
-
107
- def self.rbbt(server, script)
108
- open(server).rbbt(script)
109
- end
110
-
111
- def self.workflow(server, workflow, script)
112
- open(server).workflow(workflow, script)
113
- end
114
-
115
- def self.command(server, command, argv = [], options = nil)
116
- run(server, [command] + argv, options)
117
- end
118
- end
1
+ require_relative '../refactor'
2
+ Rbbt.require_instead 'scout/offsite/ssh'
3
+ require_relative 'ssh/refactor'
4
+
5
+ #require 'net/ssh'
6
+ #
7
+ #class SSHLine
8
+ #
9
+ # def initialize(host, user = nil)
10
+ # @host = host
11
+ # @user = user
12
+ #
13
+ # @ssh = Net::SSH.start(@host, @user)
14
+ #
15
+ # @ch = @ssh.open_channel do |ch|
16
+ # ch.exec 'bash -l'
17
+ # end
18
+ #
19
+ # @ch.on_data do |_,data|
20
+ # if m = data.match(/DONECMD: (\d+)\n/)
21
+ # @exit_status = m[1].to_i
22
+ # @output << data.sub(m[0],'')
23
+ # serve_output
24
+ # else
25
+ # @output << data
26
+ # end
27
+ # end
28
+ #
29
+ # @ch.on_extended_data do |_,c,err|
30
+ # STDERR.write err
31
+ # end
32
+ # end
33
+ #
34
+ # def send_cmd(command)
35
+ # @output = ""
36
+ # @complete_output = false
37
+ # @ch.send_data(command+"\necho DONECMD: $?\n")
38
+ # end
39
+ #
40
+ # def serve_output
41
+ # @complete_output = true
42
+ # end
43
+ #
44
+ # def run(command)
45
+ # send_cmd(command)
46
+ # @ssh.loop{ ! @complete_output}
47
+ # if @exit_status.to_i == 0
48
+ # return @output
49
+ # else
50
+ # raise SSHProcessFailed.new @host, command
51
+ # end
52
+ # end
53
+ #
54
+ # def ruby(script)
55
+ # @output = ""
56
+ # @complete_output = false
57
+ # cmd = "ruby -e \"#{script.gsub('"','\\"')}\"\n"
58
+ # Log.debug "Running ruby on #{@host}:\n#{ script }"
59
+ # @ch.send_data(cmd)
60
+ # @ch.send_data("echo DONECMD: $?\n")
61
+ # @ssh.loop{ !@complete_output }
62
+ # if @exit_status.to_i == 0
63
+ # return @output
64
+ # else
65
+ # raise SSHProcessFailed.new @host, "Ruby script:\n#{script}"
66
+ # end
67
+ # end
68
+ #
69
+ # def rbbt(script)
70
+ # rbbt_script =<<-EOF
71
+ #require 'rbbt-util'
72
+ #require 'rbbt/workflow'
73
+ #
74
+ # res = begin
75
+ # old_stdout = STDOUT.dup; STDOUT.reopen(STDERR)
76
+ ##{script}
77
+ # ensure
78
+ # STDOUT.reopen(old_stdout)
79
+ # end
80
+ #
81
+ # puts Marshal.dump(res)
82
+ # EOF
83
+ #
84
+ # m = ruby(rbbt_script)
85
+ # Marshal.load m
86
+ # end
87
+ #
88
+ # def workflow(workflow, script)
89
+ # preamble =<<-EOF
90
+ #wf = Workflow.require_workflow('#{workflow}')
91
+ # EOF
92
+ #
93
+ # rbbt(preamble + "\n" + script)
94
+ # end
95
+ #
96
+ # @connections = {}
97
+ # def self.open(host, user = nil)
98
+ # @connections[[host, user]] ||= SSHLine.new host, user
99
+ # end
100
+ #
101
+ # def self.run(server, cmd, options = nil)
102
+ # cmd = cmd * " " if Array === cmd
103
+ # cmd += " " + CMD.process_cmd_options(options) if options
104
+ # open(server).run(cmd)
105
+ # end
106
+ #
107
+ # def self.ruby(server, script)
108
+ # open(server).ruby(script)
109
+ # end
110
+ #
111
+ # def self.rbbt(server, script)
112
+ # open(server).rbbt(script)
113
+ # end
114
+ #
115
+ # def self.workflow(server, workflow, script)
116
+ # open(server).workflow(workflow, script)
117
+ # end
118
+ #
119
+ # def self.command(server, command, argv = [], options = nil)
120
+ # run(server, [command] + argv, options)
121
+ # end
122
+ #end