rbbt-util 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +2 -2
- data/bin/rbbt +45 -0
- data/bin/rbbt_dangling_locks.rb +9 -0
- data/bin/rbbt_monitor.rb +12 -10
- data/bin/run_workflow.rb +80 -18
- data/lib/rbbt.rb +1 -1
- data/lib/rbbt/annotations.rb +1 -19
- data/lib/rbbt/annotations/annotated_array.rb +23 -0
- data/lib/rbbt/fix_width_table.rb +2 -2
- data/lib/rbbt/persist.rb +13 -5
- data/lib/rbbt/persist/tsv.rb +2 -0
- data/lib/rbbt/resource.rb +4 -4
- data/lib/rbbt/resource/path.rb +35 -10
- data/lib/rbbt/resource/util.rb +54 -47
- data/lib/rbbt/tsv.rb +17 -15
- data/lib/rbbt/tsv/accessor.rb +35 -37
- data/lib/rbbt/tsv/excel.rb +3 -1
- data/lib/rbbt/tsv/manipulate.rb +27 -4
- data/lib/rbbt/tsv/parser.rb +13 -7
- data/lib/rbbt/util/R.rb +11 -1
- data/lib/rbbt/util/misc.rb +182 -26
- data/lib/rbbt/util/named_array.rb +14 -7
- data/lib/rbbt/util/open.rb +2 -1
- data/lib/rbbt/util/tmpfile.rb +16 -1
- data/lib/rbbt/workflow.rb +63 -101
- data/lib/rbbt/workflow/accessor.rb +19 -9
- data/lib/rbbt/workflow/annotate.rb +33 -64
- data/lib/rbbt/workflow/definition.rb +71 -0
- data/lib/rbbt/workflow/soap.rb +15 -5
- data/lib/rbbt/workflow/step.rb +57 -8
- data/lib/rbbt/workflow/usage.rb +72 -0
- data/share/lib/R/util.R +12 -0
- data/share/rbbt_commands/conf/web_user/add +26 -0
- data/share/rbbt_commands/conf/web_user/list +9 -0
- data/share/rbbt_commands/conf/web_user/remove +18 -0
- data/share/rbbt_commands/workflow/remote/add +11 -0
- data/share/rbbt_commands/workflow/remote/list +9 -0
- data/share/rbbt_commands/workflow/remote/remove +9 -0
- data/share/rbbt_commands/workflow/task +181 -0
- data/test/rbbt/test_resource.rb +2 -1
- data/test/rbbt/test_workflow.rb +13 -0
- data/test/rbbt/tsv/test_manipulate.rb +18 -0
- data/test/rbbt/util/test_misc.rb +19 -39
- data/test/rbbt/util/test_tmpfile.rb +8 -0
- data/test/rbbt/workflow/test_soap.rb +2 -0
- metadata +31 -2
data/lib/rbbt/resource/path.rb
CHANGED
@@ -37,7 +37,7 @@ module Path
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def glob(pattern = '*')
|
40
|
-
Dir.glob(File.join(self, pattern))
|
40
|
+
Dir.glob(File.join(self, pattern)).collect{|f| Path.setup(f, self.resource, self.pkgdir)}
|
41
41
|
end
|
42
42
|
|
43
43
|
def path_get_brackets(name)
|
@@ -59,13 +59,20 @@ module Path
|
|
59
59
|
end
|
60
60
|
|
61
61
|
SEARCH_PATHS = {
|
62
|
-
:user
|
63
|
-
:global
|
64
|
-
:local
|
65
|
-
:lib
|
62
|
+
:user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
|
63
|
+
:global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
64
|
+
:local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
65
|
+
:lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
|
66
66
|
:default => :user
|
67
67
|
}
|
68
68
|
|
69
|
+
search_path_file = File.join(ENV['HOME'], '.rbbt/etc/search_paths')
|
70
|
+
if File.exists?(search_path_file)
|
71
|
+
YAML.load(File.open(search_path_file)).each do |where, location|
|
72
|
+
SEARCH_PATHS[where.to_sym] = location
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
69
76
|
def find(where = nil, caller_lib = nil, search_paths = nil)
|
70
77
|
where = search_paths[:default] if where == :default
|
71
78
|
search_paths ||= SEARCH_PATHS
|
@@ -78,7 +85,9 @@ module Path
|
|
78
85
|
|
79
86
|
path = nil
|
80
87
|
if where.nil?
|
81
|
-
|
88
|
+
%w(user local global lib).each do |w|
|
89
|
+
w = w.to_sym
|
90
|
+
next unless search_paths.include? w
|
82
91
|
path = find(w, caller_lib, search_paths)
|
83
92
|
return path if File.exists? path
|
84
93
|
end
|
@@ -88,12 +97,19 @@ module Path
|
|
88
97
|
raise "Path '#{ path }' not found, and no default specified in search paths: #{search_paths.inspect}"
|
89
98
|
end
|
90
99
|
else
|
100
|
+
where = where.to_sym
|
101
|
+
raise "Did not recognize the 'where' tag: #{where}. Options: #{search_paths.keys}" unless search_paths.include? where
|
91
102
|
libdir = where == :lib ? Path.caller_lib_dir(caller_lib) : ""
|
92
103
|
libdir ||= ""
|
93
104
|
Path.setup search_paths[where].sub('{PKGDIR}', pkgdir).sub('{TOPLEVEL}', toplevel).sub('{SUBPATH}', subpath).sub('{LIBDIR}', libdir), @pkgdir, @resource
|
94
105
|
end
|
95
106
|
end
|
96
107
|
|
108
|
+
def find_all(caller_lib = nil, search_paths = nil)
|
109
|
+
search_paths ||= SEARCH_PATHS
|
110
|
+
search_paths.keys.collect{|where| find(where, Path.caller_lib_dir, search_paths)}.select{|file| file.exists?}.uniq
|
111
|
+
end
|
112
|
+
|
97
113
|
#{{{ Methods
|
98
114
|
|
99
115
|
def in_dir?(dir)
|
@@ -125,13 +141,18 @@ module Path
|
|
125
141
|
|
126
142
|
resource.produce self, force
|
127
143
|
|
128
|
-
|
144
|
+
self
|
129
145
|
end
|
130
146
|
|
131
147
|
def read(&block)
|
132
148
|
Open.read(self.produce.find, &block)
|
133
149
|
end
|
134
150
|
|
151
|
+
def write(*args, &block)
|
152
|
+
Open.write(self.produce.find, *args, &block)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
135
156
|
def open(options = {})
|
136
157
|
Open.open(self.produce.find, options)
|
137
158
|
end
|
@@ -140,6 +161,10 @@ module Path
|
|
140
161
|
"" + self
|
141
162
|
end
|
142
163
|
|
164
|
+
def basename
|
165
|
+
Path.setup(File.basename(self), self.resource, self.pkgdir)
|
166
|
+
end
|
167
|
+
|
143
168
|
def tsv(*args)
|
144
169
|
TSV.open(self.produce, *args)
|
145
170
|
end
|
@@ -157,15 +182,15 @@ module Path
|
|
157
182
|
end
|
158
183
|
|
159
184
|
def index(options = {})
|
160
|
-
TSV.index(self.produce
|
185
|
+
TSV.index(self.produce, options)
|
161
186
|
end
|
162
187
|
|
163
188
|
def range_index(start, eend, options = {})
|
164
|
-
TSV.range_index(self.produce
|
189
|
+
TSV.range_index(self.produce, start, eend, options)
|
165
190
|
end
|
166
191
|
|
167
192
|
def pos_index(pos, options = {})
|
168
|
-
TSV.pos_index(self.produce
|
193
|
+
TSV.pos_index(self.produce, pos, options)
|
169
194
|
end
|
170
195
|
|
171
196
|
def to_yaml(*args)
|
data/lib/rbbt/resource/util.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rbbt/resource/rake'
|
2
1
|
|
3
2
|
module Path
|
4
3
|
|
@@ -31,53 +30,60 @@ end
|
|
31
30
|
|
32
31
|
module Resource
|
33
32
|
def set_software_env(software_dir)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
33
|
+
software_dir.find_all.each do |software_dir|
|
34
|
+
bin_dir = File.join(software_dir, 'bin')
|
35
|
+
opt_dir = File.join(software_dir, 'opt')
|
36
|
+
|
37
|
+
Misc.env_add 'PATH', bin_dir
|
38
|
+
|
39
|
+
FileUtils.mkdir_p opt_dir unless File.exists? opt_dir
|
40
|
+
|
41
|
+
%w(.ld-paths .pkgconfig-paths .aclocal-paths .java-classpaths).each do |file|
|
42
|
+
filename = File.join(opt_dir, file)
|
43
|
+
begin
|
44
|
+
FileUtils.touch filename unless File.exists? filename
|
45
|
+
rescue
|
46
|
+
Log.warn("Could not touch #{ filename }")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
if not File.exists? File.join(opt_dir,'.post_install')
|
52
|
+
Open.write(File.join(opt_dir,'.post_install'),"#!/bin/bash\n")
|
53
|
+
end
|
54
|
+
rescue Exception
|
55
|
+
Log.warn("Could not create default .post_install in #{ software_dir }")
|
56
|
+
end
|
57
|
+
|
58
|
+
Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line|
|
59
|
+
Misc.env_add('LD_LIBRARY_PATH',line.chomp)
|
60
|
+
Misc.env_add('LD_RUN_PATH',line.chomp)
|
61
|
+
end if File.exists? File.join(opt_dir, '.ld-paths')
|
62
|
+
|
63
|
+
Open.read(File.join opt_dir, '.pkgconfig-paths').split(/\n/).each do |line|
|
64
|
+
Misc.env_add('PKG_CONFIG_PATH',line.chomp)
|
65
|
+
end if File.exists? File.join(opt_dir, '.pkgconfig-paths')
|
66
|
+
|
67
|
+
Open.read(File.join opt_dir, '.aclocal-paths').split(/\n/).each do |line|
|
68
|
+
Misc.env_add('ACLOCAL_FLAGS', "-I#{File.join(opt_dir, line.chomp)}", ' ')
|
69
|
+
end if File.exists? File.join(opt_dir, '.aclocal-paths')
|
70
|
+
|
71
|
+
Open.read(File.join opt_dir, '.java-classpaths').split(/\n/).each do |line|
|
72
|
+
Misc.env_add('CLASSPATH', "#{File.join(opt_dir,'java', 'lib', line.chomp)}")
|
73
|
+
end if File.exists? File.join(opt_dir, '.java-classpaths')
|
74
|
+
|
75
|
+
Dir.glob(File.join opt_dir, 'jars', '*').each do |file|
|
76
|
+
Misc.env_add('CLASSPATH', "#{File.expand_path(file)}")
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
File.chmod 0777, File.join(opt_dir, '.post_install')
|
81
|
+
rescue
|
82
|
+
Log.warn("Could not change permisions of .post_install in #{ software_dir }")
|
83
|
+
end
|
84
|
+
|
85
|
+
CMD.cmd(File.join(opt_dir, '.post_install')) if File.exists? File.join(opt_dir, '.post_install')
|
60
86
|
end
|
61
|
-
|
62
|
-
Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line|
|
63
|
-
Misc.env_add('LD_LIBRARY_PATH',line.chomp)
|
64
|
-
end
|
65
|
-
|
66
|
-
Open.read(File.join opt_dir, '.aclocal-paths').split(/\n/).each do |line|
|
67
|
-
Misc.env_add('ACLOCAL_FLAGS', "-I#{File.join(opt_dir, line.chomp)}", ' ')
|
68
|
-
end
|
69
|
-
|
70
|
-
Open.read(File.join opt_dir, '.java-classpaths').split(/\n/).each do |line|
|
71
|
-
Misc.env_add('CLASSPATH', "#{File.join(opt_dir,'java', 'lib', line.chomp)}")
|
72
|
-
end
|
73
|
-
|
74
|
-
Dir.glob(File.join opt_dir, 'jars', '*').each do |file|
|
75
|
-
Misc.env_add('CLASSPATH', "#{File.expand_path(file)}")
|
76
|
-
end
|
77
|
-
|
78
|
-
File.chmod 0774, File.join(opt_dir, '.post_install')
|
79
|
-
|
80
|
-
CMD.cmd(File.join(opt_dir, '.post_install'))
|
81
87
|
end
|
82
88
|
|
83
89
|
|
@@ -100,6 +106,7 @@ module Resource
|
|
100
106
|
rake_dir = rake_dir.find if rake_dir.respond_to? :find
|
101
107
|
|
102
108
|
begin
|
109
|
+
require 'rbbt/resource/rake'
|
103
110
|
Rake.run(rakefile, rake_dir, task)
|
104
111
|
rescue Rake::TaskNotFound
|
105
112
|
raise $! if rake_dir.nil? or rake_dir.empty? or rake_dir == "/" or rake_dir == "./"
|
data/lib/rbbt/tsv.rb
CHANGED
@@ -31,7 +31,7 @@ module TSV
|
|
31
31
|
hash
|
32
32
|
end
|
33
33
|
|
34
|
-
# options
|
34
|
+
# options shift if type.nil?
|
35
35
|
def self.open(source, type = nil, options = nil)
|
36
36
|
type, options = nil, type if options.nil? and Hash === type
|
37
37
|
options ||= {}
|
@@ -50,24 +50,24 @@ module TSV
|
|
50
50
|
|
51
51
|
lock_filename = filename.nil? ? nil : Persist.persistence_path(filename, {:dir => Rbbt.tmp.tsv_open_locks.find})
|
52
52
|
Misc.lock lock_filename do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
data = Persist.persist_tsv source, filename, options, persist_options do |data|
|
54
|
+
if serializer
|
55
|
+
data.extend TSV unless TSV === data
|
56
|
+
data.serializer = serializer
|
57
|
+
end
|
58
58
|
|
59
|
-
|
59
|
+
open_options = Misc.pull_keys options, :open
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
stream = get_stream source, open_options
|
62
|
+
parse stream, data, options
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
data.filename = filename.to_s unless filename.nil?
|
65
|
+
if data.identifiers.nil? and Path === filename and filename.identifier_file_path
|
66
|
+
data.identifiers = filename.identifier_file_path.to_s
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
data
|
70
|
+
end
|
71
71
|
end
|
72
72
|
|
73
73
|
data.unnamed = unnamed unless unnamed.nil?
|
@@ -145,6 +145,8 @@ module TSV
|
|
145
145
|
begin
|
146
146
|
progress_monitor.tick(stream.pos) if progress_monitor
|
147
147
|
|
148
|
+
raise Parser::SKIP_LINE if line.empty?
|
149
|
+
|
148
150
|
line = Misc.fixutf8(line)
|
149
151
|
line = parser.process line
|
150
152
|
parts = parser.chop_line line
|
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -6,7 +6,7 @@ module TSV
|
|
6
6
|
|
7
7
|
NIL_YAML = "--- \n"
|
8
8
|
|
9
|
-
attr_accessor :unnamed, :serializer_module, :entity_options
|
9
|
+
attr_accessor :unnamed, :serializer_module, :entity_options, :entity_templates
|
10
10
|
|
11
11
|
def entity_options
|
12
12
|
if @entity_options.nil?
|
@@ -16,33 +16,43 @@ module TSV
|
|
16
16
|
@entity_options
|
17
17
|
end
|
18
18
|
|
19
|
+
def entity_templates
|
20
|
+
@entity_templates ||= {}
|
21
|
+
end
|
22
|
+
|
19
23
|
def prepare_entity(entity, field, options = {})
|
20
24
|
return entity if entity.nil?
|
21
25
|
return entity unless defined? Entity
|
22
26
|
entity = entity if options.delete :dup_array
|
23
|
-
|
24
|
-
if (template =
|
27
|
+
entity_templates
|
28
|
+
if (template = entity_templates[field])
|
25
29
|
entity = template.annotate(entity.frozen? ? entity.dup : entity)
|
26
30
|
entity.extend AnnotatedArray if Array === entity
|
27
31
|
entity
|
28
32
|
else
|
29
|
-
if
|
33
|
+
if entity_templates.include? field
|
30
34
|
entity
|
31
35
|
else
|
32
36
|
template = Misc.prepare_entity("TEMPLATE", field, options)
|
33
37
|
if Annotated === template
|
34
|
-
|
38
|
+
entity_templates[field] = template
|
35
39
|
entity = template.annotate(entity.frozen? ? entity.dup : entity)
|
36
40
|
entity.extend AnnotatedArray if Array === entity
|
37
41
|
entity
|
38
42
|
else
|
39
|
-
|
43
|
+
entity_templates[field] = nil
|
40
44
|
entity
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
50
|
+
def setup_array(*args)
|
51
|
+
res = NamedArray.setup(*args)
|
52
|
+
res.instance_variable_set(:@entity_templates, entity_templates)
|
53
|
+
res
|
54
|
+
end
|
55
|
+
|
46
56
|
def with_unnamed
|
47
57
|
saved_unnamed = @unnamed
|
48
58
|
@unnamed = true
|
@@ -109,7 +119,7 @@ module TSV
|
|
109
119
|
|
110
120
|
case type
|
111
121
|
when :double, :list
|
112
|
-
|
122
|
+
setup_array value, fields, key, entity_options, entity_templates
|
113
123
|
when :flat, :single
|
114
124
|
value = value.dup if value.frozen?
|
115
125
|
|
@@ -135,7 +145,7 @@ module TSV
|
|
135
145
|
|
136
146
|
case type
|
137
147
|
when :double, :list
|
138
|
-
values.each{|value|
|
148
|
+
values.each{|value| setup_array value, fields, nil, entity_options}
|
139
149
|
when :flat, :single
|
140
150
|
values = values.collect{|v| prepare_entity(v, fields.first, entity_options)}
|
141
151
|
end
|
@@ -159,7 +169,7 @@ module TSV
|
|
159
169
|
if not fields.nil?
|
160
170
|
case type
|
161
171
|
when :double, :list
|
162
|
-
|
172
|
+
setup_array value, fields, key, entity_options, entity_templates if Array === value
|
163
173
|
when :flat, :single
|
164
174
|
prepare_entity(value, fields.first, entity_options)
|
165
175
|
end
|
@@ -186,7 +196,7 @@ module TSV
|
|
186
196
|
if not fields.nil?
|
187
197
|
case type
|
188
198
|
when :double, :list
|
189
|
-
|
199
|
+
setup_array value, fields, key, entity_options if Array === value
|
190
200
|
when :flat, :single
|
191
201
|
value = prepare_entity(value, fields.first, entity_options)
|
192
202
|
end
|
@@ -194,7 +204,6 @@ module TSV
|
|
194
204
|
key = prepare_entity(key, key_field, entity_options)
|
195
205
|
end
|
196
206
|
|
197
|
-
|
198
207
|
if block_given?
|
199
208
|
yield key, value
|
200
209
|
else
|
@@ -225,8 +234,6 @@ module TSV
|
|
225
234
|
end
|
226
235
|
end
|
227
236
|
|
228
|
-
|
229
|
-
|
230
237
|
#{{{ Sorting
|
231
238
|
|
232
239
|
def tsv_sort_by(field = nil, just_keys = false, &block)
|
@@ -282,30 +289,21 @@ module TSV
|
|
282
289
|
end
|
283
290
|
|
284
291
|
# Starts in page 1
|
285
|
-
def page(pnum, psize, field = nil, just_keys = false, &block)
|
286
|
-
|
287
|
-
|
288
|
-
|
292
|
+
def page(pnum, psize, field = nil, just_keys = false, reverse = false, &block)
|
293
|
+
pstart = psize * (pnum - 1)
|
294
|
+
pend = psize * pnum - 1
|
295
|
+
field = :key if field == "key"
|
296
|
+
keys = sort_by(field || :key, true, &block)
|
297
|
+
keys.reverse! if reverse
|
298
|
+
|
299
|
+
if just_keys
|
300
|
+
keys[pstart..pend]
|
289
301
|
else
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
with_unnamed do
|
294
|
-
pstart = psize * (pnum - 1)
|
295
|
-
pend = psize * pnum - 1
|
296
|
-
field = :key if field == "key"
|
297
|
-
keys = sort_by(field || :key, true, &block)
|
298
|
-
keys.reverse! if reverse
|
299
|
-
|
300
|
-
if just_keys
|
301
|
-
keys[pstart..pend]
|
302
|
-
else
|
303
|
-
select :key => keys[pstart..pend]
|
304
|
-
end
|
302
|
+
select :key => keys[pstart..pend]
|
305
303
|
end
|
306
304
|
end
|
307
305
|
|
308
|
-
|
306
|
+
|
309
307
|
def self.entry(*entries)
|
310
308
|
entries = entries.collect{|entry| entry.to_s}
|
311
309
|
ENTRIES.concat entries
|
@@ -332,7 +330,7 @@ if '#{entry}' == 'serializer'
|
|
332
330
|
return if value.nil?
|
333
331
|
|
334
332
|
self.serializer_module = SERIALIZER_ALIAS[value.to_sym]
|
335
|
-
|
333
|
+
|
336
334
|
if serializer_module.nil?
|
337
335
|
class << self
|
338
336
|
alias serialized_get tsv_clean_get_brackets
|
@@ -366,7 +364,7 @@ else
|
|
366
364
|
self.tsv_clean_set_brackets '#{key}', value.nil? ? NIL_YAML : value.to_yaml
|
367
365
|
end
|
368
366
|
end
|
369
|
-
"
|
367
|
+
"
|
370
368
|
end
|
371
369
|
end
|
372
370
|
|
@@ -384,7 +382,7 @@ end
|
|
384
382
|
if @fields.nil? or @unnamed
|
385
383
|
@fields
|
386
384
|
else
|
387
|
-
@named_fields ||= NamedArray.setup @fields, @fields, nil, entity_options
|
385
|
+
@named_fields ||= NamedArray.setup @fields, @fields, nil, entity_options, entity_templates
|
388
386
|
end
|
389
387
|
end
|
390
388
|
|
@@ -404,7 +402,7 @@ end
|
|
404
402
|
return [] if list.nil? || list.empty?
|
405
403
|
fields ||= list.fields if list.respond_to? :fields
|
406
404
|
zipped = list[0].zip(*list[1..-1])
|
407
|
-
zipped = zipped.collect{|v|
|
405
|
+
zipped = zipped.collect{|v| setup_array(v, fields)} if fields
|
408
406
|
zipped
|
409
407
|
end
|
410
408
|
|