sevenwire-bj 1.0.1

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/lib/bj/util.rb ADDED
@@ -0,0 +1,133 @@
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.has_key?(:logger) ? options[:logger] : Bj.logger
25
+ verbose = options.has_key? :verbose
26
+ logger.info{ "cmd <#{ cmd }>" } if logger
27
+ status = systemu cmd, 1=>(stdout=""), 2=>(stderr="")
28
+ logger.info{ "status <#{ status.exitstatus }>" } if logger
29
+ if verbose
30
+ if logger
31
+ if stdout.empty?
32
+ logger.info{ "stdout <>" }
33
+ else
34
+ logger.info{ "stdout <" }
35
+ logger << stdout.strip.gsub(%r/^/, ' ')
36
+ logger << "\n>\n"
37
+ end
38
+ if stderr.empty?
39
+ logger.info{ "stderr <>" }
40
+ else
41
+ logger.info{ "stderr <" }
42
+ logger << stderr.strip.gsub(%r/^/, ' ')
43
+ logger << "\n>\n"
44
+ end
45
+ else
46
+ STDOUT.puts stdout
47
+ STDERR.puts stderr
48
+ end
49
+ end
50
+ status.exitstatus.zero? or raise "#{ cmd.inspect } failed with #{ $?.inspect }"
51
+ [ stdout, stderr ]
52
+ end
53
+
54
+ def start *a
55
+ q = Queue.new
56
+ thread = Thread.new do
57
+ Thread.current.abort_on_exception = true
58
+ systemu(*a){|pid| q << pid}
59
+ end
60
+ pid = q.pop
61
+ thread.singleton_class{ define_method(:pid){ pid } }
62
+ thread
63
+ end
64
+
65
+ def alive pid
66
+ return false unless pid
67
+ pid = Integer pid.to_s
68
+ Process::kill 0, pid
69
+ true
70
+ rescue Errno::ESRCH, Errno::EPERM
71
+ false
72
+ end
73
+ alias_method "alive?", "alive"
74
+
75
+ def which_ruby
76
+ c = ::Config::CONFIG
77
+ ruby = File::join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
78
+ raise "ruby @ #{ ruby } not executable!?" unless test(?e, ruby)
79
+ ruby
80
+ end
81
+
82
+ def which_rake
83
+ tmp = Tempfile.new Process.pid
84
+ tmp.write "task(:foobar){ puts 42 }"
85
+ tmp.close
86
+ bat = spawn("rake.bat -f #{ tmp.path.inspect } foobar", :logger => false) rescue false
87
+ bat ? "rake.bat" : "rake"
88
+ ensure
89
+ tmp.close! rescue nil
90
+ end
91
+
92
+ def ipc_signals_supported
93
+ @ipc_signals_supported ||=
94
+ IO.popen 'ruby', 'r+' do |ruby|
95
+ pid = ruby.pid
96
+ begin
97
+ Process.kill 'TERM', pid
98
+ true
99
+ rescue Exception
100
+ false
101
+ end
102
+ end
103
+ end
104
+ alias_method "ipc_signals_supported?", "ipc_signals_supported"
105
+
106
+ def find_script basename
107
+ path = ENV["PATH"] || ENV["path"] || Bj.default_path
108
+ raise "no env PATH" unless path
109
+ path = path.split File::PATH_SEPARATOR
110
+ path.unshift File.join(Bj.rails_root, "script")
111
+ path.each do |directory|
112
+ script = File.join directory, basename
113
+ return File.expand_path(script) if(test(?s, script) and test(?r, script))
114
+ end
115
+ raise "no #{ basename } found in #{ path.inspect }"
116
+ end
117
+
118
+ def valid_rails_root root = ".", expected = %w[ config script app ]
119
+ directories = expected.flatten.compact.map{|dir| dir.to_s}
120
+ directories.all?{|dir| test(?d, File.join(root, dir))}
121
+ end
122
+ alias_method "valid_rails_root?", "valid_rails_root"
123
+
124
+ def emsg e
125
+ m = e.message rescue ""
126
+ c = e.class rescue Exception
127
+ b = e.backtrace.join("\n") rescue ""
128
+ "#{ m }(#{ c })\n#{ b }"
129
+ end
130
+ end
131
+ send :extend, ModuleMethods
132
+ end
133
+ end
data/rakefile ADDED
@@ -0,0 +1,3 @@
1
+ task :foobar do
2
+ puts 42
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sevenwire-bj
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ara T. Howard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: main
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.6.0
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: systemu
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.2.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: orderedhash
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ version:
42
+ description:
43
+ email: ara.t.howard@gmail.com
44
+ executables:
45
+ - bj
46
+ extensions: []
47
+
48
+ extra_rdoc_files: []
49
+
50
+ files:
51
+ - bin
52
+ - bin/bj
53
+ - bj.gemspec
54
+ - HISTORY
55
+ - install.rb
56
+ - lib
57
+ - lib/bj
58
+ - lib/bj/api.rb
59
+ - lib/bj/attributes.rb
60
+ - lib/bj/bj.rb
61
+ - lib/bj/errors.rb
62
+ - lib/bj/joblist.rb
63
+ - lib/bj/logger.rb
64
+ - lib/bj/runner.rb
65
+ - lib/bj/stdext.rb
66
+ - lib/bj/table.rb
67
+ - lib/bj/util.rb
68
+ - lib/bj.rb
69
+ - rakefile
70
+ - README
71
+ - TODO
72
+ has_rdoc: false
73
+ homepage: http://codeforpeople.com/lib/ruby/bj/
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ requirements: []
92
+
93
+ rubyforge_project: codeforpeople
94
+ rubygems_version: 1.2.0
95
+ signing_key:
96
+ specification_version: 2
97
+ summary: Bj
98
+ test_files: []
99
+