bj 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bj/util.rb ADDED
@@ -0,0 +1,81 @@
1
+ class Bj
2
+ module Util
3
+ module ModuleMethods
4
+ def constant_get const, &block
5
+ begin
6
+ ancestors = const.split(%r/::/)
7
+ parent = Object
8
+ while((child = ancestors.shift))
9
+ klass = parent.const_get child
10
+ parent = klass
11
+ end
12
+ klass
13
+ rescue
14
+ block ? block.call : raise
15
+ end
16
+ end
17
+
18
+ def const_or_env const, &block
19
+ constant_get(const){ ENV[const] || block.call }
20
+ end
21
+
22
+ def spawn cmd, options = {}
23
+ options.to_options!
24
+ logger = options[:logger] || Bj.logger
25
+ logger.info{ "cmd <#{ cmd }>" } if logger
26
+ status = systemu cmd, 1=>(stdout=""), 2=>(stderr="")
27
+ logger.info{ "status <#{ status.exitstatus }>" } if logger
28
+ status.exitstatus.zero? or raise "#{ cmd.inspect } failed with #{ $?.inspect }"
29
+ [ stdout, stderr ]
30
+ end
31
+
32
+ def alive pid
33
+ return false unless pid
34
+ pid = Integer pid.to_s
35
+ Process::kill 0, pid
36
+ true
37
+ rescue Errno::ESRCH, Errno::EPERM
38
+ false
39
+ end
40
+ alias_method "alive?", "alive"
41
+
42
+ def ping pid, options = {}
43
+ return false unless pid
44
+ pid = Integer pid
45
+ signal = options[:signal] || 'SIGHUP'
46
+ begin
47
+ Process::kill signal, pid
48
+ pid
49
+ rescue Exception
50
+ false
51
+ end
52
+ end
53
+
54
+ def which_ruby
55
+ c = ::Config::CONFIG
56
+ ruby = File::join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
57
+ raise "ruby @ #{ ruby } not executable!?" unless test(?e, ruby)
58
+ ruby
59
+ end
60
+
61
+ def find_script basename
62
+ path = ENV["PATH"] || ENV["path"]
63
+ raise "no env PATH" unless path
64
+ path = path.split File::PATH_SEPARATOR
65
+ path.push File.join(Bj.rails_root, "script")
66
+ path.each do |directory|
67
+ script = File.join directory, basename
68
+ return File.expand_path(script) if(test(?s, script) and test(?r, script))
69
+ end
70
+ raise "no #{ basename } found in #{ path.inspect }"
71
+ end
72
+
73
+ def valid_rails_root root = ".", expected = %w[ config script app ]
74
+ directories = expected.flatten.compact.map{|dir| dir.to_s}
75
+ directories.all?{|dir| test(?d, File.join(root, dir))}
76
+ end
77
+ alias_method "valid_rails_root?", "valid_rails_root"
78
+ end
79
+ send :extend, ModuleMethods
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: bj
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-12-12 00:00:00 -07:00
8
+ summary: bj
9
+ require_paths:
10
+ - lib
11
+ email: ara.t.howard@gmail.com
12
+ homepage: http://codeforpeople.com/lib/ruby/bj/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: bj
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ara T. Howard
31
+ files:
32
+ - bin
33
+ - bin/bj
34
+ - gemspec.rb
35
+ - HISTORY
36
+ - install.rb
37
+ - lib
38
+ - lib/bj
39
+ - lib/bj/api.rb
40
+ - lib/bj/bj.rb
41
+ - lib/bj/errors.rb
42
+ - lib/bj/joblist.rb
43
+ - lib/bj/logger.rb
44
+ - lib/bj/runner.rb
45
+ - lib/bj/stdext.rb
46
+ - lib/bj/table.rb
47
+ - lib/bj/util.rb
48
+ - lib/bj.rb
49
+ - README
50
+ - TODO
51
+ test_files: []
52
+
53
+ rdoc_options: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ executables:
58
+ - bj
59
+ extensions: []
60
+
61
+ requirements: []
62
+
63
+ dependencies:
64
+ - !ruby/object:Gem::Dependency
65
+ name: attributes
66
+ version_requirement:
67
+ version_requirements: !ruby/object:Gem::Version::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 5.0.0
72
+ version:
73
+ - !ruby/object:Gem::Dependency
74
+ name: main
75
+ version_requirement:
76
+ version_requirements: !ruby/object:Gem::Version::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.6.0
81
+ version:
82
+ - !ruby/object:Gem::Dependency
83
+ name: systemu
84
+ version_requirement:
85
+ version_requirements: !ruby/object:Gem::Version::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ version:
91
+ - !ruby/object:Gem::Dependency
92
+ name: orderedhash
93
+ version_requirement:
94
+ version_requirements: !ruby/object:Gem::Version::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 0.0.3
99
+ version: