rbbt-util 5.5.68 → 5.6.0
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/association.rb +1 -1
- data/lib/rbbt/association/index.rb +2 -1
- data/lib/rbbt/entity.rb +2 -0
- data/lib/rbbt/persist/tsv.rb +46 -232
- data/lib/rbbt/persist/tsv/cdb.rb +139 -0
- data/lib/rbbt/persist/tsv/kyotocabinet.rb +168 -0
- data/lib/rbbt/persist/tsv/leveldb.rb +121 -0
- data/lib/rbbt/persist/tsv/lmdb.rb +148 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +158 -0
- data/lib/rbbt/resource/rake.rb +2 -1
- data/lib/rbbt/tsv/accessor.rb +74 -101
- data/lib/rbbt/tsv/parser.rb +2 -5
- data/lib/rbbt/tsv/serializers.rb +6 -0
- data/lib/rbbt/tsv/util.rb +8 -2
- data/lib/rbbt/util/R.rb +6 -0
- data/lib/rbbt/util/cmd.rb +7 -4
- data/lib/rbbt/util/misc.rb +10 -4
- data/lib/rbbt/util/open.rb +8 -6
- data/lib/rbbt/util/simpleopt.rb +1 -1
- data/lib/rbbt/workflow.rb +17 -3
- data/lib/rbbt/workflow/accessor.rb +5 -1
- data/lib/rbbt/workflow/definition.rb +6 -0
- data/lib/rbbt/workflow/step.rb +10 -4
- data/lib/rbbt/workflow/task.rb +1 -1
- data/share/rbbt_commands/tsv/json +37 -0
- data/share/rbbt_commands/workflow/task +8 -2
- data/test/rbbt/persist/test_tsv.rb +77 -0
- data/test/rbbt/persist/tsv/test_cdb.rb +23 -0
- data/test/rbbt/persist/tsv/test_kyotocabinet.rb +33 -0
- data/test/rbbt/persist/tsv/test_leveldb.rb +22 -0
- data/test/rbbt/persist/tsv/test_lmdb.rb +22 -0
- data/test/rbbt/persist/tsv/test_tokyocabinet.rb +242 -0
- data/test/rbbt/test_persist.rb +1 -225
- data/test/rbbt/test_workflow.rb +0 -1
- data/test/rbbt/workflow/test_step.rb +14 -12
- data/test/test_helper.rb +4 -2
- metadata +20 -4
- data/test/rbbt/workflow/test_soap.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b772991027bae39d5d75e7d19fdfc628b2a78871
|
4
|
+
data.tar.gz: aed0bd56fbd0178bff6cd37b386390a392a5a7ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aeb956836ee4d77b643249dc63c13ba6aed3aa9568b58173eb872c45e384d5202ea8e742c55e775187371f4e5b438198d57f56896e3daad9041158320692677
|
7
|
+
data.tar.gz: eab7947a295e70759b50bf6333c589f7c71aa535d5c5c26f0c848aacb5b9f723505799bb4baec4c16f30b5fe3f9a5ed8715f3f6326612b33b342823622428497
|
data/lib/rbbt/association.rb
CHANGED
@@ -242,7 +242,7 @@ module Association
|
|
242
242
|
tsv = load_tsv(file, options)
|
243
243
|
|
244
244
|
tsv.annotate(data)
|
245
|
-
data.serializer = tsv.type if
|
245
|
+
data.serializer = tsv.type if data.respond_to? :persistence_path
|
246
246
|
|
247
247
|
tsv.with_unnamed do
|
248
248
|
tsv.each do |k,v|
|
@@ -11,6 +11,7 @@ module Association
|
|
11
11
|
repo.extend Association::Index
|
12
12
|
repo.parse_key_field
|
13
13
|
repo.unnamed = true
|
14
|
+
repo
|
14
15
|
end
|
15
16
|
|
16
17
|
def reverse
|
@@ -56,7 +57,7 @@ module Association
|
|
56
57
|
acc
|
57
58
|
end
|
58
59
|
end
|
59
|
-
|
60
|
+
|
60
61
|
#{{{ Subset
|
61
62
|
|
62
63
|
def select_entities(entities)
|
data/lib/rbbt/entity.rb
CHANGED
data/lib/rbbt/persist/tsv.rb
CHANGED
@@ -1,237 +1,35 @@
|
|
1
1
|
begin
|
2
|
-
require 'tokyocabinet'
|
2
|
+
require 'rbbt/persist/tsv/tokyocabinet'
|
3
3
|
rescue Exception
|
4
4
|
Log.warn "The tokyocabinet gem could not be loaded: persistence over TSV files will fail"
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
tokyocabinet_class = TokyoCabinet::HDB if tokyocabinet_class == "HDB"
|
14
|
-
tokyocabinet_class = TokyoCabinet::BDB if tokyocabinet_class == "BDB"
|
15
|
-
|
16
|
-
flags = (write ? tokyocabinet_class::OWRITER | tokyocabinet_class::OCREAT : tokyocabinet_class::OREADER)
|
17
|
-
|
18
|
-
FileUtils.mkdir_p File.dirname(path) unless File.exists?(File.dirname(path))
|
19
|
-
|
20
|
-
database = TC_CONNECTIONS[path] ||= tokyocabinet_class.new
|
21
|
-
database.close
|
22
|
-
|
23
|
-
if !database.open(path, flags)
|
24
|
-
ecode = database.ecode
|
25
|
-
raise "Open error: #{database.errmsg(ecode)}. Trying to open file #{path}"
|
26
|
-
end
|
27
|
-
|
28
|
-
if not database.respond_to? :old_close
|
29
|
-
class << database
|
30
|
-
attr_accessor :writable, :closed, :persistence_path, :tokyocabinet_class
|
31
|
-
|
32
|
-
def prefix(key)
|
33
|
-
range(key, 1, key + 255.chr, 1)
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_prefix(key)
|
37
|
-
keys = prefix(key)
|
38
|
-
select(:key => keys)
|
39
|
-
end
|
40
|
-
|
41
|
-
def closed?
|
42
|
-
@closed
|
43
|
-
end
|
44
|
-
|
45
|
-
alias old_close close
|
46
|
-
def close
|
47
|
-
@closed = true
|
48
|
-
old_close
|
49
|
-
end
|
50
|
-
|
51
|
-
def read(force = false)
|
52
|
-
return if not write? and not closed and not force
|
53
|
-
self.close
|
54
|
-
if !self.open(@persistence_path, tokyocabinet_class::OREADER)
|
55
|
-
ecode = self.ecode
|
56
|
-
raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}"
|
57
|
-
end
|
58
|
-
@writable = false
|
59
|
-
@closed = false
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def write(force = true)
|
64
|
-
return if write? and not closed and not force
|
65
|
-
self.close
|
66
|
-
|
67
|
-
if !self.open(@persistence_path, tokyocabinet_class::OWRITER)
|
68
|
-
ecode = self.ecode
|
69
|
-
raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}"
|
70
|
-
end
|
71
|
-
|
72
|
-
@writable = true
|
73
|
-
@closed = false
|
74
|
-
self
|
75
|
-
end
|
76
|
-
|
77
|
-
def write?
|
78
|
-
@writable
|
79
|
-
end
|
80
|
-
|
81
|
-
def collect
|
82
|
-
res = []
|
83
|
-
each do |key, value|
|
84
|
-
res << if block_given?
|
85
|
-
yield key, value
|
86
|
-
else
|
87
|
-
[key, value]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
res
|
91
|
-
end
|
92
|
-
|
93
|
-
def delete(key)
|
94
|
-
out(key)
|
95
|
-
end
|
96
|
-
|
97
|
-
def write_and_read
|
98
|
-
lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
|
99
|
-
Misc.lock(lock_filename) do
|
100
|
-
write if @closed or not write?
|
101
|
-
res = begin
|
102
|
-
yield
|
103
|
-
ensure
|
104
|
-
read
|
105
|
-
end
|
106
|
-
res
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def write_and_close
|
111
|
-
lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
|
112
|
-
Misc.lock(lock_filename) do
|
113
|
-
write if @closed or not write?
|
114
|
-
res = begin
|
115
|
-
yield
|
116
|
-
ensure
|
117
|
-
close
|
118
|
-
end
|
119
|
-
res
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def read_and_close
|
124
|
-
read if @closed or write?
|
125
|
-
res = begin
|
126
|
-
yield
|
127
|
-
ensure
|
128
|
-
close
|
129
|
-
end
|
130
|
-
res
|
131
|
-
end
|
132
|
-
|
133
|
-
def merge!(hash)
|
134
|
-
hash.each do |key,values|
|
135
|
-
self[key] = values
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
if instance_methods.include? "range"
|
140
|
-
alias old_range range
|
141
|
-
|
142
|
-
def range(*args)
|
143
|
-
keys = old_range(*args)
|
144
|
-
keys - TSV::ENTRY_KEYS
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
database.persistence_path ||= path
|
151
|
-
database.tokyocabinet_class = tokyocabinet_class
|
152
|
-
|
153
|
-
unless serializer == :clean
|
154
|
-
TSV.setup database
|
155
|
-
database.serializer = serializer || database.serializer
|
156
|
-
database.fields
|
157
|
-
end
|
158
|
-
|
159
|
-
database
|
160
|
-
end
|
161
|
-
|
162
|
-
def self.persist_tsv(source, filename, options = {}, persist_options = {})
|
163
|
-
persist_options[:prefix] ||= "TSV"
|
164
|
-
|
165
|
-
data = case
|
166
|
-
when persist_options[:data]
|
167
|
-
persist_options[:data]
|
168
|
-
when persist_options[:persist]
|
169
|
-
|
170
|
-
filename ||= case
|
171
|
-
when Path === source
|
172
|
-
source
|
173
|
-
when (source.respond_to?(:filename) and source.filename)
|
174
|
-
source.filename
|
175
|
-
when source.respond_to?(:cmd)
|
176
|
-
"CMD-#{Misc.digest(source.cmd)}"
|
177
|
-
when TSV === source
|
178
|
-
"TSV[#{Misc.digest Misc.fingerprint(source)}]"
|
179
|
-
else
|
180
|
-
source.object_id.to_s
|
181
|
-
end
|
182
|
-
|
183
|
-
filename ||= source.object_id.to_s
|
184
|
-
|
185
|
-
path = persistence_path(filename, persist_options, options)
|
186
|
-
|
187
|
-
if is_persisted? path and not persist_options[:update]
|
188
|
-
Log.debug "TSV persistence up-to-date: #{ path }"
|
189
|
-
lock_filename = Persist.persistence_path(path, {:dir => TSV.lock_dir})
|
190
|
-
return Misc.lock(lock_filename) do open_tokyocabinet(path, false, nil, persist_options[:engine] || TokyoCabinet::HDB); end
|
191
|
-
else
|
192
|
-
Log.medium "TSV persistence creating: #{ path }"
|
193
|
-
end
|
194
|
-
|
195
|
-
FileUtils.rm path if File.exists? path
|
196
|
-
|
197
|
-
tmp_path = path + '.persist'
|
198
|
-
|
199
|
-
data = open_tokyocabinet(tmp_path, true, persist_options[:serializer], persist_options[:engine] || TokyoCabinet::HDB)
|
200
|
-
data.serializer = :type if TSV === data and data.serializer.nil?
|
201
|
-
|
202
|
-
data.close
|
203
|
-
|
204
|
-
data
|
205
|
-
else
|
206
|
-
{}
|
207
|
-
end
|
7
|
+
begin
|
8
|
+
require 'rbbt/persist/tsv/lmdb'
|
9
|
+
rescue Exception
|
10
|
+
Log.warn "The lmdb gem could not be loaded. Persistance using this engine will fail."
|
11
|
+
end
|
208
12
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
else
|
215
|
-
yield data
|
216
|
-
end
|
217
|
-
rescue Exception
|
218
|
-
Log.error "Captured error during persist_tsv. Erasing: #{path}"
|
219
|
-
FileUtils.rm tmp_path if tmp_path and File.exists? tmp_path
|
220
|
-
raise $!
|
221
|
-
ensure
|
222
|
-
data.close if data.respond_to? :close
|
223
|
-
if tmp_path
|
224
|
-
FileUtils.mv tmp_path, path if File.exists? tmp_path and not File.exists? path
|
225
|
-
tsv = TC_CONNECTIONS[path] = TC_CONNECTIONS.delete tmp_path
|
226
|
-
tsv.persistence_path = path
|
227
|
-
end
|
228
|
-
end
|
13
|
+
begin
|
14
|
+
require 'rbbt/persist/tsv/leveldb'
|
15
|
+
rescue Exception
|
16
|
+
Log.warn "The LevelDB gem could not be loaded. Persistance using this engine will fail."
|
17
|
+
end
|
229
18
|
|
230
|
-
|
19
|
+
begin
|
20
|
+
require 'rbbt/persist/tsv/cdb'
|
21
|
+
rescue Exception
|
22
|
+
Log.warn "The CDB gem could not be loaded. Persistance using this engine will fail."
|
23
|
+
end
|
231
24
|
|
25
|
+
begin
|
26
|
+
require 'rbbt/persist/tsv/kyotocabinet'
|
27
|
+
rescue Exception
|
28
|
+
Log.warn "The kyotocabinet gem could not be loaded. Persistance using this engine will fail."
|
29
|
+
end
|
232
30
|
|
233
|
-
|
234
|
-
|
31
|
+
module Persist
|
32
|
+
CONNECTIONS = {}
|
235
33
|
|
236
34
|
def self.get_filename(source)
|
237
35
|
case
|
@@ -246,6 +44,21 @@ module Persist
|
|
246
44
|
end || source.object_id.to_s
|
247
45
|
end
|
248
46
|
|
47
|
+
def self.open_database(path, write, serializer = nil, type = "HDB")
|
48
|
+
case type
|
49
|
+
when "LevelDB"
|
50
|
+
Persist.open_leveldb(path, write, serializer)
|
51
|
+
when "CDB"
|
52
|
+
Persist.open_cdb(path, write, serializer)
|
53
|
+
when "LMDB"
|
54
|
+
Persist.open_lmdb(path, write, serializer)
|
55
|
+
when 'kch', 'kct'
|
56
|
+
Persist.open_kyotocabinet(path, write, serializer, type)
|
57
|
+
else
|
58
|
+
Persist.open_tokyocabinet(path, write, serializer, type)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
249
62
|
def self.persist_tsv(source, filename, options = {}, persist_options = {}, &block)
|
250
63
|
persist_options[:prefix] ||= "TSV"
|
251
64
|
|
@@ -270,14 +83,14 @@ module Persist
|
|
270
83
|
|
271
84
|
if is_persisted? path and not persist_options[:update]
|
272
85
|
Log.debug "TSV persistence up-to-date: #{ path }"
|
273
|
-
return
|
86
|
+
return open_database(path, false, nil, persist_options[:engine] || TokyoCabinet::HDB)
|
274
87
|
end
|
275
88
|
|
276
89
|
Misc.lock lock_filename do
|
277
90
|
begin
|
278
91
|
if is_persisted? path
|
279
92
|
Log.debug "TSV persistence up-to-date: #{ path }"
|
280
|
-
return
|
93
|
+
return open_database(path, false, nil, persist_options[:engine] || TokyoCabinet::HDB)
|
281
94
|
end
|
282
95
|
|
283
96
|
FileUtils.rm path if File.exists? path
|
@@ -286,22 +99,23 @@ module Persist
|
|
286
99
|
|
287
100
|
tmp_path = path + '.persist'
|
288
101
|
|
289
|
-
data =
|
102
|
+
data = open_database(tmp_path, true, persist_options[:serializer], persist_options[:engine] || TokyoCabinet::HDB)
|
290
103
|
data.serializer = :type if TSV === data and data.serializer.nil?
|
291
104
|
|
292
105
|
data.write_and_read do
|
293
106
|
yield data
|
294
107
|
end
|
295
108
|
|
296
|
-
FileUtils.mv
|
297
|
-
tsv =
|
109
|
+
FileUtils.mv data.persistence_path, path if File.exists? data.persistence_path and not File.exists? path
|
110
|
+
tsv = CONNECTIONS[path] = CONNECTIONS.delete tmp_path
|
298
111
|
tsv.persistence_path = path
|
112
|
+
tsv.fix_io if tsv.respond_to? :fix_io
|
299
113
|
|
300
114
|
data
|
301
115
|
rescue Exception
|
302
116
|
Log.error "Captured error during persist_tsv. Erasing: #{path}"
|
303
|
-
FileUtils.
|
304
|
-
FileUtils.
|
117
|
+
FileUtils.rm_rf tmp_path if tmp_path and File.exists? tmp_path
|
118
|
+
FileUtils.rm_rf path if path and File.exists? path
|
305
119
|
raise $!
|
306
120
|
end
|
307
121
|
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'libcdb'
|
2
|
+
|
3
|
+
module Persist
|
4
|
+
|
5
|
+
module CDBAdapter
|
6
|
+
attr_accessor :persistence_path, :closed
|
7
|
+
|
8
|
+
def self.open(path, write)
|
9
|
+
write = true unless File.exists? path
|
10
|
+
|
11
|
+
database = CONNECTIONS[path] ||= begin
|
12
|
+
file = File.open(path, 'w')
|
13
|
+
LibCDB::CDB.new(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
database.extend Persist::CDBAdapter unless Persist::CDBAdapter === database
|
17
|
+
database.persistence_path ||= path
|
18
|
+
|
19
|
+
database
|
20
|
+
end
|
21
|
+
|
22
|
+
def include?(k)
|
23
|
+
not write? and super(k)
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](*args)
|
27
|
+
write? ? nil : super(*args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def []=(k,v)
|
31
|
+
if write?
|
32
|
+
add(k,v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def closed?
|
37
|
+
@closed
|
38
|
+
end
|
39
|
+
|
40
|
+
def fix_io
|
41
|
+
if instance_variable_get(:@io) != persistence_path
|
42
|
+
#close_read if read?
|
43
|
+
#close_write if write?
|
44
|
+
instance_variable_set(:@io, File.open(persistence_path))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def close
|
49
|
+
self.closed = true
|
50
|
+
begin
|
51
|
+
fix_io
|
52
|
+
super
|
53
|
+
rescue
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def read(force = false)
|
58
|
+
self.closed = false
|
59
|
+
fix_io
|
60
|
+
open_read
|
61
|
+
end
|
62
|
+
|
63
|
+
def write(force = true)
|
64
|
+
self.closed = false
|
65
|
+
fix_io
|
66
|
+
open_write
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete(key)
|
71
|
+
out(key)
|
72
|
+
end
|
73
|
+
|
74
|
+
def write_and_read
|
75
|
+
lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
|
76
|
+
Misc.lock(lock_filename) do
|
77
|
+
write if @closed or not write?
|
78
|
+
res = begin
|
79
|
+
yield
|
80
|
+
rescue
|
81
|
+
Log.error $!.message
|
82
|
+
Log.debug $!.backtrace * "\n"
|
83
|
+
ensure
|
84
|
+
read if write?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def write_and_close
|
90
|
+
lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
|
91
|
+
Misc.lock(lock_filename) do
|
92
|
+
write if @closed or not write?
|
93
|
+
res = begin
|
94
|
+
yield
|
95
|
+
ensure
|
96
|
+
close
|
97
|
+
end
|
98
|
+
res
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def read_and_close
|
103
|
+
read if @closed or write?
|
104
|
+
res = begin
|
105
|
+
yield
|
106
|
+
ensure
|
107
|
+
close
|
108
|
+
end
|
109
|
+
res
|
110
|
+
end
|
111
|
+
|
112
|
+
def merge!(hash)
|
113
|
+
hash.each do |key,values|
|
114
|
+
self[key] = values
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def range(*args)
|
120
|
+
super(*args) - TSV::ENTRY_KEYS.to_a
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def self.open_cdb(path, write, serializer = nil)
|
126
|
+
write = true unless File.exists? path
|
127
|
+
|
128
|
+
FileUtils.mkdir_p File.dirname(path) unless File.exists?(File.dirname(path))
|
129
|
+
|
130
|
+
database = Persist::CDBAdapter.open(path, write)
|
131
|
+
|
132
|
+
unless serializer == :clean
|
133
|
+
TSV.setup database
|
134
|
+
database.serializer = serializer || database.serializer
|
135
|
+
end
|
136
|
+
|
137
|
+
database
|
138
|
+
end
|
139
|
+
end
|