rbbt-util 5.44.1 → 6.0.4

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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/bin/rbbt +67 -90
  4. data/bin/rbbt_exec.rb +2 -2
  5. data/etc/app.d/base.rb +2 -2
  6. data/etc/app.d/semaphores.rb +3 -3
  7. data/lib/rbbt/annotations/annotated_array.rb +207 -207
  8. data/lib/rbbt/annotations/refactor.rb +27 -0
  9. data/lib/rbbt/annotations/util.rb +282 -282
  10. data/lib/rbbt/annotations.rb +343 -320
  11. data/lib/rbbt/association/database.rb +200 -225
  12. data/lib/rbbt/association/index.rb +294 -291
  13. data/lib/rbbt/association/item.rb +227 -227
  14. data/lib/rbbt/association/open.rb +35 -34
  15. data/lib/rbbt/association/util.rb +0 -169
  16. data/lib/rbbt/association.rb +2 -4
  17. data/lib/rbbt/entity/identifiers.rb +119 -118
  18. data/lib/rbbt/entity/refactor.rb +12 -0
  19. data/lib/rbbt/entity.rb +319 -315
  20. data/lib/rbbt/hpc/batch.rb +72 -53
  21. data/lib/rbbt/hpc/lsf.rb +2 -2
  22. data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
  23. data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
  24. data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
  25. data/lib/rbbt/hpc/orchestrate.rb +19 -13
  26. data/lib/rbbt/hpc/slurm.rb +18 -18
  27. data/lib/rbbt/knowledge_base/entity.rb +13 -5
  28. data/lib/rbbt/knowledge_base/query.rb +2 -2
  29. data/lib/rbbt/knowledge_base/registry.rb +32 -31
  30. data/lib/rbbt/knowledge_base/traverse.rb +1 -1
  31. data/lib/rbbt/knowledge_base.rb +1 -1
  32. data/lib/rbbt/monitor.rb +36 -25
  33. data/lib/rbbt/persist/refactor.rb +166 -0
  34. data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
  35. data/lib/rbbt/persist/tsv.rb +187 -185
  36. data/lib/rbbt/persist.rb +556 -551
  37. data/lib/rbbt/refactor.rb +20 -0
  38. data/lib/rbbt/resource/path/refactor.rb +178 -0
  39. data/lib/rbbt/resource/path.rb +317 -497
  40. data/lib/rbbt/resource/util.rb +0 -48
  41. data/lib/rbbt/resource.rb +3 -390
  42. data/lib/rbbt/tsv/accessor.rb +2 -838
  43. data/lib/rbbt/tsv/attach.rb +303 -299
  44. data/lib/rbbt/tsv/change_id.rb +244 -245
  45. data/lib/rbbt/tsv/csv.rb +87 -85
  46. data/lib/rbbt/tsv/dumper.rb +2 -100
  47. data/lib/rbbt/tsv/excel.rb +26 -24
  48. data/lib/rbbt/tsv/field_index.rb +4 -1
  49. data/lib/rbbt/tsv/filter.rb +3 -2
  50. data/lib/rbbt/tsv/index.rb +2 -284
  51. data/lib/rbbt/tsv/manipulate.rb +750 -747
  52. data/lib/rbbt/tsv/marshal.rb +3 -3
  53. data/lib/rbbt/tsv/matrix.rb +2 -2
  54. data/lib/rbbt/tsv/parallel/through.rb +2 -1
  55. data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
  56. data/lib/rbbt/tsv/parser.rb +678 -678
  57. data/lib/rbbt/tsv/refactor.rb +195 -0
  58. data/lib/rbbt/tsv/stream.rb +253 -251
  59. data/lib/rbbt/tsv/util.rb +420 -420
  60. data/lib/rbbt/tsv.rb +210 -208
  61. data/lib/rbbt/util/R/eval.rb +4 -4
  62. data/lib/rbbt/util/R/plot.rb +62 -166
  63. data/lib/rbbt/util/R.rb +21 -18
  64. data/lib/rbbt/util/cmd.rb +2 -318
  65. data/lib/rbbt/util/color.rb +269 -269
  66. data/lib/rbbt/util/colorize.rb +89 -89
  67. data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
  68. data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
  69. data/lib/rbbt/util/concurrency/processes.rb +389 -386
  70. data/lib/rbbt/util/config.rb +169 -167
  71. data/lib/rbbt/util/filecache.rb +1 -1
  72. data/lib/rbbt/util/iruby.rb +20 -0
  73. data/lib/rbbt/util/log/progress/report.rb +241 -241
  74. data/lib/rbbt/util/log/progress/util.rb +99 -99
  75. data/lib/rbbt/util/log/progress.rb +102 -102
  76. data/lib/rbbt/util/log/refactor.rb +49 -0
  77. data/lib/rbbt/util/log.rb +486 -532
  78. data/lib/rbbt/util/migrate.rb +2 -2
  79. data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
  80. data/lib/rbbt/util/misc/development.rb +12 -11
  81. data/lib/rbbt/util/misc/exceptions.rb +117 -112
  82. data/lib/rbbt/util/misc/format.rb +2 -230
  83. data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
  84. data/lib/rbbt/util/misc/inspect.rb +2 -476
  85. data/lib/rbbt/util/misc/lock.rb +109 -106
  86. data/lib/rbbt/util/misc/omics.rb +9 -1
  87. data/lib/rbbt/util/misc/pipes.rb +765 -793
  88. data/lib/rbbt/util/misc/refactor.rb +20 -0
  89. data/lib/rbbt/util/misc/ssw.rb +27 -17
  90. data/lib/rbbt/util/misc/system.rb +92 -105
  91. data/lib/rbbt/util/misc.rb +39 -20
  92. data/lib/rbbt/util/named_array/refactor.rb +4 -0
  93. data/lib/rbbt/util/named_array.rb +3 -220
  94. data/lib/rbbt/util/open/refactor.rb +7 -0
  95. data/lib/rbbt/util/open.rb +3 -857
  96. data/lib/rbbt/util/procpath.rb +6 -6
  97. data/lib/rbbt/util/python/paths.rb +27 -0
  98. data/lib/rbbt/util/python/run.rb +115 -0
  99. data/lib/rbbt/util/python/script.rb +110 -0
  100. data/lib/rbbt/util/python/util.rb +3 -3
  101. data/lib/rbbt/util/python.rb +22 -81
  102. data/lib/rbbt/util/semaphore.rb +152 -148
  103. data/lib/rbbt/util/simpleopt.rb +9 -8
  104. data/lib/rbbt/util/ssh/refactor.rb +19 -0
  105. data/lib/rbbt/util/ssh.rb +122 -118
  106. data/lib/rbbt/util/tar.rb +117 -115
  107. data/lib/rbbt/util/tmpfile.rb +69 -67
  108. data/lib/rbbt/util/version.rb +2 -0
  109. data/lib/rbbt/workflow/refactor/entity.rb +11 -0
  110. data/lib/rbbt/workflow/refactor/export.rb +66 -0
  111. data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
  112. data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
  113. data/lib/rbbt/workflow/refactor/task_info.rb +66 -0
  114. data/lib/rbbt/workflow/refactor.rb +150 -0
  115. data/lib/rbbt/workflow/remote_workflow/driver/rest.rb +1 -2
  116. data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
  117. data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
  118. data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
  119. data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
  120. data/lib/rbbt/workflow/remote_workflow.rb +6 -1
  121. data/lib/rbbt/workflow/step/run.rb +766 -766
  122. data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
  123. data/lib/rbbt/workflow/step.rb +2 -362
  124. data/lib/rbbt/workflow/task.rb +118 -118
  125. data/lib/rbbt/workflow/usage.rb +289 -287
  126. data/lib/rbbt/workflow/util/archive.rb +6 -5
  127. data/lib/rbbt/workflow/util/data.rb +1 -1
  128. data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
  129. data/lib/rbbt/workflow/util/trace.rb +79 -44
  130. data/lib/rbbt/workflow.rb +4 -882
  131. data/lib/rbbt-util.rb +21 -13
  132. data/lib/rbbt.rb +16 -3
  133. data/python/rbbt/__init__.py +96 -4
  134. data/python/rbbt/workflow/remote.py +104 -0
  135. data/python/rbbt/workflow.py +64 -0
  136. data/python/test.py +10 -0
  137. data/share/Rlib/plot.R +37 -37
  138. data/share/Rlib/svg.R +22 -5
  139. data/share/install/software/lib/install_helpers +1 -1
  140. data/share/rbbt_commands/hpc/list +2 -3
  141. data/share/rbbt_commands/hpc/orchestrate +4 -4
  142. data/share/rbbt_commands/hpc/tail +2 -0
  143. data/share/rbbt_commands/hpc/task +10 -7
  144. data/share/rbbt_commands/lsf/list +2 -3
  145. data/share/rbbt_commands/lsf/orchestrate +4 -4
  146. data/share/rbbt_commands/lsf/tail +2 -0
  147. data/share/rbbt_commands/lsf/task +10 -7
  148. data/share/rbbt_commands/migrate +1 -1
  149. data/share/rbbt_commands/pbs/list +2 -3
  150. data/share/rbbt_commands/pbs/orchestrate +4 -4
  151. data/share/rbbt_commands/pbs/tail +2 -0
  152. data/share/rbbt_commands/pbs/task +10 -7
  153. data/share/rbbt_commands/resource/produce +8 -1
  154. data/share/rbbt_commands/slurm/list +2 -3
  155. data/share/rbbt_commands/slurm/orchestrate +4 -4
  156. data/share/rbbt_commands/slurm/tail +2 -0
  157. data/share/rbbt_commands/slurm/task +10 -7
  158. data/share/rbbt_commands/system/clean +5 -5
  159. data/share/rbbt_commands/system/status +5 -5
  160. data/share/rbbt_commands/tsv/get +2 -3
  161. data/share/rbbt_commands/tsv/info +10 -13
  162. data/share/rbbt_commands/tsv/keys +18 -14
  163. data/share/rbbt_commands/tsv/slice +2 -2
  164. data/share/rbbt_commands/tsv/transpose +6 -2
  165. data/share/rbbt_commands/workflow/info +20 -24
  166. data/share/rbbt_commands/workflow/list +1 -1
  167. data/share/rbbt_commands/workflow/prov +20 -13
  168. data/share/rbbt_commands/workflow/retry +43 -0
  169. data/share/rbbt_commands/workflow/server +12 -2
  170. data/share/rbbt_commands/workflow/task +80 -73
  171. data/share/rbbt_commands/workflow/write_info +26 -9
  172. data/share/software/opt/ssw/ssw.c +861 -0
  173. data/share/software/opt/ssw/ssw.h +130 -0
  174. data/share/workflow_config.ru +3 -3
  175. metadata +45 -6
@@ -1,497 +1,317 @@
1
- require 'rbbt/resource/util'
2
- require 'rbbt/util/misc/indiferent_hash'
3
- require 'yaml'
4
-
5
- module Path
6
- attr_accessor :resource, :pkgdir, :original, :search_paths, :search_order, :libdir, :where
7
-
8
- def self.setup(string, pkgdir = nil, resource = nil, search_paths = nil, search_order = nil, libdir = nil)
9
- return string if string.nil?
10
- string = string.dup if string.frozen?
11
- string.extend Path
12
- string.pkgdir = pkgdir || 'rbbt'
13
- string.resource = resource
14
- string.search_paths = search_paths
15
- string.search_order = search_order
16
- string.libdir = libdir || Path.caller_lib_dir
17
- string
18
- end
19
-
20
- def search_order
21
- @search_order ||= STANDARD_SEARCH.dup.uniq
22
- end
23
-
24
- def search_paths
25
- @search_paths ||= SEARCH_PATHS.dup
26
- end
27
-
28
- def add_search_path(name, dir)
29
- search_paths[name.to_sym] = dir
30
- end
31
-
32
- def prepend_search_path(name, dir)
33
- add_search_path(name, dir)
34
- search_order.unshift(name.to_sym)
35
- end
36
-
37
- def append_search_path(name, dir)
38
- add_search_path(name, dir)
39
- search_order.push(name.to_sym)
40
- end
41
-
42
- def sub(*args)
43
- self.annotate super(*args)
44
- end
45
-
46
- def annotate(name)
47
- name = name.to_s
48
- name = Path.setup name, @pkgdir, @resource, @search_paths, @search_order, @libdir
49
- name
50
- end
51
-
52
- def join(name)
53
- raise "Invalid path: #{ self }" if self.nil?
54
- new = if self.empty?
55
- self.annotate name.to_s.dup.chomp
56
- else
57
- self.annotate File.join(self, name.to_s.chomp)
58
- end
59
- new.original = File.join(self.original, name.to_s.chomp) if self.original
60
- new
61
- end
62
-
63
- def dirname
64
- Path.setup File.dirname(self), @pkgdir, @resource
65
- end
66
-
67
- def directory?
68
- return nil unless self.exists?
69
- File.directory? self.find
70
- end
71
-
72
- def glob(pattern = '*')
73
- if self.include? "*"
74
- self.glob_all pattern
75
- else
76
- return [] unless self.exists?
77
- found = self.find
78
- exp = File.join(found, pattern)
79
- paths = Dir.glob(exp).collect{|f| self.annotate(f) }
80
-
81
- paths.each do |p|
82
- p.original = File.join(found.original, p.sub(/^#{found}/, ''))
83
- end if found.original
84
-
85
- paths
86
- end
87
- end
88
-
89
- def glob_all(pattern = nil, caller_lib = nil, search_paths = nil)
90
- search_paths ||= @search_paths || SEARCH_PATHS
91
- search_paths = search_paths.dup
92
-
93
- location_paths = {}
94
- search_paths.keys.collect do |where|
95
- found = find(where, Path.caller_lib_dir, search_paths)
96
- paths = pattern ? Dir.glob(File.join(found, pattern)) : Dir.glob(found)
97
-
98
- paths = paths.collect{|p| self.annotate p }
99
-
100
- paths = paths.each do |p|
101
- p.original = File.join(found.original, p.sub(/^#{found}/, ''))
102
- p.where = where
103
- end if found.original and pattern
104
-
105
- location_paths[where] = paths
106
- end
107
-
108
- #location_paths.values.compact.flatten.collect{|file| File.expand_path(file) }.uniq.collect{|path| Path.setup(path, self.resource, self.pkgdir)}
109
- location_paths.values.compact.flatten.uniq
110
- end
111
-
112
- def [](name, orig = false)
113
- return super(name) if orig
114
- join name
115
- end
116
-
117
- def byte(pos)
118
- send(:[], pos, true)
119
- end
120
-
121
- def method_missing(name, prev = nil, *args, &block)
122
- if block_given?
123
- super name, prev, *args, &block
124
- else
125
- # Fix problem with ruby 1.9 calling methods by its own initiative. ARG
126
- super(name, prev, *args) if name.to_s =~ /^to_/
127
- if prev.nil?
128
- join name
129
- else
130
- join(prev).join(name)
131
- end
132
- end
133
- end
134
-
135
- SEARCH_PATHS = IndiferentHash.setup({
136
- :current => File.join("{PWD}", "{TOPLEVEL}", "{SUBPATH}"),
137
- :user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
138
- :global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
139
- :local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
140
- :fast => File.join('/fast', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
141
- :cache => File.join('/cache', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
142
- :bulk => File.join('/bulk', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
143
- :lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
144
- :base => File.join(caller_lib_dir(__FILE__), "{TOPLEVEL}", "{SUBPATH}"),
145
- :default => :user
146
- })
147
-
148
- STANDARD_SEARCH = %w(current workflow user local global lib fast cache bulk)
149
-
150
- search_path_file = File.join(ENV['HOME'], '.rbbt/etc/search_paths')
151
- if File.exist?(search_path_file)
152
- begin
153
- Misc.load_yaml(search_path_file).each do |where, location|
154
- SEARCH_PATHS[where.to_sym] = location
155
- end
156
- rescue
157
- Log.error "Error loading search_paths from #{search_path_file}: " << $!.message
158
- end
159
- end
160
-
161
- def find(where = nil, caller_lib = nil, paths = nil)
162
-
163
- if located?
164
- path = self
165
- path = path + '.gz' if File.exist?(path + '.gz')
166
- path = path + '.bgz' if File.exist?(path + '.bgz')
167
- self.annotate(path)
168
-
169
- path.original = self
170
- return path
171
- end
172
-
173
- if where == :all || where == 'all'
174
- return find_all(caller_lib, paths)
175
- end
176
-
177
- @path ||= {}
178
- rsearch_paths = (resource and resource.respond_to?(:search_paths)) ? resource.search_paths : nil
179
- key = [where, caller_lib, rsearch_paths, paths].inspect
180
- self.sub!('~/', Etc.getpwuid.dir + '/') if self.include? "~"
181
-
182
- return @path[key] if @path[key]
183
-
184
- @path[key] ||= begin
185
- paths = [paths, rsearch_paths, self.search_paths, SEARCH_PATHS].reverse.compact.inject({}){|acc,h| acc.merge! h; acc }
186
- where = paths[:default] if where == :default
187
- if self.match(/(.*?)\/(.*)/)
188
- toplevel, subpath = self.match(/(.*?)\/(.*)/).values_at 1, 2
189
- else
190
- toplevel, subpath = "{REMOVE}", self
191
- end
192
-
193
- path = nil
194
- search_order = self.search_order || []
195
- res = nil
196
- if where.nil?
197
-
198
- (STANDARD_SEARCH - search_order).each do |w|
199
- w = w.to_sym
200
- break if res
201
- next unless paths.include? w
202
- path = find(w, caller_lib, paths)
203
- res = path if File.exist? path
204
- end
205
-
206
- search_order.each do |w|
207
- w = w.to_sym
208
- next if res
209
- next unless paths.include? w
210
- path = find(w, caller_lib, paths)
211
- res = path if File.exist?(path)
212
- end if res.nil?
213
-
214
- (paths.keys - STANDARD_SEARCH - search_order).each do |w|
215
- w = w.to_sym
216
- next if res
217
- next unless paths.include? w
218
- path = find(w, caller_lib, paths)
219
- res = path if File.exist? path
220
- end if res.nil?
221
-
222
- if paths.include? :default
223
- res = find((paths[:default] || :user), caller_lib, paths)
224
- else
225
- raise "Path '#{ path }' not found, and no default specified in search paths: #{paths.inspect}"
226
- end if res.nil?
227
-
228
- else
229
- where = where.to_sym
230
-
231
- if paths.include? where
232
- path = paths[where]
233
- elsif where.to_s.include?("/")
234
- path = where.to_s
235
- else
236
- raise "Did not recognize the 'where' tag: #{where}. Options: #{paths.keys}" unless paths.include? where
237
- end
238
-
239
- if where == :lib
240
- libdir = @libdir || Path.caller_lib_dir(caller_lib) || "NOLIBDIR"
241
- else
242
- libdir = "NOLIBDIR"
243
- end
244
-
245
- pwd = FileUtils.pwd
246
- path = File.join(path, "{PATH}") unless path.include? "PATH}" or path.include? "{BASENAME}"
247
- path = path.
248
- sub('{PKGDIR}', pkgdir).
249
- sub('{PWD}', pwd).
250
- sub('{TOPLEVEL}', toplevel).
251
- sub('{SUBPATH}', subpath).
252
- sub('{BASENAME}', File.basename(self)).
253
- sub('{PATH}', self).
254
- sub('{LIBDIR}', libdir).
255
- sub('{RESOURCE}', resource.to_s).
256
- sub('{REMOVE}/', '').
257
- sub('{REMOVE}', '')
258
-
259
- path = path + '.gz' if File.exist?(path + '.gz')
260
- path = path + '.bgz' if File.exist?(path + '.bgz')
261
-
262
- self.annotate path
263
-
264
- res = path
265
- end
266
-
267
- res.original = self.original || self
268
- res.where = where
269
-
270
- res
271
- end
272
- @path[key]
273
- end
274
-
275
- def find_all(caller_lib = nil, search_paths = nil)
276
- search_paths ||= @search_paths || SEARCH_PATHS
277
- search_paths = search_paths.dup
278
-
279
- search_paths.keys.
280
- collect{|where| find(where, Path.caller_lib_dir, search_paths) }.
281
- compact.select{|file| file.exists? }.uniq
282
- end
283
-
284
- #{{{ Methods
285
-
286
- def in_dir?(dir)
287
- ! ! File.expand_path(self).match(/^#{Regexp.quote dir}/)
288
- end
289
-
290
- def to_s
291
- self.find
292
- end
293
-
294
- def filename
295
- self.find
296
- end
297
-
298
- def _exists?
299
- Open.exists? self.find.to_s
300
- end
301
-
302
- def exists?
303
- begin
304
- self.produce
305
- _exists?
306
- rescue Exception
307
- false
308
- end
309
- end
310
-
311
- def produce(force = false)
312
- return self if _exists? and not force
313
-
314
- raise "No resource defined to produce file: #{ self }" if resource.nil?
315
-
316
- resource.produce self, force if Resource === resource
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