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.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +2 -2
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +9 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +27 -17
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +11 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +40 -2
data/lib/rbbt/resource/path.rb
CHANGED
@@ -1,497 +1,317 @@
|
|
1
|
-
require 'rbbt/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
string
|
13
|
-
string
|
14
|
-
string.
|
15
|
-
string.
|
16
|
-
string.
|
17
|
-
string
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
search_paths
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
super
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
self.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
toplevel, subpath =
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
path =
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
libdir =
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
sub('{
|
249
|
-
sub('{
|
250
|
-
sub('{
|
251
|
-
sub('{
|
252
|
-
sub('{
|
253
|
-
sub('{
|
254
|
-
sub('{
|
255
|
-
sub('{
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
res
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
search_paths
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
self
|
319
|
-
end
|
320
|
-
|
321
|
-
def read(&block)
|
322
|
-
Open.read(self.produce.find, &block)
|
323
|
-
end
|
324
|
-
|
325
|
-
def write(*args, &block)
|
326
|
-
Open.write(self.produce.find, *args, &block)
|
327
|
-
end
|
328
|
-
|
329
|
-
|
330
|
-
def open(options = {}, &block)
|
331
|
-
file = Open.remote?(self) || Open.ssh?(self) ? self : self.produce.find
|
332
|
-
Open.open(file, options, &block)
|
333
|
-
end
|
334
|
-
|
335
|
-
def to_s
|
336
|
-
"" + self
|
337
|
-
end
|
338
|
-
|
339
|
-
def basename
|
340
|
-
Path.setup(File.basename(self), self.resource, self.pkgdir)
|
341
|
-
end
|
342
|
-
|
343
|
-
def tsv(*args)
|
344
|
-
begin
|
345
|
-
path = self.produce
|
346
|
-
rescue Resource::ResourceNotFound => e
|
347
|
-
begin
|
348
|
-
path = self.set_extension('tsv').produce
|
349
|
-
rescue Resource::ResourceNotFound
|
350
|
-
raise e
|
351
|
-
end
|
352
|
-
end
|
353
|
-
TSV.open(path, *args)
|
354
|
-
end
|
355
|
-
|
356
|
-
def tsv_options(options = {})
|
357
|
-
self.open do |stream|
|
358
|
-
TSV::Parser.new(stream, options).options
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def traverse(options = {}, &block)
|
363
|
-
TSV::Parser.traverse(self.open, options, &block)
|
364
|
-
end
|
365
|
-
|
366
|
-
def list
|
367
|
-
begin
|
368
|
-
path = self.produce
|
369
|
-
rescue Resource::ResourceNotFound => e
|
370
|
-
begin
|
371
|
-
path = self.set_extension('list').produce
|
372
|
-
rescue Resource::ResourceNotFound
|
373
|
-
raise e
|
374
|
-
end
|
375
|
-
end
|
376
|
-
Open.read(path).split("\n")
|
377
|
-
end
|
378
|
-
|
379
|
-
def keys(field = 0, sep = "\t")
|
380
|
-
Open.read(self.produce.find).split("\n").collect{|l| next if l =~ /^#/; l.split(sep, -1)[field]}.compact
|
381
|
-
end
|
382
|
-
|
383
|
-
def yaml
|
384
|
-
self.open do |f|
|
385
|
-
YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(f) : YAML.load(f)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
def pipe_to(cmd, options = {})
|
390
|
-
CMD.cmd(cmd, {:in => self.open, :pipe => true}.merge(options))
|
391
|
-
end
|
392
|
-
|
393
|
-
def index(options = {})
|
394
|
-
TSV.index(self.produce, options)
|
395
|
-
end
|
396
|
-
|
397
|
-
def range_index(start, eend, options = {})
|
398
|
-
TSV.range_index(self.produce, start, eend, options)
|
399
|
-
end
|
400
|
-
|
401
|
-
def pos_index(pos, options = {})
|
402
|
-
TSV.pos_index(self.produce, pos, options)
|
403
|
-
end
|
404
|
-
|
405
|
-
def to_yaml(*args)
|
406
|
-
self.to_s.to_yaml(*args)
|
407
|
-
end
|
408
|
-
|
409
|
-
def fields
|
410
|
-
TSV.parse_header(self.open).fields
|
411
|
-
end
|
412
|
-
|
413
|
-
def all_fields
|
414
|
-
self.open do |stream|
|
415
|
-
TSV.parse_header(stream).all_fields
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
def identifier_file_path
|
420
|
-
if self.dirname.identifiers.exists?
|
421
|
-
self.dirname.identifiers
|
422
|
-
else
|
423
|
-
nil
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
def identifier_files
|
428
|
-
if identifier_file_path.nil?
|
429
|
-
[]
|
430
|
-
else
|
431
|
-
[identifier_file_path]
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
def set_extension(new_extension = nil)
|
436
|
-
new_path = self + "." + new_extension.to_s
|
437
|
-
self.annotate(new_path)
|
438
|
-
end
|
439
|
-
|
440
|
-
def remove_extension(new_extension = nil)
|
441
|
-
self.sub(/\.[^\.\/]{1,5}$/,'')
|
442
|
-
end
|
443
|
-
|
444
|
-
|
445
|
-
def self.get_extension(path)
|
446
|
-
path.match(/\.([^\.\/]{1,5})$/)[1]
|
447
|
-
end
|
448
|
-
|
449
|
-
def replace_extension(new_extension = nil, multiple = false)
|
450
|
-
if String === multiple
|
451
|
-
new_path = self.sub(/(\.[^\.\/]{1,5})(.#{multiple})?$/,'')
|
452
|
-
elsif multiple
|
453
|
-
new_path = self.sub(/(\.[^\.\/]{1,5})+$/,'')
|
454
|
-
else
|
455
|
-
new_path = self.sub(/\.[^\.\/]{1,5}$/,'')
|
456
|
-
end
|
457
|
-
new_path = new_path + "." + new_extension.to_s
|
458
|
-
self.annotate(new_path)
|
459
|
-
end
|
460
|
-
|
461
|
-
def doc_file(relative_to = 'lib')
|
462
|
-
if located?
|
463
|
-
lib_dir = Path.caller_lib_dir(self, relative_to)
|
464
|
-
relative_file = File.join( 'doc', self.sub(lib_dir,''))
|
465
|
-
Path.setup File.join(lib_dir, relative_file) , @pkgdir, @resource
|
466
|
-
else
|
467
|
-
Path.setup File.join('doc', self) , @pkgdir, @resource
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
def source_for_doc_file(relative_to = 'lib')
|
472
|
-
if located?
|
473
|
-
lib_dir = Path.caller_lib_dir(Path.caller_lib_dir(self, 'doc'), relative_to)
|
474
|
-
relative_file = self.sub(/(.*\/)doc\//, '\1').sub(lib_dir + "/",'')
|
475
|
-
file = File.join(lib_dir, relative_file)
|
476
|
-
|
477
|
-
if not File.exist?(file)
|
478
|
-
file= Dir.glob(file.sub(/\.[^\.\/]+$/, '.*')).first
|
479
|
-
end
|
480
|
-
|
481
|
-
Path.setup file, @pkgdir, @resource
|
482
|
-
else
|
483
|
-
relative_file = self.sub(/^doc\//, '\1')
|
484
|
-
|
485
|
-
if not File.exist?(relative_file)
|
486
|
-
relative_file = Dir.glob(relative_file.sub(/\.[^\.\/]+$/, '.*')).first
|
487
|
-
end
|
488
|
-
|
489
|
-
Path.setup relative_file , @pkgdir, @resource
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
def clean_annotations
|
494
|
-
"" << self.to_s
|
495
|
-
end
|
496
|
-
|
497
|
-
end
|
1
|
+
require 'rbbt/refactor'
|
2
|
+
Rbbt.require_instead 'scout/path'
|
3
|
+
require_relative 'path/refactor'
|
4
|
+
#require 'rbbt/resource/util'
|
5
|
+
#require 'rbbt/util/misc/indiferent_hash'
|
6
|
+
#require 'yaml'
|
7
|
+
#
|
8
|
+
#module Path
|
9
|
+
# attr_accessor :resource, :pkgdir, :original, :search_paths, :search_order, :libdir, :where
|
10
|
+
#
|
11
|
+
# def self.setup(string, pkgdir = nil, resource = nil, search_paths = nil, search_order = nil, libdir = nil)
|
12
|
+
# return string if string.nil?
|
13
|
+
# string = string.dup if string.frozen?
|
14
|
+
# string.extend Path
|
15
|
+
# string.pkgdir = pkgdir || 'rbbt'
|
16
|
+
# string.resource = resource
|
17
|
+
# string.search_paths = search_paths
|
18
|
+
# string.search_order = search_order
|
19
|
+
# string.libdir = libdir || Path.caller_lib_dir
|
20
|
+
# string
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def search_order
|
24
|
+
# @search_order ||= STANDARD_SEARCH.dup.uniq
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# def search_paths
|
28
|
+
# @search_paths ||= SEARCH_PATHS.dup
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def add_search_path(name, dir)
|
32
|
+
# search_paths[name.to_sym] = dir
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def prepend_search_path(name, dir)
|
36
|
+
# add_search_path(name, dir)
|
37
|
+
# search_order.unshift(name.to_sym)
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# def append_search_path(name, dir)
|
41
|
+
# add_search_path(name, dir)
|
42
|
+
# search_order.push(name.to_sym)
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# def sub(*args)
|
46
|
+
# self.annotate super(*args)
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# def annotate(name)
|
50
|
+
# name = name.to_s
|
51
|
+
# name = Path.setup name, @pkgdir, @resource, @search_paths, @search_order, @libdir
|
52
|
+
# name
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def join(name)
|
56
|
+
# raise "Invalid path: #{ self }" if self.nil?
|
57
|
+
# new = if self.empty?
|
58
|
+
# self.annotate name.to_s.dup.chomp
|
59
|
+
# else
|
60
|
+
# self.annotate File.join(self, name.to_s.chomp)
|
61
|
+
# end
|
62
|
+
# new.original = File.join(self.original, name.to_s.chomp) if self.original
|
63
|
+
# new
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def dirname
|
67
|
+
# Path.setup File.dirname(self), @pkgdir, @resource
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# def directory?
|
71
|
+
# return nil unless self.exists?
|
72
|
+
# File.directory? self.find
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# def glob(pattern = '*')
|
76
|
+
# if self.include? "*"
|
77
|
+
# self.glob_all pattern
|
78
|
+
# else
|
79
|
+
# return [] unless self.exists?
|
80
|
+
# found = self.find
|
81
|
+
# exp = File.join(found, pattern)
|
82
|
+
# paths = Dir.glob(exp).collect{|f| self.annotate(f) }
|
83
|
+
#
|
84
|
+
# paths.each do |p|
|
85
|
+
# p.original = File.join(found.original, p.sub(/^#{found}/, ''))
|
86
|
+
# end if found.original
|
87
|
+
#
|
88
|
+
# paths
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# def glob_all(pattern = nil, caller_lib = nil, search_paths = nil)
|
93
|
+
# search_paths ||= @search_paths || SEARCH_PATHS
|
94
|
+
# search_paths = search_paths.dup
|
95
|
+
#
|
96
|
+
# location_paths = {}
|
97
|
+
# search_paths.keys.collect do |where|
|
98
|
+
# found = find(where, Path.caller_lib_dir, search_paths)
|
99
|
+
# paths = pattern ? Dir.glob(File.join(found, pattern)) : Dir.glob(found)
|
100
|
+
#
|
101
|
+
# paths = paths.collect{|p| self.annotate p }
|
102
|
+
#
|
103
|
+
# paths = paths.each do |p|
|
104
|
+
# p.original = File.join(found.original, p.sub(/^#{found}/, ''))
|
105
|
+
# p.where = where
|
106
|
+
# end if found.original and pattern
|
107
|
+
#
|
108
|
+
# location_paths[where] = paths
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# #location_paths.values.compact.flatten.collect{|file| File.expand_path(file) }.uniq.collect{|path| Path.setup(path, self.resource, self.pkgdir)}
|
112
|
+
# location_paths.values.compact.flatten.uniq
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# def [](name, orig = false)
|
116
|
+
# return super(name) if orig
|
117
|
+
# join name
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# def byte(pos)
|
121
|
+
# send(:[], pos, true)
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# def method_missing(name, prev = nil, *args, &block)
|
125
|
+
# if block_given?
|
126
|
+
# super name, prev, *args, &block
|
127
|
+
# else
|
128
|
+
# # Fix problem with ruby 1.9 calling methods by its own initiative. ARG
|
129
|
+
# super(name, prev, *args) if name.to_s =~ /^to_/
|
130
|
+
# if prev.nil?
|
131
|
+
# join name
|
132
|
+
# else
|
133
|
+
# join(prev).join(name)
|
134
|
+
# end
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# SEARCH_PATHS = IndiferentHash.setup({
|
139
|
+
# :current => File.join("{PWD}", "{TOPLEVEL}", "{SUBPATH}"),
|
140
|
+
# :user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
|
141
|
+
# :global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
142
|
+
# :local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
143
|
+
# :fast => File.join('/fast', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
144
|
+
# :cache => File.join('/cache', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
145
|
+
# :bulk => File.join('/bulk', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
|
146
|
+
# :lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
|
147
|
+
# :base => File.join(caller_lib_dir(__FILE__), "{TOPLEVEL}", "{SUBPATH}"),
|
148
|
+
# :default => :user
|
149
|
+
# })
|
150
|
+
#
|
151
|
+
# STANDARD_SEARCH = %w(current workflow user local global lib fast cache bulk)
|
152
|
+
#
|
153
|
+
# search_path_file = File.join(ENV['HOME'], '.rbbt/etc/search_paths')
|
154
|
+
# if File.exist?(search_path_file)
|
155
|
+
# begin
|
156
|
+
# Misc.load_yaml(search_path_file).each do |where, location|
|
157
|
+
# SEARCH_PATHS[where.to_sym] = location
|
158
|
+
# end
|
159
|
+
# rescue
|
160
|
+
# Log.error "Error loading search_paths from #{search_path_file}: " << $!.message
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# def find(where = nil, caller_lib = nil, paths = nil)
|
165
|
+
#
|
166
|
+
# if located?
|
167
|
+
# self.original ||= self
|
168
|
+
# return self
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# if where == :all || where == 'all'
|
172
|
+
# return find_all(caller_lib, paths)
|
173
|
+
# end
|
174
|
+
#
|
175
|
+
# @path ||= {}
|
176
|
+
# rsearch_paths = (resource and resource.respond_to?(:search_paths)) ? resource.search_paths : nil
|
177
|
+
# key = [where, caller_lib, rsearch_paths, paths].inspect
|
178
|
+
# self.sub!('~/', Etc.getpwuid.dir + '/') if self.include? "~"
|
179
|
+
#
|
180
|
+
# return @path[key] if @path[key]
|
181
|
+
#
|
182
|
+
# @path[key] ||= begin
|
183
|
+
# paths = [paths, rsearch_paths, self.search_paths, SEARCH_PATHS].reverse.compact.inject({}){|acc,h| acc.merge! h; acc }
|
184
|
+
# where = paths[:default] if where == :default
|
185
|
+
# if self.match(/(.*?)\/(.*)/)
|
186
|
+
# toplevel, subpath = self.match(/(.*?)\/(.*)/).values_at 1, 2
|
187
|
+
# else
|
188
|
+
# toplevel, subpath = "{REMOVE}", self
|
189
|
+
# end
|
190
|
+
#
|
191
|
+
# path = nil
|
192
|
+
# search_order = self.search_order || []
|
193
|
+
# res = nil
|
194
|
+
# if where.nil?
|
195
|
+
#
|
196
|
+
# (STANDARD_SEARCH - search_order).each do |w|
|
197
|
+
# w = w.to_sym
|
198
|
+
# break if res
|
199
|
+
# next unless paths.include? w
|
200
|
+
# path = find(w, caller_lib, paths)
|
201
|
+
# res = path if File.exist? path
|
202
|
+
# end
|
203
|
+
#
|
204
|
+
# search_order.each do |w|
|
205
|
+
# w = w.to_sym
|
206
|
+
# next if res
|
207
|
+
# next unless paths.include? w
|
208
|
+
# path = find(w, caller_lib, paths)
|
209
|
+
# res = path if File.exist?(path)
|
210
|
+
# end if res.nil?
|
211
|
+
#
|
212
|
+
# (paths.keys - STANDARD_SEARCH - search_order).each do |w|
|
213
|
+
# w = w.to_sym
|
214
|
+
# next if res
|
215
|
+
# next unless paths.include? w
|
216
|
+
# path = find(w, caller_lib, paths)
|
217
|
+
# res = path if File.exist? path
|
218
|
+
# end if res.nil?
|
219
|
+
#
|
220
|
+
# if paths.include? :default
|
221
|
+
# res = find((paths[:default] || :user), caller_lib, paths)
|
222
|
+
# else
|
223
|
+
# raise "Path '#{ path }' not found, and no default specified in search paths: #{paths.inspect}"
|
224
|
+
# end if res.nil?
|
225
|
+
#
|
226
|
+
# else
|
227
|
+
# where = where.to_sym
|
228
|
+
#
|
229
|
+
# if paths.include? where
|
230
|
+
# path = paths[where]
|
231
|
+
# elsif where.to_s.include?("/")
|
232
|
+
# path = where.to_s
|
233
|
+
# else
|
234
|
+
# raise "Did not recognize the 'where' tag: #{where}. Options: #{paths.keys}" unless paths.include? where
|
235
|
+
# end
|
236
|
+
#
|
237
|
+
# if where == :lib
|
238
|
+
# libdir = @libdir || Path.caller_lib_dir(caller_lib) || "NOLIBDIR"
|
239
|
+
# else
|
240
|
+
# libdir = "NOLIBDIR"
|
241
|
+
# end
|
242
|
+
#
|
243
|
+
# pwd = FileUtils.pwd
|
244
|
+
# path = File.join(path, "{PATH}") unless path.include? "PATH}" or path.include? "{BASENAME}"
|
245
|
+
# path = path.
|
246
|
+
# sub('{PKGDIR}', pkgdir).
|
247
|
+
# sub('{PWD}', pwd).
|
248
|
+
# sub('{TOPLEVEL}', toplevel).
|
249
|
+
# sub('{SUBPATH}', subpath).
|
250
|
+
# sub('{BASENAME}', File.basename(self)).
|
251
|
+
# sub('{PATH}', self).
|
252
|
+
# sub('{LIBDIR}', libdir).
|
253
|
+
# sub('{RESOURCE}', resource.to_s).
|
254
|
+
# sub('{REMOVE}/', '').
|
255
|
+
# sub('{REMOVE}', '')
|
256
|
+
#
|
257
|
+
# path = path + '.gz' if File.exist?(path + '.gz')
|
258
|
+
# path = path + '.bgz' if File.exist?(path + '.bgz')
|
259
|
+
#
|
260
|
+
# self.annotate path
|
261
|
+
#
|
262
|
+
# res = path
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# res.original = self.original || self
|
266
|
+
# res.where = where
|
267
|
+
#
|
268
|
+
# res
|
269
|
+
# end
|
270
|
+
# @path[key]
|
271
|
+
# end
|
272
|
+
#
|
273
|
+
# def find_all(caller_lib = nil, search_paths = nil)
|
274
|
+
# search_paths ||= @search_paths || SEARCH_PATHS
|
275
|
+
# search_paths = search_paths.dup
|
276
|
+
#
|
277
|
+
# search_paths.keys.
|
278
|
+
# collect{|where| find(where, Path.caller_lib_dir, search_paths) }.
|
279
|
+
# compact.select{|file| file.exists? }.uniq
|
280
|
+
# end
|
281
|
+
#
|
282
|
+
# #{{{ Methods
|
283
|
+
#
|
284
|
+
# def in_dir?(dir)
|
285
|
+
# ! ! File.expand_path(self).match(/^#{Regexp.quote dir}/)
|
286
|
+
# end
|
287
|
+
#
|
288
|
+
# def to_s
|
289
|
+
# self.find
|
290
|
+
# end
|
291
|
+
#
|
292
|
+
# def filename
|
293
|
+
# self.find
|
294
|
+
# end
|
295
|
+
#
|
296
|
+
# def _exists?
|
297
|
+
# Open.exists? self.find.to_s
|
298
|
+
# end
|
299
|
+
#
|
300
|
+
# def exists?
|
301
|
+
# begin
|
302
|
+
# self.produce
|
303
|
+
# _exists?
|
304
|
+
# rescue Exception
|
305
|
+
# false
|
306
|
+
# end
|
307
|
+
# end
|
308
|
+
#
|
309
|
+
#
|
310
|
+
# def to_s
|
311
|
+
# "" + self
|
312
|
+
# end
|
313
|
+
#
|
314
|
+
# def clean_annotations
|
315
|
+
# "" << self.to_s
|
316
|
+
# end
|
317
|
+
#end
|