rbbt-util 2.1.0 → 3.0.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.
- data/bin/rbbt_query.rb +63 -0
- data/lib/rbbt-util.rb +5 -5
- data/lib/rbbt.rb +2 -11
- data/lib/rbbt/util/cmd.rb +1 -1
- data/lib/rbbt/util/fix_width_table.rb +9 -3
- data/lib/rbbt/util/log.rb +23 -7
- data/lib/rbbt/util/misc.rb +121 -15
- data/lib/rbbt/util/open.rb +14 -4
- data/lib/rbbt/util/persistence.rb +52 -21
- data/lib/rbbt/util/rake.rb +108 -21
- data/lib/rbbt/util/resource.rb +338 -0
- data/lib/rbbt/util/simpleDSL.rb +1 -1
- data/lib/rbbt/util/simpleopt.rb +1 -1
- data/lib/rbbt/util/task.rb +340 -0
- data/lib/rbbt/util/tc_hash.rb +19 -2
- data/lib/rbbt/util/tsv.rb +15 -10
- data/lib/rbbt/util/tsv/accessor.rb +16 -7
- data/lib/rbbt/util/tsv/attach.rb +220 -17
- data/lib/rbbt/util/tsv/index.rb +6 -1
- data/lib/rbbt/util/tsv/manipulate.rb +4 -5
- data/lib/rbbt/util/tsv/parse.rb +45 -21
- data/lib/rbbt/util/tsv/resource.rb +74 -0
- data/lib/rbbt/util/workflow.rb +99 -75
- data/test/rbbt/util/test_filecache.rb +2 -2
- data/test/rbbt/util/test_misc.rb +7 -2
- data/test/rbbt/util/test_persistence.rb +40 -5
- data/test/rbbt/util/test_resource.rb +92 -0
- data/test/rbbt/util/test_task.rb +118 -0
- data/test/rbbt/util/test_tsv.rb +5 -1
- data/test/rbbt/util/test_workflow.rb +77 -62
- data/test/rbbt/util/tsv/test_attach.rb +95 -7
- data/test/rbbt/util/tsv/test_index.rb +0 -1
- data/test/rbbt/util/tsv/test_manipulate.rb +20 -0
- data/test/rbbt/util/tsv/test_resource.rb +9 -0
- data/test/test_helper.rb +10 -0
- data/test/test_rbbt.rb +2 -37
- metadata +16 -18
- data/lib/rbbt/util/data_module.rb +0 -93
- data/lib/rbbt/util/path.rb +0 -155
- data/lib/rbbt/util/pkg_config.rb +0 -78
- data/lib/rbbt/util/pkg_data.rb +0 -119
- data/lib/rbbt/util/pkg_software.rb +0 -145
- data/test/rbbt/util/test_data_module.rb +0 -50
- data/test/rbbt/util/test_path.rb +0 -10
- data/test/rbbt/util/test_pkg_data.rb +0 -129
- data/test/test_pkg.rb +0 -28
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
require 'rbbt'
|
5
|
+
require 'rbbt/util/persistence'
|
4
6
|
require 'rbbt/util/tmpfile'
|
5
7
|
require 'rbbt/util/log'
|
6
8
|
require 'fileutils'
|
@@ -8,6 +10,14 @@ require 'fileutils'
|
|
8
10
|
class Test::Unit::TestCase
|
9
11
|
include FileUtils
|
10
12
|
|
13
|
+
def setup
|
14
|
+
Persistence.cachedir = Rbbt.tmp.test.persistence.find :user
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
FileUtils.rm_rf Rbbt.tmp.test.find :user
|
19
|
+
end
|
20
|
+
|
11
21
|
def test_datafile(file)
|
12
22
|
File.join(File.dirname(__FILE__), 'data', file)
|
13
23
|
end
|
data/test/test_rbbt.rb
CHANGED
@@ -4,42 +4,7 @@ require 'rbbt/util/misc'
|
|
4
4
|
require 'rbbt/util/open'
|
5
5
|
|
6
6
|
class TestRbbt < Test::Unit::TestCase
|
7
|
-
def
|
8
|
-
|
9
|
-
assert Rbbt.files.test_url.read =~ /html/
|
10
|
-
FileUtils.rm Rbbt.files.test_url
|
7
|
+
def test_true
|
8
|
+
assert true
|
11
9
|
end
|
12
|
-
|
13
|
-
def test_xclip
|
14
|
-
sharedir = PKGData.sharedir_for_file(__FILE__)
|
15
|
-
|
16
|
-
File.open(File.join(sharedir, 'install', 'software', 'xclip'), 'w') do |f|
|
17
|
-
f.puts '#!/bin/bash
|
18
|
-
|
19
|
-
INSTALL_HELPER_FILE="$1"
|
20
|
-
RBBT_SOFTWARE_DIR="$2"
|
21
|
-
source "$INSTALL_HELPER_FILE"
|
22
|
-
|
23
|
-
name="xclip:0.12"
|
24
|
-
url="http://downloads.sourceforge.net/project/xclip/xclip/0.12/xclip-0.12.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fxclip%2F&ts=1286472387&use_mirror=sunet"
|
25
|
-
|
26
|
-
install_src "$name" "$url"
|
27
|
-
'
|
28
|
-
end
|
29
|
-
FileUtils.chmod 0774, File.join(sharedir, 'install', 'software', 'xclip')
|
30
|
-
|
31
|
-
Rbbt.add_software :xclip => ['','']
|
32
|
-
Rbbt.find_software :xclip
|
33
|
-
assert File.exists? File.join(Rbbt.bin_dir, 'xclip')
|
34
|
-
|
35
|
-
FileUtils.rm_rf File.join(sharedir, 'install', 'software', 'xclip')
|
36
|
-
Dir.glob(File.join(Rbbt.datadir, 'software', 'opt', 'xclip','bin/*')).each do |exe|
|
37
|
-
FileUtils.rm_rf File.join(Rbbt.datadir, 'software', 'opt', 'bin', File.basename(exe))
|
38
|
-
end
|
39
|
-
Dir.glob(File.join(Rbbt.datadir, 'software', 'opt', 'xclip','current', 'bin/*')).each do |exe|
|
40
|
-
FileUtils.rm_rf File.join(Rbbt.datadir, 'software', 'opt', 'bin', File.basename(exe))
|
41
|
-
end
|
42
|
-
FileUtils.rm_rf File.join(Rbbt.datadir, 'software', 'opt', 'xclip')
|
43
|
-
end
|
44
|
-
|
45
10
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
- 1
|
7
|
+
- 3
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 2
|
10
|
+
version: 3.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Miguel Vazquez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-19 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +94,7 @@ executables:
|
|
94
94
|
- tsv.rb
|
95
95
|
- tchash.rb
|
96
96
|
- workflow.rb
|
97
|
+
- rbbt_query.rb
|
97
98
|
extensions: []
|
98
99
|
|
99
100
|
extra_rdoc_files:
|
@@ -106,21 +107,18 @@ files:
|
|
106
107
|
- lib/rbbt/util/bed.rb
|
107
108
|
- lib/rbbt/util/cachehelper.rb
|
108
109
|
- lib/rbbt/util/cmd.rb
|
109
|
-
- lib/rbbt/util/data_module.rb
|
110
110
|
- lib/rbbt/util/excel2tsv.rb
|
111
111
|
- lib/rbbt/util/filecache.rb
|
112
112
|
- lib/rbbt/util/fix_width_table.rb
|
113
113
|
- lib/rbbt/util/log.rb
|
114
114
|
- lib/rbbt/util/misc.rb
|
115
115
|
- lib/rbbt/util/open.rb
|
116
|
-
- lib/rbbt/util/path.rb
|
117
116
|
- lib/rbbt/util/persistence.rb
|
118
|
-
- lib/rbbt/util/pkg_config.rb
|
119
|
-
- lib/rbbt/util/pkg_data.rb
|
120
|
-
- lib/rbbt/util/pkg_software.rb
|
121
117
|
- lib/rbbt/util/rake.rb
|
118
|
+
- lib/rbbt/util/resource.rb
|
122
119
|
- lib/rbbt/util/simpleDSL.rb
|
123
120
|
- lib/rbbt/util/simpleopt.rb
|
121
|
+
- lib/rbbt/util/task.rb
|
124
122
|
- lib/rbbt/util/tc_hash.rb
|
125
123
|
- lib/rbbt/util/tmpfile.rb
|
126
124
|
- lib/rbbt/util/tsv.rb
|
@@ -129,24 +127,24 @@ files:
|
|
129
127
|
- lib/rbbt/util/tsv/index.rb
|
130
128
|
- lib/rbbt/util/tsv/manipulate.rb
|
131
129
|
- lib/rbbt/util/tsv/parse.rb
|
130
|
+
- lib/rbbt/util/tsv/resource.rb
|
132
131
|
- lib/rbbt/util/workflow.rb
|
133
132
|
- share/install/software/lib/install_helpers
|
134
133
|
- share/lib/R/util.R
|
135
134
|
- test/rbbt/util/test_R.rb
|
136
135
|
- test/rbbt/util/test_bed.rb
|
137
136
|
- test/rbbt/util/test_cmd.rb
|
138
|
-
- test/rbbt/util/test_data_module.rb
|
139
137
|
- test/rbbt/util/test_excel2tsv.rb
|
140
138
|
- test/rbbt/util/test_filecache.rb
|
141
139
|
- test/rbbt/util/test_fix_width_table.rb
|
142
140
|
- test/rbbt/util/test_misc.rb
|
143
141
|
- test/rbbt/util/test_open.rb
|
144
|
-
- test/rbbt/util/test_path.rb
|
145
142
|
- test/rbbt/util/test_persistence.rb
|
146
|
-
- test/rbbt/util/test_pkg_data.rb
|
147
143
|
- test/rbbt/util/test_rake.rb
|
144
|
+
- test/rbbt/util/test_resource.rb
|
148
145
|
- test/rbbt/util/test_simpleDSL.rb
|
149
146
|
- test/rbbt/util/test_simpleopt.rb
|
147
|
+
- test/rbbt/util/test_task.rb
|
150
148
|
- test/rbbt/util/test_tc_hash.rb
|
151
149
|
- test/rbbt/util/test_tmpfile.rb
|
152
150
|
- test/rbbt/util/test_tsv.rb
|
@@ -156,12 +154,13 @@ files:
|
|
156
154
|
- test/rbbt/util/tsv/test_index.rb
|
157
155
|
- test/rbbt/util/tsv/test_manipulate.rb
|
158
156
|
- test/rbbt/util/tsv/test_parse.rb
|
157
|
+
- test/rbbt/util/tsv/test_resource.rb
|
159
158
|
- test/test_helper.rb
|
160
|
-
- test/test_pkg.rb
|
161
159
|
- test/test_rbbt.rb
|
162
160
|
- bin/tsv.rb
|
163
161
|
- bin/tchash.rb
|
164
162
|
- bin/workflow.rb
|
163
|
+
- bin/rbbt_query.rb
|
165
164
|
has_rdoc: true
|
166
165
|
homepage: http://github.com/mikisvaz/rbbt-util
|
167
166
|
licenses: []
|
@@ -200,18 +199,17 @@ test_files:
|
|
200
199
|
- test/rbbt/util/test_R.rb
|
201
200
|
- test/rbbt/util/test_bed.rb
|
202
201
|
- test/rbbt/util/test_cmd.rb
|
203
|
-
- test/rbbt/util/test_data_module.rb
|
204
202
|
- test/rbbt/util/test_excel2tsv.rb
|
205
203
|
- test/rbbt/util/test_filecache.rb
|
206
204
|
- test/rbbt/util/test_fix_width_table.rb
|
207
205
|
- test/rbbt/util/test_misc.rb
|
208
206
|
- test/rbbt/util/test_open.rb
|
209
|
-
- test/rbbt/util/test_path.rb
|
210
207
|
- test/rbbt/util/test_persistence.rb
|
211
|
-
- test/rbbt/util/test_pkg_data.rb
|
212
208
|
- test/rbbt/util/test_rake.rb
|
209
|
+
- test/rbbt/util/test_resource.rb
|
213
210
|
- test/rbbt/util/test_simpleDSL.rb
|
214
211
|
- test/rbbt/util/test_simpleopt.rb
|
212
|
+
- test/rbbt/util/test_task.rb
|
215
213
|
- test/rbbt/util/test_tc_hash.rb
|
216
214
|
- test/rbbt/util/test_tmpfile.rb
|
217
215
|
- test/rbbt/util/test_tsv.rb
|
@@ -221,6 +219,6 @@ test_files:
|
|
221
219
|
- test/rbbt/util/tsv/test_index.rb
|
222
220
|
- test/rbbt/util/tsv/test_manipulate.rb
|
223
221
|
- test/rbbt/util/tsv/test_parse.rb
|
222
|
+
- test/rbbt/util/tsv/test_resource.rb
|
224
223
|
- test/test_helper.rb
|
225
|
-
- test/test_pkg.rb
|
226
224
|
- test/test_rbbt.rb
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module DataModule
|
2
|
-
|
3
|
-
def self.rakefiles(sharedir, data_module)
|
4
|
-
Dir.glob(File.join(sharedir, 'install', data_module.to_s, '**','Rakefile')).collect{|f| File.expand_path f}
|
5
|
-
end
|
6
|
-
|
7
|
-
attr_accessor :sharedir, :rakefile, :pkg_module
|
8
|
-
def self.extended(data_module)
|
9
|
-
if defined? data_module::PKG and data_module::PKG
|
10
|
-
data_module.pkg_module = data_module::PKG
|
11
|
-
else
|
12
|
-
data_module.pkg_module = Rbbt
|
13
|
-
end
|
14
|
-
|
15
|
-
data_module.sharedir = PKGData.get_caller_sharedir
|
16
|
-
|
17
|
-
install_dir = File.join(data_module.sharedir, 'install')
|
18
|
-
rake_sharedir = File.join(data_module.sharedir, 'install')
|
19
|
-
|
20
|
-
rakefiles(data_module.sharedir, data_module).each do |rakefile|
|
21
|
-
rakefile_dir = File.dirname(rakefile)
|
22
|
-
|
23
|
-
RakeHelper.files(rakefile).each do |file|
|
24
|
-
file_path = Misc.path_relative_to(File.join(File.dirname(rakefile), file), rakefile_dir)
|
25
|
-
get = :Rakefile
|
26
|
-
subdir = Misc.path_relative_to(File.dirname(rakefile), install_dir)
|
27
|
-
namespace = data_module.to_s.gsub('/', '::')
|
28
|
-
|
29
|
-
data_module.pkg_module.claim file_path, get, subdir, namespace, rake_sharedir
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def files
|
35
|
-
DataModule.rakefiles(sharedir, self).collect do |rakefile|
|
36
|
-
RakeHelper.files(rakefile).collect
|
37
|
-
end.flatten
|
38
|
-
end
|
39
|
-
|
40
|
-
def datadir
|
41
|
-
File.join(pkg_module.datadir, self.to_s)
|
42
|
-
end
|
43
|
-
|
44
|
-
module WithKey
|
45
|
-
def klass=(klass)
|
46
|
-
@klass = klass
|
47
|
-
end
|
48
|
-
|
49
|
-
def klass
|
50
|
-
@klass
|
51
|
-
end
|
52
|
-
|
53
|
-
def key=(key)
|
54
|
-
@key = key
|
55
|
-
end
|
56
|
-
|
57
|
-
def key
|
58
|
-
@key
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_missing(name, *args)
|
62
|
-
if key
|
63
|
-
klass.send(name, key, *args)
|
64
|
-
else
|
65
|
-
klass.send(name, *args)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def with_key(key)
|
71
|
-
klass = self
|
72
|
-
o = Object.new
|
73
|
-
o.extend WithKey
|
74
|
-
o.klass = self
|
75
|
-
o.key = key
|
76
|
-
o
|
77
|
-
end
|
78
|
-
|
79
|
-
alias old_method_missing method_missing
|
80
|
-
def method_missing(name, *args, &block)
|
81
|
-
begin
|
82
|
-
if args.any?
|
83
|
-
pkg_module.files[self.to_s][args.first][name]
|
84
|
-
else
|
85
|
-
pkg_module.files[self.to_s][name]
|
86
|
-
end
|
87
|
-
rescue
|
88
|
-
Log.debug $!.message
|
89
|
-
Log.debug $!.backtrace * "\n"
|
90
|
-
old_method_missing name, *args, &block
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
data/lib/rbbt/util/path.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'rbbt/util/misc'
|
2
|
-
require 'rbbt/util/tsv'
|
3
|
-
|
4
|
-
module Path
|
5
|
-
attr_accessor :pkg_module, :datadir
|
6
|
-
|
7
|
-
def self.find_files_back_to(path, target, subdir)
|
8
|
-
return [] if path.nil?
|
9
|
-
raise "Path #{ path } not in directory #{ subdir }" if not Misc.in_directory? path, subdir
|
10
|
-
|
11
|
-
pkg_module = path.pkg_module
|
12
|
-
|
13
|
-
files = []
|
14
|
-
while path != subdir
|
15
|
-
path = File.dirname(path)
|
16
|
-
path.extend Path
|
17
|
-
path.pkg_module = pkg_module
|
18
|
-
path.datadir = path.datadir
|
19
|
-
if path[target].exists?
|
20
|
-
files << path[target]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
files
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.path(string, datadir = nil, pkg_module = nil)
|
28
|
-
string.extend Path
|
29
|
-
string.datadir = datadir
|
30
|
-
string.pkg_module = case
|
31
|
-
when pkg_module.nil?
|
32
|
-
nil
|
33
|
-
when String === pkg_module
|
34
|
-
Misc.string2const pkg_module
|
35
|
-
else
|
36
|
-
pkg_module
|
37
|
-
end
|
38
|
-
string
|
39
|
-
end
|
40
|
-
|
41
|
-
def method_missing(name, *args, &block)
|
42
|
-
new = File.join(self.dup, name.to_s)
|
43
|
-
new.extend Path
|
44
|
-
new.pkg_module = pkg_module
|
45
|
-
new.datadir = datadir
|
46
|
-
new
|
47
|
-
end
|
48
|
-
|
49
|
-
def [](name)
|
50
|
-
new = File.join(self.dup, name.to_s)
|
51
|
-
new.extend Path
|
52
|
-
new.pkg_module = pkg_module
|
53
|
-
new.datadir = datadir
|
54
|
-
new
|
55
|
-
end
|
56
|
-
|
57
|
-
def namespace
|
58
|
-
return nil if self.nil? or self.empty? or (not datadir.nil? and (self == datadir or File.dirname(self) == datadir))
|
59
|
-
if File.directory? self
|
60
|
-
File.basename(self)
|
61
|
-
else
|
62
|
-
File.basename(File.dirname(self))
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def identifier_files
|
67
|
-
if datadir.nil?
|
68
|
-
path = File.join(File.dirname(self), 'identifiers')
|
69
|
-
path.extend Path
|
70
|
-
path.pkg_module = pkg_module
|
71
|
-
if path.exists?
|
72
|
-
[path]
|
73
|
-
else
|
74
|
-
[]
|
75
|
-
end
|
76
|
-
else
|
77
|
-
identifier_files = Path.find_files_back_to(self, 'identifiers', datadir)
|
78
|
-
return identifier_files.collect{|f| Path.path(f, datadir, pkg_module)}
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def tsv(key = nil, options = {})
|
83
|
-
if options.empty? and Hash === key
|
84
|
-
options, key = key, nil
|
85
|
-
end
|
86
|
-
|
87
|
-
produce
|
88
|
-
TSV.new self, key, options.merge(:datadir => datadir)
|
89
|
-
end
|
90
|
-
|
91
|
-
def index(options = {})
|
92
|
-
produce
|
93
|
-
TSV.index self, options
|
94
|
-
end
|
95
|
-
|
96
|
-
def open(options = {})
|
97
|
-
produce
|
98
|
-
Open.open(self, options)
|
99
|
-
end
|
100
|
-
|
101
|
-
def read(options = {})
|
102
|
-
produce
|
103
|
-
Open.read(self, options)
|
104
|
-
end
|
105
|
-
|
106
|
-
def fields(sep = nil, header_hash = nil)
|
107
|
-
produce
|
108
|
-
TSV.parse_header(self.open, sep, header_hash)[1].collect{|f| f.extend TSV::Field; f.namespace = namespace ;f}
|
109
|
-
end
|
110
|
-
|
111
|
-
def all_fields(sep = nil, header_hash = nil)
|
112
|
-
produce
|
113
|
-
key_field, fields = TSV.parse_header(self.open, sep, header_hash).values_at(0, 1).flatten.collect{|f| f.extend TSV::Field; f.namespace = namespace; f}
|
114
|
-
end
|
115
|
-
|
116
|
-
def fields_in_namespace(sep = nil, header_hash = nil)
|
117
|
-
produce
|
118
|
-
TSV.parse_header(self.open, sep, header_hash)[1].collect{|f| f.extend TSV::Field; f.namespace = namespace ;f}.select{|f| f.namespace == namespace}
|
119
|
-
end
|
120
|
-
|
121
|
-
def all_namespace_fields(sep = nil, header_hash = nil)
|
122
|
-
produce
|
123
|
-
key_field, fields = TSV.parse_header(self.open, sep, header_hash).values_at(0, 1).flatten.collect{|f| f.extend TSV::Field; f.namespace = namespace; f}.select{|f| f.namespace == namespace}
|
124
|
-
end
|
125
|
-
|
126
|
-
def filename
|
127
|
-
self.to_s
|
128
|
-
end
|
129
|
-
|
130
|
-
def exists?
|
131
|
-
begin
|
132
|
-
produce
|
133
|
-
true
|
134
|
-
rescue
|
135
|
-
false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def produce
|
140
|
-
return self if File.exists? self
|
141
|
-
|
142
|
-
raise "No especified pkg_data for file #{ self }, cannot produce" if pkg_data.nil?
|
143
|
-
|
144
|
-
Log.debug("Trying to produce '#{ self }'")
|
145
|
-
file, producer = pkg_module.reclaim self
|
146
|
-
|
147
|
-
raise "File #{self} has not been claimed, cannot produce" if file.nil? or producer.nil?
|
148
|
-
|
149
|
-
pkg_module.produce(self, producer[:get], producer[:subdir], producer[:sharedir])
|
150
|
-
|
151
|
-
self
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
|
data/lib/rbbt/util/pkg_config.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module PKGConfig
|
4
|
-
class NoConfig < Exception; end
|
5
|
-
class NoVariables < Exception; end
|
6
|
-
|
7
|
-
class RootdirNotFoundError < StandardError; end
|
8
|
-
|
9
|
-
def self.rootdir_for_file(file = __FILE__)
|
10
|
-
dir = File.expand_path(File.dirname file)
|
11
|
-
|
12
|
-
while not File.exists?(File.join(dir, 'lib')) and dir != '/'
|
13
|
-
dir = File.dirname(dir)
|
14
|
-
end
|
15
|
-
|
16
|
-
if File.exists? File.join(dir, 'lib')
|
17
|
-
dir
|
18
|
-
else
|
19
|
-
raise RootdirNotFoundError
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.get_caller_rootdir
|
24
|
-
caller.each do |line|
|
25
|
-
next if line =~ /\/pkg_config\.rb/
|
26
|
-
begin
|
27
|
-
return PKGConfig.rootdir_for_file(line)
|
28
|
-
rescue RootdirNotFoundError
|
29
|
-
end
|
30
|
-
end
|
31
|
-
raise RootdirNotFoundError
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def self.extended(base)
|
36
|
-
base.module_eval{ @@rootdir = PKGConfig.get_caller_rootdir}
|
37
|
-
end
|
38
|
-
|
39
|
-
def rootdir
|
40
|
-
@@rootdir
|
41
|
-
end
|
42
|
-
|
43
|
-
def load_config(file, pkg_variables)
|
44
|
-
config = YAML.load_file(file)
|
45
|
-
|
46
|
-
pkg_variables.each do |variable|
|
47
|
-
self.send("#{variable}=", config[variable])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_cfg(pkg_variables, default = nil)
|
52
|
-
pkg_cfg_files = [ ENV['RBBT_CONFIG'] || "",
|
53
|
-
File.join(ENV["HOME"], '.' + self.to_s),
|
54
|
-
File.join('/etc/', '.' + self.to_s)]
|
55
|
-
|
56
|
-
pkg_variables.each do |variable|
|
57
|
-
self.class_eval %{
|
58
|
-
def self.#{variable}
|
59
|
-
@#{variable}
|
60
|
-
end
|
61
|
-
def self.#{variable}=(value)
|
62
|
-
@#{variable} = value
|
63
|
-
end
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
file = pkg_cfg_files.select{|file| File.exists? file}.first
|
68
|
-
if file.nil?
|
69
|
-
if default
|
70
|
-
file = pkg_cfg_files[1]
|
71
|
-
Open.write(file, default)
|
72
|
-
else
|
73
|
-
raise NoConfig, "No config file found. [#{pkg_cfg_files * ", "}]" if file.nil?
|
74
|
-
end
|
75
|
-
end
|
76
|
-
load_config file, pkg_variables
|
77
|
-
end
|
78
|
-
end
|