open4 0.5.1 → 0.6.0

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/README CHANGED
@@ -1,6 +1,6 @@
1
1
  URIS
2
2
 
3
- http://rubyforge.org/frs/?group_id=1024
3
+ http://rubyforge.org/projects/codeforpeople/
4
4
  http://www.codeforpeople.com/lib/ruby/
5
5
 
6
6
  SYNOPSIS
@@ -10,6 +10,35 @@ SYNOPSIS
10
10
 
11
11
  HISTORY
12
12
 
13
+ 0.6.0:
14
+ - added feature for exitstatus to be list of acceptable exit statuses
15
+
16
+ Open4.spawn 'ruby -e "exit 42"' # raises
17
+ Open4.spawn 'ruby -e "exit 42"', :exitstatus=>[0,42] # ok
18
+
19
+ - added :status switch, which will always simply return the status (no
20
+ error thrown for failure)
21
+
22
+ Open4.spawn 'ruby -e "exit 42"' # raises
23
+ status = Open4.spawn 'ruby -e "exit 42"', :status=>true # ok
24
+
25
+ note, however, that any SpawnError does in fact contain the failed
26
+ status so, even when they are thrown, error status can be retrieved:
27
+
28
+ include Open4
29
+
30
+ status =
31
+ begin
32
+ spawn 'ruby -e "exit 42"'
33
+ rescue SpawnError => e
34
+ warn{ e }
35
+ e.status
36
+ end
37
+
38
+ 0.5.1:
39
+ - fixes a __critical__ but in ThreadEnsemble class that had a race
40
+ condition that could cause thread deadlock. sorry bout that folks.
41
+
13
42
  0.5.0:
14
43
  - on the suggestion of tim pease (thanks tim!), i added timeout features
15
44
  to open4. the command run may have an overall timeout and individual
@@ -4,7 +4,7 @@ require 'thread'
4
4
 
5
5
  module Open4
6
6
  #--{{{
7
- VERSION = '0.5.1'
7
+ VERSION = '0.6.0'
8
8
  def self.version() VERSION end
9
9
 
10
10
  class Error < ::StandardError; end
@@ -229,7 +229,7 @@ module Open4
229
229
  #--{{{
230
230
  getopt = getopts opts
231
231
 
232
- ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
232
+ ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['status', getopt['quiet', false] ] ]
233
233
  ignore_exec_failure = getopt[ 'ignore_exec_failure', !getopt['raise', true] ]
234
234
  exitstatus = getopt[ %w( exitstatus exit_status status ), 0 ]
235
235
  stdin = getopt[ %w( stdin in i 0 ) << 0 ]
@@ -245,6 +245,8 @@ module Open4
245
245
  stdout ||= '' if stdout_timeout
246
246
  stderr ||= '' if stderr_timeout
247
247
 
248
+ exitstatus = [*exitstatus]
249
+
248
250
  started = false
249
251
 
250
252
  status =
@@ -280,7 +282,7 @@ module Open4
280
282
  end
281
283
 
282
284
  raise SpawnError.new(cmd, status) unless
283
- (ignore_exit_failure or (status.nil? and ignore_exec_failure) or (status.exitstatus == exitstatus))
285
+ (ignore_exit_failure or (status.nil? and ignore_exec_failure) or exitstatus.include?(status.exitstatus))
284
286
 
285
287
  status
286
288
  #--}}}
@@ -4,7 +4,7 @@ require 'thread'
4
4
 
5
5
  module Open4
6
6
  #--{{{
7
- VERSION = '0.5.1'
7
+ VERSION = '0.6.0'
8
8
  def self.version() VERSION end
9
9
 
10
10
  class Error < ::StandardError; end
@@ -229,7 +229,7 @@ module Open4
229
229
  #--{{{
230
230
  getopt = getopts opts
231
231
 
232
- ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
232
+ ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['status', getopt['quiet', false] ] ]
233
233
  ignore_exec_failure = getopt[ 'ignore_exec_failure', !getopt['raise', true] ]
234
234
  exitstatus = getopt[ %w( exitstatus exit_status status ), 0 ]
235
235
  stdin = getopt[ %w( stdin in i 0 ) << 0 ]
@@ -245,6 +245,8 @@ module Open4
245
245
  stdout ||= '' if stdout_timeout
246
246
  stderr ||= '' if stderr_timeout
247
247
 
248
+ exitstatus = [*exitstatus]
249
+
248
250
  started = false
249
251
 
250
252
  status =
@@ -280,7 +282,7 @@ module Open4
280
282
  end
281
283
 
282
284
  raise SpawnError.new(cmd, status) unless
283
- (ignore_exit_failure or (status.nil? and ignore_exec_failure) or (status.exitstatus == exitstatus))
285
+ (ignore_exit_failure or (status.nil? and ignore_exec_failure) or exitstatus.include?(status.exitstatus))
284
286
 
285
287
  status
286
288
  #--}}}
File without changes
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: open4
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2006-08-22 00:00:00.000000 -06:00
6
+ version: 0.6.0
7
+ date: 2006-08-31 00:00:00.000000 -06:00
8
8
  summary: open4
9
9
  require_paths:
10
10
  - lib
@@ -33,11 +33,8 @@ files:
33
33
  - sample
34
34
  - lib
35
35
  - README
36
- - build
37
- - install
36
+ - open4-0.6.0.gem
38
37
  - gemspec.rb
39
- - a.rb
40
- - open4-0.5.1.gem
41
38
  - sample/block.rb
42
39
  - sample/simple.rb
43
40
  - sample/exception.rb
@@ -46,7 +43,7 @@ files:
46
43
  - sample/timeout.rb
47
44
  - sample/stdin_timeout.rb
48
45
  - lib/open4.rb
49
- - lib/open4-0.5.1.rb
46
+ - lib/open4-0.6.0.rb
50
47
  test_files: []
51
48
  rdoc_options: []
52
49
  extra_rdoc_files: []
data/a.rb DELETED
@@ -1,64 +0,0 @@
1
- require 'thread'
2
-
3
- class ThreadEnsemble
4
- #--{{{
5
- attr 'threads'
6
-
7
- def initialize
8
- @threads, @argv, @done, @running = [], [], Queue.new, false
9
- end
10
-
11
- def add_thread *a, &b
12
- @running ? raise : (@argv << [a, b])
13
- end
14
-
15
- def killall
16
- (@threads - [Thread.current]).each{|t| t.kill rescue nil} if @running
17
- end
18
-
19
- def run
20
- @running = true
21
-
22
- begin
23
- @argv.each do |a, b|
24
- @threads << Thread.new(*a) do |*a|
25
- begin
26
- b[*a]
27
- ensure
28
- killall rescue nil if $!
29
- @done.push Thread.current
30
- end
31
- end
32
- end
33
- rescue
34
- killall
35
- raise
36
- ensure
37
- all_done
38
- end
39
-
40
- @threads.map{|t| t.value}
41
- end
42
-
43
- def all_done
44
- @threads.size.times{ @done.pop }
45
- end
46
- #--}}}
47
- end
48
-
49
- loop do
50
- te = ThreadEnsemble.new
51
-
52
- 1000.times do
53
- te.add_thread do
54
- raise
55
- end
56
- end
57
-
58
- begin
59
- te.run
60
- rescue
61
- running = te.threads.select{|t| t.status}
62
- abort running.inspect if running.size > 0
63
- end
64
- end
data/install DELETED
@@ -1,201 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rbconfig'
3
- require 'find'
4
- require 'ftools'
5
- require 'tempfile'
6
- include Config
7
-
8
- LIBDIR = "lib"
9
- LIBDIR_MODE = 0644
10
-
11
- BINDIR = "bin"
12
- BINDIR_MODE = 0755
13
-
14
-
15
- $srcdir = CONFIG["srcdir"]
16
- $version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
17
- $libdir = File.join(CONFIG["libdir"], "ruby", $version)
18
- $archdir = File.join($libdir, CONFIG["arch"])
19
- $site_libdir = $:.find {|x| x =~ /site_ruby$/}
20
- $bindir = CONFIG["bindir"] || CONFIG['BINDIR']
21
- $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
22
- $ruby_ext = CONFIG['EXEEXT'] || ''
23
- $ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
24
-
25
- if !$site_libdir
26
- $site_libdir = File.join($libdir, "site_ruby")
27
- elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
28
- $site_libdir = File.join($site_libdir, $version)
29
- end
30
-
31
- def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
32
- #{{{
33
- path = []
34
- dir = []
35
- Find.find(srcdir) do |f|
36
- next unless FileTest.file?(f)
37
- next if (f = f[srcdir.length+1..-1]) == nil
38
- next if (/CVS$/ =~ File.dirname(f))
39
- next if f =~ %r/\.lnk/
40
- path.push f
41
- dir |= [File.dirname(f)]
42
- end
43
- for f in dir
44
- next if f == "."
45
- next if f == "CVS"
46
- File::makedirs(File.join(destdir, f))
47
- end
48
- for f in path
49
- next if (/\~$/ =~ f)
50
- next if (/^\./ =~ File.basename(f))
51
- unless bin
52
- File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
53
- else
54
- from = File.join(srcdir, f)
55
- to = File.join(destdir, f)
56
- shebangify(from) do |sf|
57
- $deferr.print from, " -> ", File::catname(from, to), "\n"
58
- $deferr.printf "chmod %04o %s\n", mode, to
59
- File::install(sf, to, mode, false)
60
- end
61
- end
62
- end
63
- #}}}
64
- end
65
- def shebangify f
66
- #{{{
67
- open(f) do |fd|
68
- buf = fd.read 42
69
- if buf =~ %r/^\s*#\s*!.*ruby/o
70
- ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
71
- begin
72
- fd.rewind
73
- ftmp.puts "#!#{ $ruby }"
74
- while((buf = fd.read(8192)))
75
- ftmp.write buf
76
- end
77
- ftmp.close
78
- yield ftmp.path
79
- ensure
80
- ftmp.close!
81
- end
82
- else
83
- yield f
84
- end
85
- end
86
- #}}}
87
- end
88
- def ARGV.switch
89
- #{{{
90
- return nil if self.empty?
91
- arg = self.shift
92
- return nil if arg == '--'
93
- if arg =~ /^-(.)(.*)/
94
- return arg if $1 == '-'
95
- raise 'unknown switch "-"' if $2.index('-')
96
- self.unshift "-#{$2}" if $2.size > 0
97
- "-#{$1}"
98
- else
99
- self.unshift arg
100
- nil
101
- end
102
- #}}}
103
- end
104
- def ARGV.req_arg
105
- #{{{
106
- self.shift || raise('missing argument')
107
- #}}}
108
- end
109
- def linkify d, linked = []
110
- #--{{{
111
- if test ?d, d
112
- versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
113
- versioned.each do |v|
114
- src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
115
- lnk = nil
116
- begin
117
- if test ?l, dst
118
- lnk = "#{ dst }.lnk"
119
- puts "#{ dst } -> #{ lnk }"
120
- File::rename dst, lnk
121
- end
122
- unless test ?e, dst
123
- puts "#{ src } -> #{ dst }"
124
- File::copy src, dst
125
- linked << dst
126
- end
127
- ensure
128
- if lnk
129
- at_exit do
130
- puts "#{ lnk } -> #{ dst }"
131
- File::rename lnk, dst
132
- end
133
- end
134
- end
135
- end
136
- end
137
- linked
138
- #--}}}
139
- end
140
-
141
-
142
- #
143
- # main program
144
- #
145
-
146
- libdir = $site_libdir
147
- bindir = $bindir
148
- no_linkify = false
149
- linked = nil
150
- help = false
151
-
152
- usage = <<-usage
153
- #{ File::basename $0 }
154
- -d, --destdir <destdir>
155
- -l, --libdir <libdir>
156
- -b, --bindir <bindir>
157
- -r, --ruby <ruby>
158
- -n, --no_linkify
159
- -h, --help
160
- usage
161
-
162
- begin
163
- while switch = ARGV.switch
164
- case switch
165
- when '-d', '--destdir'
166
- libdir = ARGV.req_arg
167
- when '-l', '--libdir'
168
- libdir = ARGV.req_arg
169
- when '-b', '--bindir'
170
- bindir = ARGV.req_arg
171
- when '-r', '--ruby'
172
- $ruby = ARGV.req_arg
173
- when '-n', '--no_linkify'
174
- no_linkify = true
175
- when '-h', '--help'
176
- help = true
177
- else
178
- raise "unknown switch #{switch.dump}"
179
- end
180
- end
181
- rescue
182
- STDERR.puts $!.to_s
183
- STDERR.puts usage
184
- exit 1
185
- end
186
-
187
- if help
188
- STDOUT.puts usage
189
- exit
190
- end
191
-
192
- unless no_linkify
193
- linked = linkify('lib') + linkify('bin')
194
- end
195
-
196
- install_rb(LIBDIR, libdir, LIBDIR_MODE)
197
- install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
198
-
199
- if linked
200
- linked.each{|path| File::rm_f path}
201
- end
File without changes