right_popen 1.0.21-x86-mswin32-60 → 1.1.3-x86-mswin32-60
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.rdoc +10 -8
- data/lib/right_popen.rb +125 -30
- data/lib/right_popen/process_base.rb +339 -0
- data/lib/right_popen/process_status.rb +64 -0
- data/lib/right_popen/safe_output_buffer.rb +79 -0
- data/lib/right_popen/target_proxy.rb +67 -0
- data/lib/right_popen/version.rb +2 -2
- data/lib/right_popen/win32/popen3_async.rb +258 -0
- data/lib/right_popen/win32/popen3_sync.rb +35 -0
- data/lib/right_popen/win32/process.rb +306 -0
- data/lib/right_popen/win32/{right_popen.rb → right_popen_ex.rb} +8 -231
- data/lib/win32/right_popen.so +0 -0
- data/right_popen.gemspec +2 -2
- data/spec/produce_mixed_output.rb +3 -0
- data/spec/right_popen/safe_output_buffer_spec.rb +26 -0
- data/spec/right_popen_spec.rb +272 -227
- data/spec/runner.rb +171 -79
- data/spec/sleeper.rb +35 -0
- data/spec/stdout.rb +1 -1
- data/spec/writer.rb +34 -0
- metadata +23 -15
data/spec/runner.rb
CHANGED
@@ -22,103 +22,195 @@
|
|
22
22
|
#++
|
23
23
|
|
24
24
|
module RightScale
|
25
|
-
|
26
|
-
class
|
27
|
-
|
28
|
-
options
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
module RightPopen
|
26
|
+
class Runner
|
27
|
+
class RunnerStatus
|
28
|
+
def initialize(command, options={}, &callback)
|
29
|
+
options = {:repeats=>1, :force_yield=>nil, :timeout=>nil, :expect_timeout=>false}.merge(options)
|
30
|
+
|
31
|
+
@command = command
|
32
|
+
@output_text = ""
|
33
|
+
@error_text = ""
|
34
|
+
@status = nil
|
35
|
+
@did_timeout = false
|
36
|
+
@callback = callback
|
37
|
+
@pid = nil
|
38
|
+
@force_yield = options[:force_yield]
|
39
|
+
|
40
|
+
@expect_timeout = options[:expect_timeout]
|
41
|
+
@expect_size_limit = options[:expect_size_limit]
|
42
42
|
end
|
43
|
-
end
|
44
43
|
|
45
|
-
|
44
|
+
attr_accessor :output_text, :error_text, :status, :pid
|
45
|
+
attr_accessor :did_timeout, :did_size_limit
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
def on_read_stdout(data)
|
48
|
+
sleep @force_yield if @force_yield
|
49
|
+
@output_text << data
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def on_read_stderr(data)
|
53
|
+
sleep @force_yield if @force_yield
|
54
|
+
@error_text << data
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_pid(pid)
|
58
|
+
raise "PID already set!" unless @pid.nil?
|
59
|
+
@pid = pid
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_timeout
|
63
|
+
puts "\n** Failed to run #{@command.inspect}: Timeout" unless @expect_timeout
|
64
|
+
@did_timeout = true
|
65
|
+
@callback.call(self) if @expect_timeout
|
66
|
+
end
|
67
|
+
|
68
|
+
def on_size_limit
|
69
|
+
puts "\n** Failed to run #{@command.inspect}: Size limit" unless @expect_size_limit
|
70
|
+
@did_size_limit = true
|
71
|
+
@callback.call(self) if @expect_size_limit
|
72
|
+
end
|
56
73
|
|
57
|
-
|
58
|
-
|
59
|
-
|
74
|
+
def on_exit(status)
|
75
|
+
@status = status
|
76
|
+
@callback.call(self)
|
77
|
+
end
|
60
78
|
end
|
61
79
|
|
62
|
-
def
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
80
|
+
def initialize
|
81
|
+
@count = 0
|
82
|
+
@done = false
|
83
|
+
@last_exception = nil
|
84
|
+
@last_iteration = 0
|
66
85
|
end
|
67
|
-
end
|
68
86
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
87
|
+
def run_right_popen3(synchronicity, command, runner_options={}, &callback)
|
88
|
+
runner_options = {
|
89
|
+
:repeats => 1,
|
90
|
+
:expect_timeout => false,
|
91
|
+
:expect_size_limit => false
|
92
|
+
}.merge(runner_options)
|
93
|
+
popen3_options = {
|
94
|
+
:input => runner_options[:input],
|
95
|
+
:environment => runner_options[:env],
|
96
|
+
:timeout_seconds => runner_options.has_key?(:timeout) ? runner_options[:timeout] : 2,
|
97
|
+
:size_limit_bytes => runner_options[:size_limit_bytes],
|
98
|
+
:watch_directory => runner_options[:watch_directory]
|
99
|
+
}
|
100
|
+
case synchronicity
|
101
|
+
when :sync
|
102
|
+
run_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
103
|
+
when :async
|
104
|
+
run_right_popen3_async(command, runner_options, popen3_options, &callback)
|
105
|
+
else
|
106
|
+
raise "unknown synchronicity = #{synchronicity.inspect}"
|
107
|
+
end
|
108
|
+
end
|
75
109
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
110
|
+
def run_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
111
|
+
begin
|
112
|
+
@iterations = 0
|
113
|
+
@repeats = runner_options[:repeats]
|
114
|
+
@stats = []
|
115
|
+
while @iterations < @repeats
|
116
|
+
@iterations += 1
|
117
|
+
do_right_popen3_sync(command, runner_options, popen3_options) do |runner_status|
|
118
|
+
@stats << runner_status
|
119
|
+
callback.call(runner_status) if callback
|
120
|
+
if @repeats > 1
|
121
|
+
puts if 1 == (@iterations % 64)
|
122
|
+
print '+'
|
123
|
+
puts if @iterations == @repeats
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
@stats.uniq!
|
128
|
+
@stats.size < 2 ? @stats.first : @stats
|
129
|
+
rescue Exception => e
|
130
|
+
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
131
|
+
raise e
|
132
|
+
end
|
133
|
+
end
|
89
134
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
135
|
+
def run_right_popen3_async(command, runner_options, popen3_options, &callback)
|
136
|
+
begin
|
137
|
+
@iterations = 0
|
138
|
+
@repeats = runner_options[:repeats]
|
139
|
+
@stats = []
|
140
|
+
EM.run do
|
141
|
+
EM.defer do
|
142
|
+
begin
|
143
|
+
do_right_popen3_async(command, runner_options, popen3_options) do |runner_status|
|
144
|
+
maybe_continue_popen3_async(runner_status, command, runner_options, popen3_options, &callback)
|
145
|
+
end
|
146
|
+
rescue Exception => e
|
147
|
+
puts e.class, e.message, e.backtrace.join("\n")
|
148
|
+
EM.stop
|
149
|
+
end
|
100
150
|
end
|
101
151
|
end
|
152
|
+
@stats.uniq!
|
153
|
+
@stats.size < 2 ? @stats.first : @stats
|
154
|
+
rescue Exception => e
|
155
|
+
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
156
|
+
raise e
|
102
157
|
end
|
103
|
-
@stats.size < 2 ? @stats.first : @stats
|
104
|
-
rescue Exception => e
|
105
|
-
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
106
|
-
raise e
|
107
158
|
end
|
108
|
-
end
|
109
159
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
160
|
+
def do_right_popen3(synchronicity, command, runner_options, popen3_options, &callback)
|
161
|
+
runner_status = RunnerStatus.new(command, runner_options, &callback)
|
162
|
+
popen3_options = {
|
163
|
+
:target => runner_status,
|
164
|
+
:stdout_handler => :on_read_stdout,
|
165
|
+
:stderr_handler => :on_read_stderr,
|
166
|
+
:pid_handler => :on_pid,
|
167
|
+
:timeout_handler => :on_timeout,
|
168
|
+
:size_limit_handler => :on_size_limit,
|
169
|
+
:exit_handler => :on_exit
|
170
|
+
}.merge(popen3_options)
|
171
|
+
case synchronicity
|
172
|
+
when :sync
|
173
|
+
result = ::RightScale::RightPopen.popen3_sync(command, popen3_options)
|
174
|
+
when :async
|
175
|
+
result = ::RightScale::RightPopen.popen3_async(command, popen3_options)
|
176
|
+
else
|
177
|
+
raise "Uknown synchronicity = #{synchronicity.inspect}"
|
178
|
+
end
|
179
|
+
result.should == true
|
180
|
+
true
|
181
|
+
end
|
182
|
+
|
183
|
+
def do_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
184
|
+
do_right_popen3(:sync, command, runner_options, popen3_options, &callback)
|
185
|
+
end
|
186
|
+
|
187
|
+
def do_right_popen3_async(command, runner_options, popen3_options, &callback)
|
188
|
+
do_right_popen3(:async, command, runner_options, popen3_options, &callback)
|
189
|
+
end
|
190
|
+
|
191
|
+
def maybe_continue_popen3_async(runner_status, command, runner_options, popen3_options, &callback)
|
192
|
+
@iterations += 1
|
193
|
+
@stats << runner_status
|
194
|
+
callback.call(runner_status) if callback
|
195
|
+
if @iterations < @repeats
|
196
|
+
if @repeats > 1
|
197
|
+
puts if 1 == (@iterations % 64)
|
198
|
+
print '+'
|
199
|
+
puts if @iterations == @repeats
|
200
|
+
end
|
201
|
+
EM.defer do
|
202
|
+
begin
|
203
|
+
do_right_popen3_async(command, runner_options, popen3_options) do |runner_status2|
|
204
|
+
maybe_continue_popen3_async(runner_status2, command, runner_options, popen3_options, &callback)
|
205
|
+
end
|
206
|
+
rescue Exception => e
|
207
|
+
puts e.class, e.message, e.backtrace.join("\n")
|
208
|
+
EM.stop
|
209
|
+
end
|
118
210
|
end
|
211
|
+
else
|
212
|
+
EM.stop
|
119
213
|
end
|
120
|
-
else
|
121
|
-
EM.stop
|
122
214
|
end
|
123
215
|
end
|
124
216
|
end
|
data/spec/sleeper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
+
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# 'Software'), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
REPEATS = (ARGV[0] || '4').to_i
|
25
|
+
|
26
|
+
STDOUT.sync = true
|
27
|
+
STDERR.sync = true
|
28
|
+
REPEATS.times do |i|
|
29
|
+
STDOUT.puts "To sleep... #{i}"
|
30
|
+
STDERR.puts "Perchance to dream... #{i}"
|
31
|
+
sleep 1
|
32
|
+
end
|
33
|
+
STDOUT.puts "The sleeper must awaken."
|
34
|
+
|
35
|
+
exit 0
|
data/spec/stdout.rb
CHANGED
data/spec/writer.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
+
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# 'Software'), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
watched_dir = ARGV[0]
|
25
|
+
|
26
|
+
10.times do |i|
|
27
|
+
path = ::File.join(watched_dir, "file#{i}.txt")
|
28
|
+
::File.open(path, 'w') do |f|
|
29
|
+
f.write 'x' * 100
|
30
|
+
end
|
31
|
+
sleep 0.2
|
32
|
+
end
|
33
|
+
|
34
|
+
exit 0
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_popen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 1.1.3
|
11
11
|
platform: x86-mswin32-60
|
12
12
|
authors:
|
13
13
|
- Scott Messier
|
@@ -17,8 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date:
|
21
|
-
default_executable:
|
20
|
+
date: 2013-07-17 00:00:00 Z
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
24
23
|
name: eventmachine
|
@@ -28,13 +27,13 @@ dependencies:
|
|
28
27
|
requirements:
|
29
28
|
- - ">="
|
30
29
|
- !ruby/object:Gem::Version
|
31
|
-
hash:
|
30
|
+
hash: 23
|
32
31
|
segments:
|
32
|
+
- 1
|
33
33
|
- 0
|
34
|
-
-
|
35
|
-
|
36
|
-
|
37
|
-
type: :runtime
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
36
|
+
type: :development
|
38
37
|
version_requirements: *id001
|
39
38
|
- !ruby/object:Gem::Dependency
|
40
39
|
name: win32-process
|
@@ -118,8 +117,15 @@ files:
|
|
118
117
|
- ext/win32/right_popen.c
|
119
118
|
- ext/win32/right_popen.h
|
120
119
|
- lib/right_popen.rb
|
120
|
+
- lib/right_popen/process_base.rb
|
121
|
+
- lib/right_popen/process_status.rb
|
122
|
+
- lib/right_popen/safe_output_buffer.rb
|
123
|
+
- lib/right_popen/target_proxy.rb
|
121
124
|
- lib/right_popen/version.rb
|
122
|
-
- lib/right_popen/win32/
|
125
|
+
- lib/right_popen/win32/popen3_async.rb
|
126
|
+
- lib/right_popen/win32/popen3_sync.rb
|
127
|
+
- lib/right_popen/win32/process.rb
|
128
|
+
- lib/right_popen/win32/right_popen_ex.rb
|
123
129
|
- lib/win32/right_popen.so
|
124
130
|
- right_popen.gemspec
|
125
131
|
- spec/background.rb
|
@@ -130,11 +136,13 @@ files:
|
|
130
136
|
- spec/produce_status.rb
|
131
137
|
- spec/produce_stderr_only.rb
|
132
138
|
- spec/produce_stdout_only.rb
|
139
|
+
- spec/right_popen/safe_output_buffer_spec.rb
|
133
140
|
- spec/right_popen_spec.rb
|
134
141
|
- spec/runner.rb
|
142
|
+
- spec/sleeper.rb
|
135
143
|
- spec/spec_helper.rb
|
136
144
|
- spec/stdout.rb
|
137
|
-
|
145
|
+
- spec/writer.rb
|
138
146
|
homepage: https://github.com/rightscale/right_popen
|
139
147
|
licenses: []
|
140
148
|
|
@@ -169,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
177
|
requirements: []
|
170
178
|
|
171
179
|
rubyforge_project: right_popen
|
172
|
-
rubygems_version: 1.
|
180
|
+
rubygems_version: 1.8.25
|
173
181
|
signing_key:
|
174
182
|
specification_version: 3
|
175
183
|
summary: Provides a platform-independent popen implementation
|