rbbt-util 5.6.1 → 5.6.2
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.
- checksums.yaml +4 -4
- data/lib/rbbt/resource/path.rb +3 -1
- data/lib/rbbt/tsv/accessor.rb +23 -0
- data/lib/rbbt/tsv/parser.rb +6 -3
- data/lib/rbbt/util/filecache.rb +1 -8
- data/lib/rbbt/util/misc.rb +1 -1
- data/lib/rbbt/util/open.rb +18 -17
- data/share/rbbt_commands/tsv/info +3 -0
- data/share/rbbt_commands/tsv/unzip +25 -0
- data/share/rbbt_commands/tsv/values +25 -0
- data/share/rbbt_commands/workflow/task +9 -3
- data/test/rbbt/util/test_open.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7529a3f61ee17378eae98591577b9a39f9a64fd8
|
4
|
+
data.tar.gz: 21485c3f12ae2823f13e7a7f098d242dac15c0c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73f9e121eb79a0c91b92dd5474f04508771230d8451178cf348d6fb3f920d89518491106c7a051f95bd28d94bb59884aa20491b3d8dd1839786603eecb2efc41
|
7
|
+
data.tar.gz: 39c04b2dff5c9fd798c2cb45cb432395d627b60f1ff2bf9483e5602035ab8e36ccd5847e75b03eec3c0cd4b61ee0a2c4c5bdb804d2776f031708babee6303289
|
data/lib/rbbt/resource/path.rb
CHANGED
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -547,5 +547,28 @@ Example:
|
|
547
547
|
ENTRY_KEYS.each{|entry| new.delete entry}
|
548
548
|
new
|
549
549
|
end
|
550
|
+
|
551
|
+
def unzip(field = 0)
|
552
|
+
new = {}
|
553
|
+
field_pos = self.identify_field field
|
554
|
+
|
555
|
+
self.through do |key,values|
|
556
|
+
field_values = values.delete_at field_pos
|
557
|
+
zipped = values.zip_fields
|
558
|
+
field_values.zip(zipped) do |value, *rest|
|
559
|
+
new[[key,value]*":"] = Misc.zip_fields(rest)
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
self.annotate new
|
564
|
+
new.type = :list
|
565
|
+
|
566
|
+
new.key_field = [self.key_field, self.fields[field_pos]] * ":"
|
567
|
+
new_fields = self.fields.dup
|
568
|
+
new_fields.delete_at field_pos
|
569
|
+
new.fields = new_fields
|
570
|
+
|
571
|
+
new
|
572
|
+
end
|
550
573
|
end
|
551
574
|
|
data/lib/rbbt/tsv/parser.rb
CHANGED
@@ -25,7 +25,7 @@ module TSV
|
|
25
25
|
|
26
26
|
if line and line =~ /^#{@header_hash}: (.*)/
|
27
27
|
options = Misc.string2hash $1
|
28
|
-
line = stream.gets
|
28
|
+
line = Misc.fixutf8 stream.gets
|
29
29
|
end
|
30
30
|
|
31
31
|
# Determine separator
|
@@ -34,14 +34,17 @@ module TSV
|
|
34
34
|
|
35
35
|
# Process fields line
|
36
36
|
|
37
|
-
while line and Misc.fixutf8(line) =~ /^#{@header_hash}/
|
37
|
+
while line and Misc.fixutf8(line) =~ /^#{@header_hash}/
|
38
38
|
line.chomp!
|
39
39
|
@fields = line.split(@sep)
|
40
40
|
@key_field = @fields.shift
|
41
41
|
@key_field = @key_field[(0 + header_hash.length)..-1] # Remove initial hash character
|
42
|
-
|
42
|
+
|
43
|
+
line = @header_hash != "" ? Misc.fixutf8(stream.gets) : nil
|
43
44
|
end
|
44
45
|
|
46
|
+
line ||= stream.gets
|
47
|
+
|
45
48
|
@first_line = line
|
46
49
|
|
47
50
|
options
|
data/lib/rbbt/util/filecache.rb
CHANGED
@@ -21,7 +21,7 @@ module FileCache
|
|
21
21
|
filename.match(/(.+)\.(.+)/)
|
22
22
|
|
23
23
|
base = filename.sub(/\..+/,'')
|
24
|
-
dirs = base.scan(/./).values_at(0,1,2,3,4).compact
|
24
|
+
dirs = base.scan(/./).reverse.values_at(0,1,2,3,4).compact
|
25
25
|
|
26
26
|
File.join(File.join(CACHEDIR, *dirs), filename)
|
27
27
|
end
|
@@ -75,13 +75,6 @@ module FileCache
|
|
75
75
|
filename = pattern ? pattern.sub("{ID}", id.to_s) : id.to_s
|
76
76
|
path = FileCache.path(filename)
|
77
77
|
Open.write(path, content)
|
78
|
-
result_files[id] = content
|
79
|
-
end
|
80
|
-
|
81
|
-
missing.each do |id|
|
82
|
-
filename = pattern ? pattern.sub("{ID}", id.to_s) : id.to_s
|
83
|
-
result = yield id
|
84
|
-
File.open{|f| f.write(path = FileCache.path(filename)) }
|
85
78
|
result_files[id] = path
|
86
79
|
end
|
87
80
|
|
data/lib/rbbt/util/misc.rb
CHANGED
data/lib/rbbt/util/open.rb
CHANGED
@@ -216,9 +216,13 @@ module Open
|
|
216
216
|
save_content_in_repo(*dir_sub_path)
|
217
217
|
else
|
218
218
|
File.open(file, mode) do |f|
|
219
|
-
|
220
|
-
|
221
|
-
|
219
|
+
begin
|
220
|
+
f.flock(File::LOCK_EX)
|
221
|
+
f.write content
|
222
|
+
f.flock(File::LOCK_UN)
|
223
|
+
ensure
|
224
|
+
f.close unless f.closed?
|
225
|
+
end
|
222
226
|
end
|
223
227
|
end
|
224
228
|
end
|
@@ -359,21 +363,18 @@ module Open
|
|
359
363
|
end
|
360
364
|
|
361
365
|
def self.read(file, options = {}, &block)
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
366
|
+
open(file, options) do |f|
|
367
|
+
if block_given?
|
368
|
+
res = []
|
369
|
+
while not f.eof?
|
370
|
+
l = f.gets
|
371
|
+
l = Misc.fixutf8(l)
|
372
|
+
res << yield(l)
|
373
|
+
end
|
374
|
+
res
|
375
|
+
else
|
376
|
+
Misc.fixutf8(f.read)
|
370
377
|
end
|
371
|
-
f.close
|
372
|
-
res
|
373
|
-
else
|
374
|
-
text = Misc.fixutf8(f.read)
|
375
|
-
f.close unless f.closed?
|
376
|
-
text
|
377
378
|
end
|
378
379
|
end
|
379
380
|
|
@@ -7,6 +7,8 @@ options = SOPT.get("-tch--tokyocabinet:-tcb--tokyocabinet_bd")
|
|
7
7
|
|
8
8
|
file = ARGV.shift
|
9
9
|
|
10
|
+
file = STDIN if file == '-'
|
11
|
+
|
10
12
|
case
|
11
13
|
when options[:tokyocabinet]
|
12
14
|
tsv = Persist.open_tokyocabinet(file, false)
|
@@ -18,6 +20,7 @@ else
|
|
18
20
|
header = TSV.parse_header(Open.open(file))
|
19
21
|
|
20
22
|
puts "File: #{ file }"
|
23
|
+
puts "Type: #{header.type}"
|
21
24
|
puts "Key: #{header.key_field}"
|
22
25
|
puts "Fields: "
|
23
26
|
header.fields.each_with_index do |f,i|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rbbt-util'
|
4
|
+
require 'rbbt/util/simpleopt'
|
5
|
+
|
6
|
+
options = SOPT.get("-tch--tokyocabinet:-tcb--tokyocabinet_bd")
|
7
|
+
|
8
|
+
file = ARGV.shift
|
9
|
+
|
10
|
+
file = STDIN if file == '-'
|
11
|
+
|
12
|
+
case
|
13
|
+
when options[:tokyocabinet]
|
14
|
+
tsv = Persist.open_tokyocabinet(file, false)
|
15
|
+
when options[:tokyocabinet_bd]
|
16
|
+
tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
|
17
|
+
else
|
18
|
+
if String === file
|
19
|
+
file = file.dup
|
20
|
+
Path.setup(File.expand_path(file))
|
21
|
+
end
|
22
|
+
tsv = TSV.open(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
puts tsv.unzip.to_s
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rbbt-util'
|
4
|
+
require 'rbbt/util/simpleopt'
|
5
|
+
|
6
|
+
options = SOPT.get("-tch--tokyocabinet:-tcb--tokyocabinet_bd")
|
7
|
+
|
8
|
+
file = ARGV.shift
|
9
|
+
|
10
|
+
file = STDIN if file == '-'
|
11
|
+
|
12
|
+
case
|
13
|
+
when options[:tokyocabinet]
|
14
|
+
tsv = Persist.open_tokyocabinet(file, false)
|
15
|
+
when options[:tokyocabinet_bd]
|
16
|
+
tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
|
17
|
+
else
|
18
|
+
if String === file
|
19
|
+
file = file.dup
|
20
|
+
Path.setup(File.expand_path(file))
|
21
|
+
end
|
22
|
+
tsv = TSV.open(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
tsv.each{|k,v| puts (Array === v ? v.flatten*"\t" : v.to_s ) }
|
@@ -112,10 +112,11 @@ options = SOPT.get <<EOF
|
|
112
112
|
-cl--clean Clean the last step of the job so that it gets recomputed:
|
113
113
|
-rcl--recursive_clean Clean the last step and its dependencies to recompute the job completely:
|
114
114
|
-jn--jobname* Job name to use. The name 'Default' is used by default:
|
115
|
-
-pn--printname Print the name of the job and exit without starting it:
|
116
|
-
-jf--job_file* Output one of the job produced files:
|
117
115
|
-wd--workdir* Change the working directory of the workflow:
|
118
116
|
-O--output* Save job result into file:
|
117
|
+
-pn--printname Print the name of the job and exit without starting it:
|
118
|
+
-jf--job_file* Output one of the job produced files:
|
119
|
+
--info Show the job info:
|
119
120
|
--provenance Report the jobs provenance:
|
120
121
|
--fork Run job asyncronously:
|
121
122
|
EOF
|
@@ -193,8 +194,14 @@ if recursive_clean
|
|
193
194
|
job = workflow.job(task.name, name, job_options)
|
194
195
|
end
|
195
196
|
|
197
|
+
require 'pp'
|
198
|
+
|
196
199
|
# run
|
197
200
|
begin
|
201
|
+
if options[:info]
|
202
|
+
pp job.info
|
203
|
+
exit 0
|
204
|
+
end
|
198
205
|
if do_exec
|
199
206
|
res = job.exec
|
200
207
|
case
|
@@ -225,7 +232,6 @@ begin
|
|
225
232
|
|
226
233
|
|
227
234
|
if options.delete(:provenance)
|
228
|
-
require 'pp'
|
229
235
|
pp job.provenance
|
230
236
|
exit 0
|
231
237
|
end
|
data/test/rbbt/util/test_open.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.6.
|
4
|
+
version: 5.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -231,6 +231,8 @@ files:
|
|
231
231
|
- share/rbbt_commands/tsv/get
|
232
232
|
- share/rbbt_commands/tsv/info
|
233
233
|
- share/rbbt_commands/tsv/json
|
234
|
+
- share/rbbt_commands/tsv/unzip
|
235
|
+
- share/rbbt_commands/tsv/values
|
234
236
|
- share/rbbt_commands/workflow/cmd
|
235
237
|
- share/rbbt_commands/workflow/install
|
236
238
|
- share/rbbt_commands/workflow/monitor
|