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
@@ -1,113 +1,118 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class MissingParameterException < ParameterException
|
5
|
-
def initialize(parameter)
|
6
|
-
super("Missing parameter '#{parameter}'")
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class FieldNotFoundError < StandardError;end
|
1
|
+
require_relative '../../refactor'
|
2
|
+
Rbbt.require_instead 'scout/exceptions'
|
11
3
|
class ClosedStream < StandardError; end
|
12
|
-
|
13
|
-
class
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
class
|
54
|
-
attr_accessor :
|
55
|
-
def initialize(
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
class
|
62
|
-
|
63
|
-
class
|
64
|
-
|
65
|
-
class
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
class
|
78
|
-
def initialize(msg)
|
79
|
-
if defined? Step and Step === msg
|
80
|
-
step = msg
|
81
|
-
|
82
|
-
new_msg
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
4
|
+
RbbtException = ScoutException
|
5
|
+
#class RbbtException < ScoutException; end
|
6
|
+
#class ParameterException < RbbtException; end
|
7
|
+
#
|
8
|
+
#class MissingParameterException < ParameterException
|
9
|
+
# def initialize(parameter)
|
10
|
+
# super("Missing parameter '#{parameter}'")
|
11
|
+
# end
|
12
|
+
#end
|
13
|
+
#
|
14
|
+
#class FieldNotFoundError < StandardError;end
|
15
|
+
#class ClosedStream < StandardError; end
|
16
|
+
#
|
17
|
+
#class ProcessFailed < StandardError;
|
18
|
+
# attr_accessor :pid, :msg
|
19
|
+
# def initialize(pid = Process.pid, msg = nil)
|
20
|
+
# @pid = pid
|
21
|
+
# @msg = msg
|
22
|
+
# if @pid
|
23
|
+
# if @msg
|
24
|
+
# message = "Process #{@pid} failed - #{@msg}"
|
25
|
+
# else
|
26
|
+
# message = "Process #{@pid} failed"
|
27
|
+
# end
|
28
|
+
# else
|
29
|
+
# message = "Failed to run #{@msg}"
|
30
|
+
# end
|
31
|
+
# super(message)
|
32
|
+
# end
|
33
|
+
#end
|
34
|
+
#
|
35
|
+
#class SSHProcessFailed < StandardError
|
36
|
+
# attr_accessor :host, :cmd
|
37
|
+
# def initialize(host, cmd)
|
38
|
+
# @host = host
|
39
|
+
# @cmd = cmd
|
40
|
+
# message = "SSH server #{host} failed cmd '#{cmd}'"
|
41
|
+
# super(message)
|
42
|
+
# end
|
43
|
+
#end
|
44
|
+
#
|
45
|
+
#class ConcurrentStreamProcessFailed < ProcessFailed
|
46
|
+
# attr_accessor :concurrent_stream
|
47
|
+
# def initialize(pid = Process.pid, msg = nil, concurrent_stream = nil)
|
48
|
+
# super(pid, msg)
|
49
|
+
# @concurrent_stream = concurrent_stream
|
50
|
+
# end
|
51
|
+
#end
|
52
|
+
#
|
53
|
+
#class Aborted < StandardError; end
|
54
|
+
#
|
55
|
+
#class TryAgain < StandardError; end
|
56
|
+
#
|
57
|
+
#class TryThis < StandardError
|
58
|
+
# attr_accessor :payload
|
59
|
+
# def initialize(payload = nil)
|
60
|
+
# @payload = payload
|
61
|
+
# end
|
62
|
+
#end
|
63
|
+
#
|
64
|
+
#class SemaphoreInterrupted < TryAgain; end
|
65
|
+
#class LockInterrupted < TryAgain; end
|
66
|
+
#
|
67
|
+
#class RemoteServerError < StandardError; end
|
68
|
+
#
|
69
|
+
#class DependencyError < Aborted
|
70
|
+
# def initialize(msg)
|
71
|
+
# if defined? Step and Step === msg
|
72
|
+
# step = msg
|
73
|
+
# new_msg = [step.path, step.messages.last] * ": "
|
74
|
+
# super(new_msg)
|
75
|
+
# else
|
76
|
+
# super(msg)
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#end
|
80
|
+
#
|
81
|
+
#class DependencyException < RbbtException
|
82
|
+
#class DependencyRbbtException < RbbtException
|
83
|
+
# def initialize(msg)
|
84
|
+
# if defined? Step and Step === msg
|
85
|
+
# step = msg
|
86
|
+
#
|
87
|
+
# new_msg = nil
|
88
|
+
# new_msg = [step.path, step.messages.last] * ": "
|
89
|
+
#
|
90
|
+
# super(new_msg)
|
91
|
+
# else
|
92
|
+
# super(msg)
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
#end
|
96
|
+
#
|
97
|
+
#class DontClose < Exception; end
|
98
|
+
#
|
99
|
+
#class KeepLocked < Exception
|
100
|
+
# attr_accessor :payload
|
101
|
+
# def initialize(payload)
|
102
|
+
# @payload = payload
|
103
|
+
# end
|
104
|
+
#end
|
105
|
+
#
|
106
|
+
#class KeepBar < Exception
|
107
|
+
# attr_accessor :payload
|
108
|
+
# def initialize(payload)
|
109
|
+
# @payload = payload
|
110
|
+
# end
|
111
|
+
#end
|
112
|
+
#
|
113
|
+
#class StopInsist < Exception
|
114
|
+
# attr_accessor :exception
|
115
|
+
# def initialize(exception)
|
116
|
+
# @exception = exception
|
117
|
+
# end
|
118
|
+
#end
|
@@ -1,230 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def self.colors_for(list)
|
5
|
-
unused = COLOR_LIST.dup
|
6
|
-
|
7
|
-
used = {}
|
8
|
-
colors = list.collect do |elem|
|
9
|
-
if used.include? elem
|
10
|
-
used[elem]
|
11
|
-
else
|
12
|
-
color = unused.shift
|
13
|
-
used[elem]=color
|
14
|
-
color
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
[colors, used]
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.format_seconds(time, extended = false)
|
22
|
-
seconds = time.to_i
|
23
|
-
str = [seconds/3600, seconds/60 % 60, seconds % 60].map{|t| "%02i" % t }.join(':')
|
24
|
-
str << ".%02i" % ((time - seconds) * 100) if extended
|
25
|
-
str
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.format_paragraph(text, size = 80, indent = 0, offset = 0)
|
29
|
-
i = 0
|
30
|
-
offset = 0 if offset.nil?
|
31
|
-
indent = 0 if indent.nil?
|
32
|
-
size = 80 if size.nil?
|
33
|
-
size = size + offset + indent
|
34
|
-
re = /((?:\n\s*\n\s*)|(?:\n\s*(?=\*)))/
|
35
|
-
text.split(re).collect do |paragraph|
|
36
|
-
i += 1
|
37
|
-
str = if i % 2 == 1
|
38
|
-
words = paragraph.gsub(/\s+/, "\s").split(" ")
|
39
|
-
lines = []
|
40
|
-
line = " "*offset
|
41
|
-
word = words.shift
|
42
|
-
while word
|
43
|
-
word = word[0..size-indent-offset-4] + '...' if word.length >= size - indent - offset
|
44
|
-
while word and Log.uncolor(line).length + Log.uncolor(word).length <= size - indent
|
45
|
-
line << word << " "
|
46
|
-
word = words.shift
|
47
|
-
end
|
48
|
-
offset = 0
|
49
|
-
lines << ((" " * indent) << line[0..-2])
|
50
|
-
line = ""
|
51
|
-
end
|
52
|
-
(lines * "\n")
|
53
|
-
else
|
54
|
-
paragraph
|
55
|
-
end
|
56
|
-
offset = 0
|
57
|
-
str
|
58
|
-
end*""
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.format_definition_list_item(dt, dd, size = 80, indent = 20, color = :yellow)
|
62
|
-
dd = "" if dd.nil?
|
63
|
-
dt = Log.color color, dt if color
|
64
|
-
dt = dt.to_s unless dd.empty?
|
65
|
-
len = Log.uncolor(dt).length
|
66
|
-
|
67
|
-
if indent < 0
|
68
|
-
text = format_paragraph(dd, size, indent.abs-1, 0)
|
69
|
-
text = dt << "\n" << text
|
70
|
-
else
|
71
|
-
offset = len - indent
|
72
|
-
offset = 0 if offset < 0
|
73
|
-
text = format_paragraph(dd, size, indent.abs+1, offset)
|
74
|
-
text[0..len-1] = dt
|
75
|
-
end
|
76
|
-
text
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.format_definition_list(defs, size = 80, indent = 20, color = :yellow, sep = "\n\n")
|
80
|
-
entries = []
|
81
|
-
defs.each do |dt,dd|
|
82
|
-
text = format_definition_list_item(dt,dd,size,indent,color)
|
83
|
-
entries << text
|
84
|
-
end
|
85
|
-
entries * sep
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.camel_case(string)
|
89
|
-
return string if string !~ /_/ && string =~ /[A-Z]+.*/
|
90
|
-
string.split(/_|(\d+)/).map{|e|
|
91
|
-
(e =~ /^[A-Z]{2,}$/ ? e : e.capitalize)
|
92
|
-
}.join
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.camel_case_lower(string)
|
96
|
-
string.split('_').inject([]){ |buffer,e|
|
97
|
-
buffer.push(buffer.empty? ? e.downcase : (e =~ /^[A-Z]{2,}$/ ? e : e.capitalize))
|
98
|
-
}.join
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.snake_case(string)
|
102
|
-
return nil if string.nil?
|
103
|
-
string = string.to_s if Symbol === string
|
104
|
-
string.
|
105
|
-
gsub(/([A-Z]{2,})([A-Z][a-z])/,'\1_\2').
|
106
|
-
gsub(/([a-z])([A-Z])/,'\1_\2').
|
107
|
-
gsub(/\s/,'_').gsub(/[^\w_]/, '').
|
108
|
-
split("_").collect{|p| p.match(/[A-Z]{2,}/) ? p : p.downcase } * "_"
|
109
|
-
end
|
110
|
-
|
111
|
-
# source: https://gist.github.com/ekdevdes/2450285
|
112
|
-
# author: Ethan Kramer (https://github.com/ekdevdes)
|
113
|
-
def self.humanize(value, options = {})
|
114
|
-
if options.empty?
|
115
|
-
options[:format] = :sentence
|
116
|
-
end
|
117
|
-
|
118
|
-
values = value.to_s.split('_')
|
119
|
-
values.each_index do |index|
|
120
|
-
# lower case each item in array
|
121
|
-
# Miguel Vazquez edit: Except for acronyms
|
122
|
-
values[index].downcase! unless values[index].match(/[a-zA-Z][A-Z]/)
|
123
|
-
end
|
124
|
-
if options[:format] == :allcaps
|
125
|
-
values.each do |value|
|
126
|
-
value.capitalize!
|
127
|
-
end
|
128
|
-
|
129
|
-
if options.empty?
|
130
|
-
options[:seperator] = " "
|
131
|
-
end
|
132
|
-
|
133
|
-
return values.join " "
|
134
|
-
end
|
135
|
-
|
136
|
-
if options[:format] == :class
|
137
|
-
values.each do |value|
|
138
|
-
value.capitalize!
|
139
|
-
end
|
140
|
-
|
141
|
-
return values.join ""
|
142
|
-
end
|
143
|
-
|
144
|
-
if options[:format] == :sentence
|
145
|
-
values[0].capitalize! unless values[0].match(/[a-zA-Z][A-Z]/)
|
146
|
-
|
147
|
-
return values.join " "
|
148
|
-
end
|
149
|
-
|
150
|
-
if options[:format] == :nocaps
|
151
|
-
return values.join " "
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def self.fixascii(string)
|
156
|
-
if string.respond_to?(:encode)
|
157
|
-
self.fixutf8(string).encode("ASCII-8BIT")
|
158
|
-
else
|
159
|
-
string
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def self.to_utf8(string)
|
164
|
-
string.encode("UTF-16BE", :invalid => :replace, :undef => :replace, :replace => "?").encode('UTF-8')
|
165
|
-
end
|
166
|
-
|
167
|
-
def self.fixutf8(string)
|
168
|
-
return nil if string.nil?
|
169
|
-
return string if string.respond_to?(:encoding) && string.encoding.to_s == "UTF-8" && (string.respond_to?(:valid_encoding?) && string.valid_encoding?) ||
|
170
|
-
(string.respond_to?(:valid_encoding) && string.valid_encoding)
|
171
|
-
|
172
|
-
if string.respond_to?(:encode)
|
173
|
-
string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
174
|
-
else
|
175
|
-
require 'iconv'
|
176
|
-
@@ic ||= Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
177
|
-
@@ic.iconv(string)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def self.humanize_list(list)
|
182
|
-
return "" if list.empty?
|
183
|
-
if list.length == 1
|
184
|
-
list.first
|
185
|
-
else
|
186
|
-
list[0..-2].collect{|e| e.to_s} * ", " << " and " << list[-1].to_s
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def self.parse_sql_values(txt)
|
191
|
-
io = StringIO.new txt.strip
|
192
|
-
|
193
|
-
values = []
|
194
|
-
fields = []
|
195
|
-
current = nil
|
196
|
-
quoted = false
|
197
|
-
while c = io.getc
|
198
|
-
if quoted
|
199
|
-
if c == "'"
|
200
|
-
quoted = false
|
201
|
-
else
|
202
|
-
current << c
|
203
|
-
end
|
204
|
-
else
|
205
|
-
case c
|
206
|
-
when "("
|
207
|
-
current = ""
|
208
|
-
when ")"
|
209
|
-
fields << current
|
210
|
-
values << fields
|
211
|
-
fields = []
|
212
|
-
current = nil
|
213
|
-
when ','
|
214
|
-
if not current.nil?
|
215
|
-
fields << current
|
216
|
-
current = ""
|
217
|
-
end
|
218
|
-
when "'"
|
219
|
-
quoted = true
|
220
|
-
when ";"
|
221
|
-
break
|
222
|
-
else
|
223
|
-
current << c
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
values
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
1
|
+
require_relative 'refactor'
|
2
|
+
Rbbt.require_instead 'scout/misc/format'
|
@@ -1,107 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def self.setup(hash)
|
4
|
-
hash.extend IndiferentHash
|
5
|
-
end
|
6
|
-
|
7
|
-
def merge(other)
|
8
|
-
new = self.dup
|
9
|
-
IndiferentHash.setup(new)
|
10
|
-
other.each do |k,value|
|
11
|
-
new[k] = value
|
12
|
-
end
|
13
|
-
new
|
14
|
-
end
|
15
|
-
|
16
|
-
def []=(key,value)
|
17
|
-
delete(key)
|
18
|
-
super(key,value)
|
19
|
-
end
|
20
|
-
|
21
|
-
def _default?
|
22
|
-
@_default ||= self.default or self.default_proc
|
23
|
-
end
|
24
|
-
|
25
|
-
def [](key, *args)
|
26
|
-
res = super(key, *args)
|
27
|
-
res = IndiferentHash.setup(res) if Hash === res
|
28
|
-
return res unless res.nil? or (_default? and not keys.include? key)
|
29
|
-
|
30
|
-
case key
|
31
|
-
when Symbol, Module
|
32
|
-
res = super(key.to_s, *args)
|
33
|
-
when String
|
34
|
-
res = super(key.to_sym, *args)
|
35
|
-
end
|
36
|
-
|
37
|
-
res = IndiferentHash.setup(res) if Hash === res
|
38
|
-
|
39
|
-
res
|
40
|
-
end
|
41
|
-
|
42
|
-
def values_at(*key_list)
|
43
|
-
key_list.inject([]){|acc,key| acc << self[key]}
|
44
|
-
end
|
45
|
-
|
46
|
-
def include?(key)
|
47
|
-
case key
|
48
|
-
when Symbol, Module
|
49
|
-
super(key) || super(key.to_s)
|
50
|
-
when String
|
51
|
-
super(key) || super(key.to_sym)
|
52
|
-
else
|
53
|
-
super(key)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def delete(key)
|
58
|
-
case key
|
59
|
-
when Symbol, Module
|
60
|
-
super(key) || super(key.to_s)
|
61
|
-
when String
|
62
|
-
super(key) || super(key.to_sym)
|
63
|
-
else
|
64
|
-
super(key)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def clean_version
|
69
|
-
clean = {}
|
70
|
-
each do |k,v|
|
71
|
-
clean[k.to_s] = v unless clean.include? k.to_s
|
72
|
-
end
|
73
|
-
clean
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
module CaseInsensitiveHash
|
78
|
-
|
79
|
-
|
80
|
-
def self.setup(hash)
|
81
|
-
hash.extend CaseInsensitiveHash
|
82
|
-
end
|
83
|
-
|
84
|
-
def downcase_keys
|
85
|
-
@downcase_keys ||= begin
|
86
|
-
down = {}
|
87
|
-
keys.collect{|key|
|
88
|
-
down[key.to_s.downcase] = key
|
89
|
-
}
|
90
|
-
down
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def [](key, *rest)
|
95
|
-
value = super(key, *rest)
|
96
|
-
return value unless value.nil?
|
97
|
-
key_downcase = key.to_s.downcase
|
98
|
-
super(downcase_keys[key_downcase])
|
99
|
-
end
|
100
|
-
|
101
|
-
def values_at(*keys)
|
102
|
-
keys.collect do |key|
|
103
|
-
self[key]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
1
|
+
require_relative '../../refactor'
|
2
|
+
Rbbt.require_instead 'scout/indiferent_hash'
|