tb 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +13 -11
- data/lib/tb.rb +14 -6
- data/lib/tb/catreader.rb +2 -2
- data/lib/tb/cmd_consecutive.rb +6 -2
- data/lib/tb/cmd_crop.rb +22 -3
- data/lib/tb/cmd_cross.rb +24 -0
- data/lib/tb/cmd_cut.rb +20 -10
- data/lib/tb/cmd_git.rb +20 -7
- data/lib/tb/cmd_group.rb +32 -0
- data/lib/tb/cmd_gsub.rb +21 -0
- data/lib/tb/cmd_join.rb +28 -0
- data/lib/tb/cmd_ls.rb +9 -0
- data/lib/tb/cmd_melt.rb +15 -0
- data/lib/tb/cmd_mheader.rb +15 -0
- data/lib/tb/cmd_nest.rb +27 -6
- data/lib/tb/cmd_newfield.rb +19 -2
- data/lib/tb/cmd_rename.rb +20 -0
- data/lib/tb/{cmd_grep.rb → cmd_search.rb} +37 -23
- data/lib/tb/cmd_shape.rb +69 -25
- data/lib/tb/cmd_sort.rb +20 -0
- data/lib/tb/cmd_tar.rb +38 -0
- data/lib/tb/cmd_to_json.rb +2 -2
- data/lib/tb/cmd_to_ltsv.rb +3 -3
- data/lib/tb/cmd_to_pnm.rb +3 -3
- data/lib/tb/cmd_to_tsv.rb +3 -3
- data/lib/tb/cmd_to_yaml.rb +3 -3
- data/lib/tb/cmd_unmelt.rb +15 -0
- data/lib/tb/cmd_unnest.rb +31 -7
- data/lib/tb/cmdmain.rb +2 -0
- data/lib/tb/cmdtop.rb +1 -1
- data/lib/tb/cmdutil.rb +9 -62
- data/lib/tb/csv.rb +21 -79
- data/lib/tb/enumerable.rb +42 -68
- data/lib/tb/enumerator.rb +15 -7
- data/lib/tb/{fieldset.rb → hashreader.rb} +37 -56
- data/lib/tb/hashwriter.rb +54 -0
- data/lib/tb/headerreader.rb +108 -0
- data/lib/tb/headerwriter.rb +116 -0
- data/lib/tb/json.rb +17 -15
- data/lib/tb/ltsv.rb +35 -96
- data/lib/tb/ndjson.rb +63 -0
- data/lib/tb/numericreader.rb +66 -0
- data/lib/tb/numericwriter.rb +61 -0
- data/lib/tb/pnm.rb +206 -200
- data/lib/tb/ropen.rb +54 -59
- data/lib/tb/tsv.rb +39 -71
- data/sample/excel2csv +24 -25
- data/sample/poi-xls2csv.rb +13 -14
- data/tb.gemspec +154 -0
- data/test/test_cmd_cat.rb +28 -6
- data/test/test_cmd_consecutive.rb +8 -3
- data/test/test_cmd_cut.rb +14 -4
- data/test/test_cmd_git_log.rb +50 -50
- data/test/test_cmd_grep.rb +6 -6
- data/test/test_cmd_gsub.rb +7 -2
- data/test/test_cmd_ls.rb +70 -62
- data/test/test_cmd_shape.rb +43 -6
- data/test/test_cmd_svn_log.rb +26 -27
- data/test/test_cmd_to_csv.rb +10 -5
- data/test/test_cmd_to_json.rb +16 -0
- data/test/test_cmd_to_ltsv.rb +2 -2
- data/test/test_cmd_to_pp.rb +7 -2
- data/test/test_csv.rb +74 -62
- data/test/test_ex_enumerable.rb +0 -1
- data/test/test_fileenumerator.rb +3 -3
- data/test/test_headercsv.rb +43 -0
- data/test/test_json.rb +2 -2
- data/test/test_ltsv.rb +22 -17
- data/test/test_ndjson.rb +62 -0
- data/test/test_numericcsv.rb +36 -0
- data/test/test_pnm.rb +69 -70
- data/test/test_reader.rb +27 -124
- data/test/test_tbenum.rb +18 -18
- data/test/test_tsv.rb +21 -32
- data/test/util_tbtest.rb +12 -0
- metadata +41 -19
- data/lib/tb/basic.rb +0 -1070
- data/lib/tb/reader.rb +0 -106
- data/lib/tb/record.rb +0 -158
- data/test/test_basic.rb +0 -403
- data/test/test_fieldset.rb +0 -42
- data/test/test_record.rb +0 -61
data/lib/tb/cmd_melt.rb
CHANGED
@@ -61,6 +61,21 @@ def (Tb::Cmd).op_melt
|
|
61
61
|
op
|
62
62
|
end
|
63
63
|
|
64
|
+
Tb::Cmd.def_vhelp('melt', <<'End')
|
65
|
+
Example:
|
66
|
+
|
67
|
+
% cat tst.csv
|
68
|
+
foo,bar,baz
|
69
|
+
A,1,x
|
70
|
+
B,2,y
|
71
|
+
% tb melt foo tst.csv
|
72
|
+
foo,variable,value
|
73
|
+
A,bar,1
|
74
|
+
A,baz,x
|
75
|
+
B,bar,2
|
76
|
+
B,baz,y
|
77
|
+
End
|
78
|
+
|
64
79
|
def (Tb::Cmd).main_melt(argv)
|
65
80
|
op_melt.parse!(argv)
|
66
81
|
exit_if_help('melt')
|
data/lib/tb/cmd_mheader.rb
CHANGED
@@ -39,6 +39,21 @@ def (Tb::Cmd).op_mheader
|
|
39
39
|
op
|
40
40
|
end
|
41
41
|
|
42
|
+
Tb::Cmd.def_vhelp('mheader', <<'End')
|
43
|
+
Example:
|
44
|
+
|
45
|
+
% cat tst.csv
|
46
|
+
foo,foo,bar,bar
|
47
|
+
baz,qux,baz,qux
|
48
|
+
1,2,3,4
|
49
|
+
5,6,7,8
|
50
|
+
% tb mheader tst.csv
|
51
|
+
foo baz,foo qux,bar baz,bar qux
|
52
|
+
1,2,3,4
|
53
|
+
5,6,7,8
|
54
|
+
End
|
55
|
+
|
56
|
+
|
42
57
|
def (Tb::Cmd).main_mheader(argv)
|
43
58
|
op_mheader.parse!(argv)
|
44
59
|
exit_if_help('mheader')
|
data/lib/tb/cmd_nest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2011-
|
1
|
+
# Copyright (C) 2011-2014 Tanaka Akira <akr@fsij.org>
|
2
2
|
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
@@ -36,6 +36,28 @@ def (Tb::Cmd).op_nest
|
|
36
36
|
op
|
37
37
|
end
|
38
38
|
|
39
|
+
Tb::Cmd.def_vhelp('nest', <<'End')
|
40
|
+
Example:
|
41
|
+
|
42
|
+
% cat tst.csv
|
43
|
+
name,author,length
|
44
|
+
foo,A,3
|
45
|
+
bar,A,5
|
46
|
+
baz,B,2
|
47
|
+
qux,B,8
|
48
|
+
% tb nest item,name,length tst.csv
|
49
|
+
author,item
|
50
|
+
A,"name,length
|
51
|
+
foo,3
|
52
|
+
bar,5
|
53
|
+
"
|
54
|
+
B,"name,length
|
55
|
+
baz,2
|
56
|
+
qux,8
|
57
|
+
"
|
58
|
+
End
|
59
|
+
|
60
|
+
|
39
61
|
def (Tb::Cmd).main_nest(argv)
|
40
62
|
op_nest.parse!(argv)
|
41
63
|
exit_if_help('nest')
|
@@ -71,11 +93,10 @@ def (Tb::Cmd).main_nest(argv)
|
|
71
93
|
nested << pairs.reject {|f, v| !oldfields_hash[f] }
|
72
94
|
}
|
73
95
|
after_group = lambda {|(_, last_pairs)|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
96
|
+
nested_csv = ""
|
97
|
+
nested_csv << oldfields.to_csv
|
98
|
+
nested.each {|npairs|
|
99
|
+
nested_csv << oldfields.map {|of| npairs[of] }.to_csv
|
79
100
|
}
|
80
101
|
assoc = last_pairs.reject {|f, v| oldfields_hash[f] }.to_a
|
81
102
|
assoc << [newfield, nested_csv]
|
data/lib/tb/cmd_newfield.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2011-
|
1
|
+
# Copyright (C) 2011-2014 Tanaka Akira <akr@fsij.org>
|
2
2
|
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
@@ -41,6 +41,23 @@ def (Tb::Cmd).op_newfield
|
|
41
41
|
op
|
42
42
|
end
|
43
43
|
|
44
|
+
Tb::Cmd.def_vhelp('newfield', <<'End')
|
45
|
+
Example:
|
46
|
+
|
47
|
+
% cat tst.csv
|
48
|
+
a,b,c
|
49
|
+
0,1,2
|
50
|
+
4,5,6
|
51
|
+
% tb newfield foo bar tst.csv
|
52
|
+
foo,a,b,c
|
53
|
+
bar,0,1,2
|
54
|
+
bar,4,5,6
|
55
|
+
% tb newfield foo --ruby '_["b"] + _["c"]' tst.csv
|
56
|
+
foo,a,b,c
|
57
|
+
12,0,1,2
|
58
|
+
56,4,5,6
|
59
|
+
End
|
60
|
+
|
44
61
|
def (Tb::Cmd).main_newfield(argv)
|
45
62
|
op_newfield.parse!(argv)
|
46
63
|
exit_if_help('newfield')
|
@@ -50,7 +67,7 @@ def (Tb::Cmd).main_newfield(argv)
|
|
50
67
|
rubyexp = Tb::Cmd.opt_newfield_ruby
|
51
68
|
pr = eval("lambda {|_| #{rubyexp} }")
|
52
69
|
else
|
53
|
-
err('no
|
70
|
+
err('no value given.') if argv.empty?
|
54
71
|
value = argv.shift
|
55
72
|
pr = lambda {|_| value }
|
56
73
|
end
|
data/lib/tb/cmd_rename.rb
CHANGED
@@ -36,6 +36,26 @@ def (Tb::Cmd).op_rename
|
|
36
36
|
op
|
37
37
|
end
|
38
38
|
|
39
|
+
Tb::Cmd.def_vhelp('rename', <<'End')
|
40
|
+
Example:
|
41
|
+
|
42
|
+
% cat tst.csv
|
43
|
+
foo,bar,baz
|
44
|
+
1,2,3
|
45
|
+
4,5,6
|
46
|
+
7,8,9
|
47
|
+
% tb rename bar,qux tst.csv
|
48
|
+
foo,qux,baz
|
49
|
+
1,2,3
|
50
|
+
4,5,6
|
51
|
+
7,8,9
|
52
|
+
% tb rename bar,qux,baz,quux tst.csv
|
53
|
+
foo,qux,quux
|
54
|
+
1,2,3
|
55
|
+
4,5,6
|
56
|
+
7,8,9
|
57
|
+
End
|
58
|
+
|
39
59
|
def (Tb::Cmd).main_rename(argv)
|
40
60
|
op_rename.parse!(argv)
|
41
61
|
exit_if_help('rename')
|
@@ -26,41 +26,55 @@
|
|
26
26
|
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
27
27
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
28
|
|
29
|
-
Tb::Cmd.subcommands << '
|
29
|
+
Tb::Cmd.subcommands << 'search'
|
30
30
|
|
31
|
-
Tb::Cmd.default_option[:
|
32
|
-
Tb::Cmd.default_option[:
|
33
|
-
Tb::Cmd.default_option[:
|
34
|
-
Tb::Cmd.default_option[:
|
31
|
+
Tb::Cmd.default_option[:opt_search_e] = nil
|
32
|
+
Tb::Cmd.default_option[:opt_search_ruby] = nil
|
33
|
+
Tb::Cmd.default_option[:opt_search_f] = nil
|
34
|
+
Tb::Cmd.default_option[:opt_search_v] = nil
|
35
35
|
|
36
|
-
def (Tb::Cmd).
|
36
|
+
def (Tb::Cmd).op_search
|
37
37
|
op = OptionParser.new
|
38
|
-
op.banner = "Usage: tb
|
38
|
+
op.banner = "Usage: tb search [OPTS] REGEXP [TABLE ...]\n" +
|
39
39
|
"Search rows using regexp or ruby expression."
|
40
40
|
define_common_option(op, "hNo", "--no-pager")
|
41
|
-
op.def_option('-f FIELD', 'search field') {|field| Tb::Cmd.
|
42
|
-
op.def_option('-e REGEXP', 'specify a regexp.') {|pattern| Tb::Cmd.
|
43
|
-
op.def_option('--ruby RUBY-EXP', 'predicate written in ruby. A hash is given as _. no usual regexp argument.') {|ruby_exp| Tb::Cmd.
|
44
|
-
op.def_option('-v', 'ouput the records which doesn\'t match') { Tb::Cmd.
|
41
|
+
op.def_option('-f FIELD', 'search field') {|field| Tb::Cmd.opt_search_f = field }
|
42
|
+
op.def_option('-e REGEXP', 'specify a regexp.') {|pattern| Tb::Cmd.opt_search_e = pattern }
|
43
|
+
op.def_option('--ruby RUBY-EXP', 'predicate written in ruby. A hash is given as _. no usual regexp argument.') {|ruby_exp| Tb::Cmd.opt_search_ruby = ruby_exp }
|
44
|
+
op.def_option('-v', 'ouput the records which doesn\'t match') { Tb::Cmd.opt_search_v = true }
|
45
45
|
op
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
Tb::Cmd.def_vhelp('search', <<'End')
|
49
|
+
Example:
|
50
|
+
|
51
|
+
% cat tst.csv
|
52
|
+
a,b,c
|
53
|
+
0,1,2
|
54
|
+
4,5,6
|
55
|
+
% tb search 0 tst.csv
|
56
|
+
a,b,c
|
57
|
+
0,1,2
|
58
|
+
End
|
59
|
+
|
60
|
+
def (Tb::Cmd).main_search(argv)
|
61
|
+
op_search.parse!(argv)
|
62
|
+
exit_if_help('search')
|
63
|
+
if Tb::Cmd.opt_search_ruby
|
64
|
+
pred = eval("lambda {|_| #{Tb::Cmd.opt_search_ruby} }")
|
65
|
+
elsif Tb::Cmd.opt_search_e
|
66
|
+
re = Regexp.new(Tb::Cmd.opt_search_e)
|
67
|
+
pred = Tb::Cmd.opt_search_f ?
|
68
|
+
lambda {|_| re =~ _[Tb::Cmd.opt_search_f] } :
|
69
|
+
lambda {|_| _.any? {|k, v| re =~ v.to_s } }
|
57
70
|
else
|
58
71
|
err("no regexp given.") if argv.empty?
|
59
72
|
re = Regexp.new(argv.shift)
|
60
|
-
pred = Tb::Cmd.
|
61
|
-
|
73
|
+
pred = Tb::Cmd.opt_search_f ?
|
74
|
+
lambda {|_| re =~ _[Tb::Cmd.opt_search_f] } :
|
75
|
+
lambda {|_| _.any? {|k, v| re =~ v.to_s } }
|
62
76
|
end
|
63
|
-
opt_v = Tb::Cmd.
|
77
|
+
opt_v = Tb::Cmd.opt_search_v ? true : false
|
64
78
|
argv = ['-'] if argv.empty?
|
65
79
|
creader = Tb::CatReader.open(argv, Tb::Cmd.opt_N)
|
66
80
|
er = Tb::Enumerator.new {|y|
|
data/lib/tb/cmd_shape.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2011-
|
1
|
+
# Copyright (C) 2011-2014 Tanaka Akira <akr@fsij.org>
|
2
2
|
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
@@ -36,38 +36,82 @@ def (Tb::Cmd).op_shape
|
|
36
36
|
op
|
37
37
|
end
|
38
38
|
|
39
|
+
Tb::Cmd.def_vhelp('shape', <<'End')
|
40
|
+
Example:
|
41
|
+
|
42
|
+
% cat tst.csv
|
43
|
+
foo,bar,baz
|
44
|
+
1,2,3
|
45
|
+
4,5
|
46
|
+
6,7,8,9
|
47
|
+
% tb shape tst.csv -o json:-
|
48
|
+
[
|
49
|
+
{
|
50
|
+
"filename": "tst.csv",
|
51
|
+
"records": 3,
|
52
|
+
"min_pairs": 2,
|
53
|
+
"max_pairs": 3,
|
54
|
+
"header_fields": 3,
|
55
|
+
"min_fields": 2,
|
56
|
+
"max_fields": 4
|
57
|
+
}
|
58
|
+
]
|
59
|
+
End
|
60
|
+
|
39
61
|
def (Tb::Cmd).main_shape(argv)
|
40
62
|
op_shape.parse!(argv)
|
41
63
|
exit_if_help('shape')
|
42
64
|
filenames = argv.empty? ? ['-'] : argv
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
ter = Tb::Enumerator.new {|y|
|
66
|
+
filenames.each {|filename|
|
67
|
+
tablereader_open(filename) {|tblreader|
|
68
|
+
tblreader.enable_warning = false if tblreader.respond_to? :enable_warning
|
69
|
+
num_records = 0
|
70
|
+
num_header_fields = nil
|
71
|
+
min_num_fields = nil
|
72
|
+
max_num_fields = nil
|
73
|
+
if tblreader.respond_to? :header_array_hook
|
74
|
+
tblreader.header_array_hook = lambda {|header|
|
75
|
+
num_header_fields = header.length
|
76
|
+
}
|
77
|
+
end
|
78
|
+
if tblreader.respond_to? :row_array_hook
|
79
|
+
tblreader.row_array_hook = lambda {|ary|
|
80
|
+
n = ary.length
|
81
|
+
if min_num_fields.nil?
|
82
|
+
min_num_fields = max_num_fields = n
|
83
|
+
else
|
84
|
+
min_num_fields = n if n < min_num_fields
|
85
|
+
max_num_fields = n if max_num_fields < n
|
86
|
+
end
|
87
|
+
}
|
61
88
|
end
|
89
|
+
min_num_pairs = nil
|
90
|
+
max_num_pairs = nil
|
91
|
+
tblreader.each {|pairs|
|
92
|
+
num_records += 1
|
93
|
+
n = pairs.length
|
94
|
+
if min_num_pairs.nil?
|
95
|
+
min_num_pairs = max_num_pairs = n
|
96
|
+
else
|
97
|
+
min_num_pairs = n if n < min_num_pairs
|
98
|
+
max_num_pairs = n if max_num_pairs < n
|
99
|
+
end
|
100
|
+
}
|
101
|
+
h = {
|
102
|
+
'filename'=>filename,
|
103
|
+
'records'=>num_records,
|
104
|
+
'min_pairs'=>min_num_pairs,
|
105
|
+
'max_pairs'=>max_num_pairs,
|
106
|
+
}
|
107
|
+
h['header_fields'] = num_header_fields if num_header_fields
|
108
|
+
h['min_fields'] = min_num_fields if min_num_fields
|
109
|
+
h['max_fields'] = max_num_fields if max_num_fields
|
110
|
+
y.yield(h)
|
62
111
|
}
|
63
|
-
result.insert({'header_fields'=>num_header_fields,
|
64
|
-
'min_fields'=>min_num_fields,
|
65
|
-
'max_fields'=>max_num_fields,
|
66
|
-
'records'=>num_records,
|
67
|
-
'filename'=>filename})
|
68
112
|
}
|
69
113
|
}
|
70
114
|
Tb::Cmd.opt_N = false
|
71
|
-
output_tbenum(
|
115
|
+
output_tbenum(ter)
|
72
116
|
end
|
73
117
|
|
data/lib/tb/cmd_sort.rb
CHANGED
@@ -41,6 +41,26 @@ def (Tb::Cmd).op_sort
|
|
41
41
|
op
|
42
42
|
end
|
43
43
|
|
44
|
+
Tb::Cmd.def_vhelp('sort', <<'End')
|
45
|
+
Example:
|
46
|
+
|
47
|
+
% cat tst.csv
|
48
|
+
name,value
|
49
|
+
foo,1
|
50
|
+
bar,8
|
51
|
+
baz,2
|
52
|
+
% tb sort tst.csv
|
53
|
+
name,value
|
54
|
+
bar,8
|
55
|
+
baz,2
|
56
|
+
foo,1
|
57
|
+
% tb sort -f value tst.csv
|
58
|
+
name,value
|
59
|
+
foo,1
|
60
|
+
baz,2
|
61
|
+
bar,8
|
62
|
+
End
|
63
|
+
|
44
64
|
def (Tb::Cmd).main_sort(argv)
|
45
65
|
op_sort.parse!(argv)
|
46
66
|
exit_if_help('sort')
|
data/lib/tb/cmd_tar.rb
CHANGED
@@ -43,6 +43,44 @@ def (Tb::Cmd).op_tar
|
|
43
43
|
op
|
44
44
|
end
|
45
45
|
|
46
|
+
Tb::Cmd.def_vhelp('tar', <<'End')
|
47
|
+
Example:
|
48
|
+
|
49
|
+
% tb tar ruby-1.8.7.tar.bz2|head
|
50
|
+
mode,filemode,uid,user,gid,group,devmajor,devminor,size,mtime,path,linkname
|
51
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:19:03+09:00,ruby-1.8.7/,""
|
52
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24+09:00,ruby-1.8.7/ext/,""
|
53
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:25+09:00,ruby-1.8.7/doc/,""
|
54
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,5011,2008-05-31T23:57:11+09:00,ruby-1.8.7/Makefile.in,""
|
55
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,124521,2008-05-31T20:44:49+09:00,ruby-1.8.7/parse.y,""
|
56
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,32308,2008-05-29T20:23:36+09:00,ruby-1.8.7/README.EXT,""
|
57
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,19502,2008-05-31T20:44:49+09:00,ruby-1.8.7/intern.h,""
|
58
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,22581,2008-05-23T14:22:13+09:00,ruby-1.8.7/class.c,""
|
59
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24+09:00,ruby-1.8.7/djgpp/,""
|
60
|
+
% tb tar -l ruby-1.8.7.tar.bz2|head
|
61
|
+
mode,filemode,uid,user,gid,group,devmajor,devminor,size,mtime,atime,ctime,path,linkname,size_in_tar,tar_typeflag,tar_magic,tar_version,tar_chksum
|
62
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:19:03.000000000+09:00,,,ruby-1.8.7/,"",512,5,ustar,00,5406
|
63
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24.000000000+09:00,,,ruby-1.8.7/ext/,"",512,5,ustar,00,5779
|
64
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:25.000000000+09:00,,,ruby-1.8.7/doc/,"",512,5,ustar,00,5753
|
65
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,5011,2008-05-31T23:57:11.000000000+09:00,,,ruby-1.8.7/Makefile.in,"",5632,0,ustar,00,6467
|
66
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,124521,2008-05-31T20:44:49.000000000+09:00,,,ruby-1.8.7/parse.y,"",125440,0,ustar,00,6114
|
67
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,32308,2008-05-29T20:23:36.000000000+09:00,,,ruby-1.8.7/README.EXT,"",33280,0,ustar,00,6133
|
68
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,19502,2008-05-31T20:44:49.000000000+09:00,,,ruby-1.8.7/intern.h,"",20480,0,ustar,00,6216
|
69
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,22581,2008-05-23T14:22:13.000000000+09:00,,,ruby-1.8.7/class.c,"",23552,0,ustar,00,6093
|
70
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24.000000000+09:00,,,ruby-1.8.7/djgpp/,"",512,5,ustar,00,5975
|
71
|
+
% tb tar -l --hash=md5 ruby-1.8.7.tar.bz2|head
|
72
|
+
mode,filemode,uid,user,gid,group,devmajor,devminor,size,mtime,atime,ctime,path,linkname,size_in_tar,tar_typeflag,tar_magic,tar_version,tar_chksum,md5
|
73
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:19:03.000000000+09:00,,,ruby-1.8.7/,"",512,5,ustar,00,5406,
|
74
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24.000000000+09:00,,,ruby-1.8.7/ext/,"",512,5,ustar,00,5779,
|
75
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:25.000000000+09:00,,,ruby-1.8.7/doc/,"",512,5,ustar,00,5753,
|
76
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,5011,2008-05-31T23:57:11.000000000+09:00,,,ruby-1.8.7/Makefile.in,"",5632,0,ustar,00,6467,1c038d48e3132822f18bf758a81e1794
|
77
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,124521,2008-05-31T20:44:49.000000000+09:00,,,ruby-1.8.7/parse.y,"",125440,0,ustar,00,6114,6f6bd781876136a7a71cf0ffcd6ecabc
|
78
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,32308,2008-05-29T20:23:36.000000000+09:00,,,ruby-1.8.7/README.EXT,"",33280,0,ustar,00,6133,22785b26a8eb77bd426a09f0d493228b
|
79
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,19502,2008-05-31T20:44:49.000000000+09:00,,,ruby-1.8.7/intern.h,"",20480,0,ustar,00,6216,cf8876629465d2e8fcefbe71c21915a7
|
80
|
+
0644,-rw-r--r--,1001,knu,0,wheel,0,0,22581,2008-05-23T14:22:13.000000000+09:00,,,ruby-1.8.7/class.c,"",23552,0,ustar,00,6093,bff1443982b7f0261ce45db9375e5881
|
81
|
+
0755,drwxr-xr-x,1001,knu,0,wheel,0,0,0,2008-06-01T00:18:24.000000000+09:00,,,ruby-1.8.7/djgpp/,"",512,5,ustar,00,5975,
|
82
|
+
End
|
83
|
+
|
46
84
|
Tb::Cmd::TAR_RECORD_LENGTH = 512
|
47
85
|
Tb::Cmd::TAR_HEADER_STRUCTURE = [
|
48
86
|
[:name, "Z100"], # [POSIX] NUL-terminated character strings except when all characters in the array contain non-NUL characters including the last character.
|
data/lib/tb/cmd_to_json.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2011-
|
1
|
+
# Copyright (C) 2011-2014 Tanaka Akira <akr@fsij.org>
|
2
2
|
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
@@ -49,7 +49,7 @@ def (Tb::Cmd).main_to_json(argv)
|
|
49
49
|
tablereader_open(filename) {|tblreader|
|
50
50
|
tblreader.each {|pairs|
|
51
51
|
out.print sep if sep
|
52
|
-
out.print JSON.pretty_generate(
|
52
|
+
out.print JSON.pretty_generate(pairs)
|
53
53
|
sep = ",\n"
|
54
54
|
}
|
55
55
|
}
|
data/lib/tb/cmd_to_ltsv.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Tanaka Akira <akr@fsij.org>
|
1
|
+
# Copyright (C) 2013-2014 Tanaka Akira <akr@fsij.org>
|
2
2
|
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
@@ -40,9 +40,9 @@ def (Tb::Cmd).main_to_ltsv(argv)
|
|
40
40
|
op_to_ltsv.parse!(argv)
|
41
41
|
exit_if_help('to-ltsv')
|
42
42
|
argv = ['-'] if argv.empty?
|
43
|
-
|
43
|
+
reader = Tb::CatReader.open(argv, Tb::Cmd.opt_N)
|
44
44
|
with_output {|out|
|
45
|
-
|
45
|
+
reader.write_to_ltsv(out)
|
46
46
|
}
|
47
47
|
end
|
48
48
|
|