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.
Files changed (46) hide show
  1. data/bin/rbbt_query.rb +63 -0
  2. data/lib/rbbt-util.rb +5 -5
  3. data/lib/rbbt.rb +2 -11
  4. data/lib/rbbt/util/cmd.rb +1 -1
  5. data/lib/rbbt/util/fix_width_table.rb +9 -3
  6. data/lib/rbbt/util/log.rb +23 -7
  7. data/lib/rbbt/util/misc.rb +121 -15
  8. data/lib/rbbt/util/open.rb +14 -4
  9. data/lib/rbbt/util/persistence.rb +52 -21
  10. data/lib/rbbt/util/rake.rb +108 -21
  11. data/lib/rbbt/util/resource.rb +338 -0
  12. data/lib/rbbt/util/simpleDSL.rb +1 -1
  13. data/lib/rbbt/util/simpleopt.rb +1 -1
  14. data/lib/rbbt/util/task.rb +340 -0
  15. data/lib/rbbt/util/tc_hash.rb +19 -2
  16. data/lib/rbbt/util/tsv.rb +15 -10
  17. data/lib/rbbt/util/tsv/accessor.rb +16 -7
  18. data/lib/rbbt/util/tsv/attach.rb +220 -17
  19. data/lib/rbbt/util/tsv/index.rb +6 -1
  20. data/lib/rbbt/util/tsv/manipulate.rb +4 -5
  21. data/lib/rbbt/util/tsv/parse.rb +45 -21
  22. data/lib/rbbt/util/tsv/resource.rb +74 -0
  23. data/lib/rbbt/util/workflow.rb +99 -75
  24. data/test/rbbt/util/test_filecache.rb +2 -2
  25. data/test/rbbt/util/test_misc.rb +7 -2
  26. data/test/rbbt/util/test_persistence.rb +40 -5
  27. data/test/rbbt/util/test_resource.rb +92 -0
  28. data/test/rbbt/util/test_task.rb +118 -0
  29. data/test/rbbt/util/test_tsv.rb +5 -1
  30. data/test/rbbt/util/test_workflow.rb +77 -62
  31. data/test/rbbt/util/tsv/test_attach.rb +95 -7
  32. data/test/rbbt/util/tsv/test_index.rb +0 -1
  33. data/test/rbbt/util/tsv/test_manipulate.rb +20 -0
  34. data/test/rbbt/util/tsv/test_resource.rb +9 -0
  35. data/test/test_helper.rb +10 -0
  36. data/test/test_rbbt.rb +2 -37
  37. metadata +16 -18
  38. data/lib/rbbt/util/data_module.rb +0 -93
  39. data/lib/rbbt/util/path.rb +0 -155
  40. data/lib/rbbt/util/pkg_config.rb +0 -78
  41. data/lib/rbbt/util/pkg_data.rb +0 -119
  42. data/lib/rbbt/util/pkg_software.rb +0 -145
  43. data/test/rbbt/util/test_data_module.rb +0 -50
  44. data/test/rbbt/util/test_path.rb +0 -10
  45. data/test/rbbt/util/test_pkg_data.rb +0 -129
  46. data/test/test_pkg.rb +0 -28
@@ -1,119 +0,0 @@
1
- require 'rbbt/util/open'
2
- require 'rbbt/util/tsv'
3
- require 'rbbt/util/log'
4
- require 'rbbt/util/path'
5
- require 'rbbt/util/rake'
6
-
7
- module PKGData
8
- attr_accessor :claims
9
- def self.extended(pkg_module)
10
- pkg_module.claims = {}
11
- end
12
-
13
- class SharedirNotFoundError < StandardError; end
14
-
15
- def self.sharedir_for_file(file = __FILE__)
16
- dir = File.expand_path(File.dirname file)
17
-
18
- while not File.exists?(File.join(dir, 'lib')) and dir != '/'
19
- dir = File.dirname(dir)
20
- end
21
-
22
- if File.exists? File.join(dir, 'lib')
23
- File.join(dir, 'share')
24
- else
25
- raise SharedirNotFoundError
26
- end
27
- end
28
-
29
- def self.get_caller_sharedir
30
- caller.each do |line|
31
- next if line =~ /\/data_module\.rb/ or line =~ /\/pkg_data\.rb/
32
- begin
33
- return PKGData.sharedir_for_file(line)
34
- rescue SharedirNotFoundError
35
- end
36
- end
37
- raise SharedirNotFoundError
38
- end
39
-
40
- def files
41
- path = datadir.dup.extend Path
42
- path.pkg_module = self
43
- path.datadir = datadir
44
- path
45
- end
46
-
47
- def in_datadir?(file)
48
- Misc.in_directory? file, datadir
49
- end
50
-
51
- # file is the complete path of the file inside the datadir
52
- # get is the get method. :Rakefile for
53
- def claim(file, get = nil, subdir = nil, namespace = nil, sharedir = nil)
54
- file = case
55
- when (file.nil? or file === :all)
56
- File.join(datadir, subdir.to_s)
57
- when in_datadir?(file)
58
- file
59
- else
60
- File.join(datadir, subdir.to_s, file.to_s)
61
- end
62
-
63
- sharedir ||= PKGData.get_caller_sharedir
64
- claims[file] = {:get => get, :subdir => subdir, :sharedir => sharedir, :namespace => namespace}
65
- produce(file, get, subdir, sharedir) if TSV === get
66
- produce(file, get, subdir, sharedir) if String === get and not File.exists?(get) and reclaim(file).nil? and not File.basename(get.to_s) == "Rakefile"
67
- end
68
-
69
- def reclaim(file)
70
- file = File.expand_path(file.dup)
71
- return nil unless in_datadir? file
72
-
73
- while file != File.expand_path(datadir)
74
- if @claims[file]
75
- return [file, @claims[file]]
76
- end
77
- file = File.dirname(file)
78
- end
79
- nil
80
- end
81
-
82
- def declaim(file)
83
- @claims.delete file if @claims.include? file
84
- end
85
-
86
- def produce_with_rake(rakefile, subdir, file)
87
- task = File.expand_path(file).sub(/^.*#{Regexp.quote(File.join(datadir, subdir))}\/?/, '')
88
- RakeHelper.run(rakefile, task, File.join(File.join(datadir, subdir)))
89
- end
90
-
91
- def produce(file, get, subdir, sharedir)
92
- Log.low "Getting data file '#{ file }' into '#{ subdir }'. Get: #{get.class}"
93
-
94
- FileUtils.mkdir_p File.dirname(file) unless File.exists?(File.dirname(file))
95
-
96
- relative_path = Misc.path_relative_to file, datadir
97
- case
98
- when get.nil?
99
- FileUtils.cp File.join(sharedir, relative_path), file.to_s
100
- when StringIO === get
101
- Open.write(file, get.read)
102
- when Proc === get
103
- Open.write(file, get.call)
104
- when TSV === get
105
- Open.write(file, get.to_s)
106
- when ((String === get or Symbol === get) and File.basename(get.to_s) == "Rakefile")
107
- if Symbol === get
108
- rakefile = File.join(sharedir, subdir, get.to_s)
109
- else
110
- rakefile = File.join(sharedir, get.to_s)
111
- end
112
- produce_with_rake(rakefile, subdir, file)
113
- when (String === get and Open.remote? get)
114
- Open.write(file, Open.read(get, :wget_options => {:pipe => true}, :nocache => true))
115
- else
116
- raise "Unknown Get: #{get.class} #{get}"
117
- end
118
- end
119
- end
@@ -1,145 +0,0 @@
1
- require 'rbbt/util/open'
2
- require 'rbbt/util/misc'
3
- require 'rbbt/util/tsv'
4
- require 'rbbt/util/log'
5
- require 'rbbt/util/cmd'
6
- require 'rake'
7
-
8
- module PKGSoftware
9
- SOFTWARE = {} unless defined? SOFTWARE
10
-
11
- class SharedirNotFoundError < StandardError; end
12
-
13
- def self.sharedir_for_file(file = __FILE__)
14
- dir = File.expand_path(File.dirname file)
15
-
16
- while not File.exists?(File.join(dir, 'lib')) and dir != '/'
17
- dir = File.dirname(dir)
18
- end
19
-
20
- if File.exists? File.join(dir, 'lib')
21
- File.join(dir, 'share')
22
- else
23
- raise SharedirNotFoundError
24
- end
25
- end
26
-
27
- def self.get_caller_sharedir
28
- caller.each do |line|
29
- next if line =~ /\/data_module\.rb/ or line =~ /\/pkg_software\.rb/
30
- begin
31
- return PKGData.sharedir_for_file(line)
32
- rescue SharedirNotFoundError
33
- end
34
- end
35
- raise SharedirNotFoundError
36
- end
37
-
38
- def software_dir
39
- File.join(datadir, 'software')
40
- end
41
-
42
- def opt_dir
43
- File.join(software_dir, 'opt')
44
- end
45
-
46
- def bin_dir
47
- File.join(opt_dir, 'bin')
48
- end
49
-
50
-
51
- def get_pkg(pkg, path, get, sharedir)
52
- Log.log "Getting software '#{ pkg }' into '#{ path }'. Get: #{get.to_s}"
53
-
54
- FileUtils.mkdir_p File.dirname(path) unless File.exists?(File.dirname(path))
55
-
56
- case
57
- when get == :directory
58
- FileUtils.mkdir_p File.dirname(path) unless File.exists? File.dirname(path)
59
- subdir = Misc.path_relative_to File.dirname(path), opt_dir
60
- source = File.join(sharedir, 'install/software', subdir, pkg)
61
-
62
- FileUtils.cp_r File.join(sharedir, 'install/software', subdir, pkg), path
63
- when get == :binary
64
- FileUtils.mkdir_p File.dirname(path) unless File.exists? File.dirname(path)
65
- subdir = Misc.path_relative_to File.dirname(path), opt_dir
66
- source = File.join(sharedir, 'install/software', subdir, pkg)
67
-
68
- FileUtils.cp File.join(sharedir, 'install/software', subdir, pkg), path
69
- when (get.nil? or get.empty?)
70
- CMD.cmd("#{File.join(sharedir, 'install', 'software', pkg)} #{File.join(Rbbt.rootdir, 'share/install/software/lib', 'install_helpers')} #{software_dir}", :stderr => Log::HIGH)
71
- else
72
- CMD.cmd("#{File.join(sharedir, 'install', 'software', get)} #{File.join(Rbbt.rootdir, 'share/install/software/lib', 'install_helpers')} #{software_dir}")
73
- end
74
- end
75
-
76
- def add_software(pkgs = {})
77
- pkgs.each do |pkg, info|
78
- subpath, get, sharedir = info
79
-
80
- setup_env(software_dir)
81
-
82
- path = File.join(opt_dir, subpath.to_s, pkg.to_s)
83
-
84
- if not File.exists?(path)
85
- sharedir ||= PKGSoftware.get_caller_sharedir
86
- get_pkg(pkg.to_s, path, get, sharedir)
87
- setup_env(software_dir)
88
- end
89
-
90
- SOFTWARE[pkg.to_s] = path
91
- end
92
- end
93
-
94
- def find_software(pkg)
95
- SOFTWARE[pkg.to_s]
96
- end
97
-
98
- def setup_env(software_dir)
99
- Misc.env_add 'PATH', bin_dir
100
-
101
- FileUtils.mkdir_p opt_dir unless File.exists? opt_dir
102
- %w(.ld-paths .pkgconfig-paths .aclocal-paths .java-classpaths).each do |file|
103
- filename = File.join(opt_dir, file)
104
- FileUtils.touch filename unless File.exists? filename
105
- end
106
-
107
- if not File.exists? File.join(opt_dir,'.post_install')
108
- Open.write(File.join(opt_dir,'.post_install'),"#!/bin/bash\n")
109
- end
110
-
111
- Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line|
112
- Misc.env_add('LD_LIBRARY_PATH',line.chomp)
113
- Misc.env_add('LD_RUN_PATH',line.chomp)
114
- end
115
-
116
- Open.read(File.join opt_dir, '.pkgconfig-paths').split(/\n/).each do |line|
117
- Misc.env_add('PKG_CONFIG_PATH',line.chomp)
118
- end
119
-
120
- Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line|
121
- Misc.env_add('LD_LIBRARY_PATH',line.chomp)
122
- end
123
-
124
- Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line|
125
- Misc.env_add('LD_LIBRARY_PATH',line.chomp)
126
- end
127
-
128
- Open.read(File.join opt_dir, '.aclocal-paths').split(/\n/).each do |line|
129
- Misc.env_add('ACLOCAL_FLAGS', "-I#{File.join(opt_dir, line.chomp)}", ' ')
130
- end
131
-
132
- Open.read(File.join opt_dir, '.java-classpaths').split(/\n/).each do |line|
133
- Misc.env_add('CLASSPATH', "#{File.join(opt_dir,'java', 'lib', line.chomp)}")
134
- end
135
-
136
- Dir.glob(File.join opt_dir, 'jars', '*').each do |file|
137
- Misc.env_add('CLASSPATH', "#{File.expand_path(file)}")
138
- end
139
-
140
- File.chmod 0774, File.join(opt_dir, '.post_install')
141
-
142
- CMD.cmd(File.join(opt_dir, '.post_install'))
143
- end
144
-
145
- end
@@ -1,50 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
- require 'rbbt'
3
- require 'rbbt/util/data_module'
4
- require 'test/unit'
5
- require 'fileutils'
6
-
7
- SHAREDIR = File.join(PKGData.sharedir_for_file(__FILE__), 'install/DataTest')
8
- FileUtils.mkdir_p SHAREDIR
9
- File.open(File.join(SHAREDIR, 'Rakefile'), 'w') do |f|
10
- f.puts "file :file1 do |t| File.open(t.name, 'w') do |f| f.write 'File 1' end end"
11
- f.puts "file :tsv_file do |t| File.open(t.name, 'w') do |f| f.write 'a\t1\nb\t2\n' end end"
12
- end
13
-
14
- module DataTest
15
- extend DataModule
16
-
17
- def self.salute(name)
18
- "Hello #{name}"
19
- end
20
-
21
- World = with_key("world")
22
- end
23
-
24
- class TestDataModule < Test::Unit::TestCase
25
-
26
- def setup
27
-
28
- FileUtils.mkdir_p SHAREDIR
29
- File.open(File.join(SHAREDIR, 'Rakefile'), 'w') do |f|
30
- f.puts "file :file1 do |t| File.open(t.name, 'w') do |f| f.write 'File 1' end end"
31
- f.puts "file :tsv_file do |t| File.open(t.name, 'w') do |f| f.write 'a\t1\nb\t2\n' end end"
32
- end
33
- end
34
-
35
- def test_rakefile
36
- assert_equal Rbbt.files.DataTest, DataTest.datadir
37
- assert_equal "File 1", Rbbt.files.DataTest.file1.read
38
- assert_equal "Hello world", DataTest.salute("world")
39
- assert_equal "Hello world", DataTest::with_key("world").salute
40
- assert_equal "Hello world", DataTest::World.salute
41
- assert_equal "DataTest", Rbbt.files.DataTest.tsv_file.namespace
42
- assert_equal "DataTest", Rbbt.files.DataTest.tsv_file.tsv.namespace
43
- FileUtils.rm_rf File.join(Rbbt.datadir, 'DataTest')
44
- end
45
-
46
- def teardown
47
- FileUtils.rm_rf SHAREDIR
48
- end
49
- end
50
-
@@ -1,10 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt'
3
- require 'rbbt/util/path'
4
-
5
- class TestPath < Test::Unit::TestCase
6
- def test_namespace
7
- assert_equal nil, Rbbt.files.foo.namespace
8
- end
9
- end
10
-
@@ -1,129 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt'
3
- require 'rbbt/util/pkg_data'
4
-
5
- class TestPKGData < Test::Unit::TestCase
6
- def test_claims
7
- begin
8
- assert Rbbt.claims.empty?
9
- Rbbt.claim :foo, "bar"
10
- assert_equal 1, Rbbt.claims.length
11
- rescue
12
- Rbbt.declaim Rbbt.files.foo
13
- end
14
- end
15
-
16
- def test_claim_proc
17
- begin
18
- assert_nil Rbbt.reclaim(Rbbt.files.foo)
19
-
20
- Rbbt.claim :foo, proc{"bar"}
21
- assert_not_nil Rbbt.reclaim Rbbt.files.foo
22
-
23
- assert Hash === Rbbt.reclaim(Rbbt.files.foo).last
24
- assert_equal "bar", Rbbt.files.foo.read
25
- ensure
26
- Rbbt.declaim Rbbt.files.foo
27
- FileUtils.rm Rbbt.files.foo
28
- end
29
- end
30
-
31
- def test_claim_cp
32
- begin
33
- Open.write File.join(Rbbt.rootdir, 'share', 'foo'), "bar"
34
- Rbbt.claim :foo
35
- assert_equal "bar", Rbbt.files.foo.read
36
- ensure
37
- Rbbt.declaim Rbbt.files.foo
38
- FileUtils.rm Rbbt.files.foo if File.exists? Rbbt.files.foo
39
- FileUtils.rm File.join(Rbbt.rootdir, 'share', 'foo') if File.exists? File.join(Rbbt.rootdir, 'share', 'foo')
40
- end
41
- end
42
-
43
- def test_claim_tsv
44
- begin
45
- Rbbt.claim :foo, TSV.new({:a => 1, :b => 2})
46
- assert File.exists? Rbbt.files.foo
47
- assert_equal "1", Rbbt.files.foo.tsv(:type => :single)["a"]
48
- ensure
49
- FileUtils.rm Rbbt.files.foo if File.exists? Rbbt.files.foo
50
- end
51
- end
52
-
53
- def test_claim_rakefile
54
- begin
55
- FileUtils.mkdir_p File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/')
56
- Open.write(File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile'), "file :foo do |t| Open.write(t.name, 'bar') end")
57
- Rbbt.claim :foo, :Rakefile, 'test/Rake'
58
- assert_equal "bar", Rbbt.files.test.Rake.foo.read
59
- ensure
60
- begin
61
- FileUtils.rm File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile')
62
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake')
63
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test')
64
- FileUtils.rm Rbbt.files.test.Rake.foo
65
- FileUtils.rm_r Rbbt.files.test.Rake
66
- FileUtils.rm_r Rbbt.files.test
67
- rescue
68
- end
69
- end
70
- end
71
-
72
- def test_claim_rakefile2
73
- begin
74
- FileUtils.mkdir_p File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/')
75
- Open.write(File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile'), "file :foo do |t| Open.write(t.name, 'bar') end")
76
- Rbbt.claim :foo, "test/Rake/Rakefile", 'test'
77
- assert_equal "bar", Rbbt.files.test.foo.read
78
- ensure
79
- begin
80
- FileUtils.rm File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile')
81
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake')
82
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test')
83
- FileUtils.rm Rbbt.files.test.foo
84
- FileUtils.rm_r Rbbt.files.test
85
- rescue
86
- end
87
- end
88
- end
89
-
90
- def test_claim_rakefile3
91
- begin
92
- FileUtils.mkdir_p File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/')
93
- Open.write(File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile'), "file :foo do |t| Open.write(t.name, 'bar') end")
94
- Rbbt.claim :all, "test/Rake/Rakefile", 'test'
95
- assert_equal "bar", Rbbt.files.test.foo.read
96
- ensure
97
- begin
98
- FileUtils.rm File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile')
99
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake')
100
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test')
101
- FileUtils.rm Rbbt.files.test.foo
102
- FileUtils.rm_r Rbbt.files.test
103
- rescue
104
- end
105
- end
106
- end
107
-
108
- def test_claim_namespace_identifiers
109
- begin
110
- FileUtils.mkdir_p File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/')
111
- Open.write(File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile'), "
112
- file :foo do |t| Open.write(t.name, 'bar') end
113
- file :identifiers do |t| Open.write(t.name, 'bar') end
114
- ")
115
- Rbbt.claim :all, "test/Rake/Rakefile", 'test'
116
- assert_equal 1, Rbbt.files.test.foo.identifier_files.length
117
- ensure
118
- begin
119
- FileUtils.rm File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake/Rakefile')
120
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test/Rake')
121
- FileUtils.rmdir File.join(PKGData.sharedir_for_file(__FILE__), 'test')
122
- FileUtils.rm Rbbt.files.test.foo
123
- FileUtils.rm_r Rbbt.files.test
124
- rescue
125
- end
126
- end
127
- end
128
- end
129
-