subprocess 0.1.6 → 0.15
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.md +72 -0
- data/lib/subprocess.rb +529 -20
- metadata +55 -121
- data/History.txt +0 -4
- data/Manifest.txt +0 -46
- data/PostInstall.txt +0 -7
- data/README.rdoc +0 -77
- data/Rakefile +0 -20
- data/TODO.rdoc +0 -1
- data/examples/simple.irb +0 -22
- data/examples/simple_timeout.irb +0 -22
- data/features/multiple_popens_sequence.feature +0 -23
- data/features/popen.feature +0 -45
- data/features/popen_over_ssh.feature +0 -44
- data/features/popen_over_ssh_without_blocking.feature +0 -16
- data/features/popen_remote_fails_with_invalid_auth_data.feature +0 -13
- data/features/popen_reports_runtime.feature +0 -11
- data/features/popen_running.feature +0 -11
- data/features/popen_with_timeout.feature +0 -19
- data/features/popen_without_blocking.feature +0 -16
- data/features/step_definitions/common_steps.rb +0 -168
- data/features/step_definitions/multiple_popens_sequence_steps.rb +0 -73
- data/features/step_definitions/popen_over_ssh_steps.rb +0 -29
- data/features/step_definitions/popen_over_ssh_without_blocking_steps.rb +0 -30
- data/features/step_definitions/popen_remote_fails_with_invalid_auth_dat_steps.rb +0 -19
- data/features/step_definitions/popen_reports_runtime_steps.rb +0 -13
- data/features/step_definitions/popen_running_steps.rb +0 -12
- data/features/step_definitions/popen_steps.rb +0 -34
- data/features/step_definitions/popen_with_timeout_steps.rb +0 -24
- data/features/step_definitions/popen_without_blocking_steps.rb +0 -33
- data/features/support/common.rb +0 -29
- data/features/support/env.rb +0 -15
- data/features/support/matchers.rb +0 -11
- data/lib/core_ext/hash.rb +0 -14
- data/lib/core_ext/process_status.rb +0 -14
- data/lib/subprocess/popen.rb +0 -188
- data/lib/subprocess/popen_factory.rb +0 -63
- data/lib/subprocess/popen_remote.rb +0 -64
- data/lib/subprocess/popen_sequence.rb +0 -57
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -10
- data/spec/subprocess/popen_spec.rb +0 -32
- data/spec/subprocess_spec.rb +0 -2
- data/subprocess.gemspec +0 -36
- data/tasks/rspec.rake +0 -21
@@ -1,64 +0,0 @@
|
|
1
|
-
|
2
|
-
module Subprocess
|
3
|
-
|
4
|
-
class PopenRemote < Popen
|
5
|
-
attr_accessor :hostname, :ssh_params
|
6
|
-
|
7
|
-
def initialize(command, hostname, username, timeout=300, *ssh_params)
|
8
|
-
@command = command
|
9
|
-
@timeout = timeout
|
10
|
-
@running = false
|
11
|
-
@ipc_parsed = false
|
12
|
-
|
13
|
-
@hostname = hostname
|
14
|
-
@username = username
|
15
|
-
@ssh_params = ssh_params
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def log_to_stderr_and_exit(msg)
|
20
|
-
$stderr.write("Net::SSH error: #{@hostname} #{msg}")
|
21
|
-
exit 1
|
22
|
-
end
|
23
|
-
|
24
|
-
def fork_child_exec
|
25
|
-
exit_status = 0
|
26
|
-
begin
|
27
|
-
ssh = Net::SSH.start(@hostname, @username, *@ssh_params) do |ssh|
|
28
|
-
ssh.open_channel do |channel|
|
29
|
-
channel.exec(@command) do |chan, success|
|
30
|
-
log_to_stderr_and_exit('failed to open exec channel') unless success
|
31
|
-
|
32
|
-
channel.on_data do |chan, data|
|
33
|
-
$stdout.write data
|
34
|
-
end
|
35
|
-
|
36
|
-
channel.on_extended_data do |chan, type, data|
|
37
|
-
$stderr.write data
|
38
|
-
end
|
39
|
-
|
40
|
-
channel.on_request('exit-status') do |chan, data|
|
41
|
-
exit_status = data.read_long.to_i
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
ssh.loop
|
47
|
-
end
|
48
|
-
rescue Net::SSH::AuthenticationFailed
|
49
|
-
log_to_stderr_and_exit("authentication failure\n")
|
50
|
-
rescue Errno::ECONNREFUSED
|
51
|
-
log_to_stderr_and_exit("connection refused\n")
|
52
|
-
rescue Errno::ETIMEDOUT
|
53
|
-
log_to_stderr_and_exit("connection timeout\n")
|
54
|
-
rescue Errno::EHOSTUNREACH
|
55
|
-
log_to_stderr_and_exit("unreachable\n")
|
56
|
-
rescue StandardError => error
|
57
|
-
log_to_stderr_and_exit("error: #{error.message}\n")
|
58
|
-
end
|
59
|
-
exit exit_status
|
60
|
-
end
|
61
|
-
|
62
|
-
end # class PopenRemote
|
63
|
-
end # module Subprocess
|
64
|
-
|
@@ -1,57 +0,0 @@
|
|
1
|
-
|
2
|
-
module Subprocess
|
3
|
-
class PopenSequenceError < StandardError; end
|
4
|
-
class PopenSequence
|
5
|
-
require 'forwardable'
|
6
|
-
extend Forwardable
|
7
|
-
attr_reader :running, :queue, :complete, :incomplete, :failed
|
8
|
-
|
9
|
-
def_delegators :@last, :stdout, :stderr, :status
|
10
|
-
|
11
|
-
def initialize(queue=[])
|
12
|
-
@queue = queue
|
13
|
-
@incomplete = queue
|
14
|
-
@complete = []
|
15
|
-
@failed = []
|
16
|
-
@running = false
|
17
|
-
@completed = false
|
18
|
-
@last = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def include?(item)
|
22
|
-
@queue.include?(item)
|
23
|
-
end
|
24
|
-
|
25
|
-
def [](index)
|
26
|
-
@queue[index]
|
27
|
-
end
|
28
|
-
|
29
|
-
def add_popen(popen)
|
30
|
-
raise PopenSequenceError,
|
31
|
-
"appending a completed sequence is not allowed" if @completed
|
32
|
-
@incomplete << popen
|
33
|
-
end
|
34
|
-
alias :<< :add_popen
|
35
|
-
|
36
|
-
def perform
|
37
|
-
@running = true
|
38
|
-
@failure = false
|
39
|
-
@queue.each do |popen|
|
40
|
-
@last = popen
|
41
|
-
popen.perform
|
42
|
-
popen.status[:exitstatus] == 0 ? @complete << popen :
|
43
|
-
(@failed << popen; break)
|
44
|
-
end
|
45
|
-
@incomplete = @incomplete - @complete
|
46
|
-
@incomplete = @incomplete - @failed
|
47
|
-
@running = false
|
48
|
-
@completed = true
|
49
|
-
end
|
50
|
-
|
51
|
-
def completed?
|
52
|
-
@completed
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/subprocess.rb'}"
|
9
|
-
puts "Loading subprocess gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour --format nested
|
data/spec/spec_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
module Subprocess
|
4
|
-
#describe Popen do
|
5
|
-
|
6
|
-
describe "zero exit code subprocess with stdout" do
|
7
|
-
before(:each) do
|
8
|
-
@subprocess = Popen.new('echo 1')
|
9
|
-
@subprocess.run
|
10
|
-
@subprocess.wait
|
11
|
-
end
|
12
|
-
it "has an exitcode of 0" do
|
13
|
-
@subprocess.status[:exitstatus].should == 0
|
14
|
-
end
|
15
|
-
it "has a runtime in seconds" do
|
16
|
-
@subprocess.status[:run_time].should be_kind_of Numeric
|
17
|
-
end
|
18
|
-
# TODO: trackdown/report rspec bug with stdout
|
19
|
-
#it "has a stdout of 1" do
|
20
|
-
# puts @subprocess.stdout
|
21
|
-
# @subprocess.stdout.should == '1'
|
22
|
-
#end
|
23
|
-
it "has an stderr of " do
|
24
|
-
@subprocess.stderr.should == ''
|
25
|
-
end
|
26
|
-
it "has a numerical pid" do
|
27
|
-
@subprocess.pid.should be_a_kind_of Numeric
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
#end
|
32
|
-
end
|
data/spec/subprocess_spec.rb
DELETED
data/subprocess.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{subprocess}
|
5
|
-
s.version = "0.1.6"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Bram Swenson"]
|
9
|
-
s.date = %q{2010-05-22}
|
10
|
-
s.description = %q{* Subprocess provides a clean wrapper class around the Kernel.exec method.}
|
11
|
-
s.email = ["bram@craniumisajar.com"]
|
12
|
-
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
|
13
|
-
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/simple.irb", "examples/simple_timeout.irb", "features/multiple_popens_sequence.feature", "features/popen.feature", "features/popen_over_ssh.feature", "features/popen_over_ssh_without_blocking.feature", "features/popen_remote_fails_with_invalid_auth_data.feature", "features/popen_reports_runtime.feature", "features/popen_running.feature", "features/popen_with_timeout.feature", "features/popen_without_blocking.feature", "features/step_definitions/common_steps.rb", "features/step_definitions/multiple_popens_sequence_steps.rb", "features/step_definitions/popen_over_ssh_steps.rb", "features/step_definitions/popen_over_ssh_without_blocking_steps.rb", "features/step_definitions/popen_remote_fails_with_invalid_auth_dat_steps.rb", "features/step_definitions/popen_reports_runtime_steps.rb", "features/step_definitions/popen_running_steps.rb", "features/step_definitions/popen_steps.rb", "features/step_definitions/popen_with_timeout_steps.rb", "features/step_definitions/popen_without_blocking_steps.rb", "features/support/common.rb", "features/support/env.rb", "features/support/matchers.rb", "git_user_switcher", "lib/core_ext/hash.rb", "lib/core_ext/process_status.rb", "lib/subprocess.rb", "lib/subprocess/popen.rb", "lib/subprocess/popen_factory.rb", "lib/subprocess/popen_remote.rb", "lib/subprocess/popen_sequence.rb", "script/console", "script/destroy", "script/generate", "spec/spec.opts", "spec/spec_helper.rb", "spec/subprocess/popen_spec.rb", "spec/subprocess_spec.rb", "subprocess.gemspec", "tasks/rspec.rake"]
|
14
|
-
s.homepage = %q{http://github.com/bramswenson/subprocess}
|
15
|
-
s.rdoc_options = ["--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{subprocess}
|
18
|
-
s.rubygems_version = %q{1.3.6}
|
19
|
-
s.summary = %q{* Subprocess provides a clean wrapper class around the Kernel.exec method.}
|
20
|
-
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
|
27
|
-
s.add_development_dependency(%q<hoe>, [">= 2.6.0"])
|
28
|
-
else
|
29
|
-
s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
|
30
|
-
s.add_dependency(%q<hoe>, [">= 2.6.0"])
|
31
|
-
end
|
32
|
-
else
|
33
|
-
s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
|
34
|
-
s.add_dependency(%q<hoe>, [">= 2.6.0"])
|
35
|
-
end
|
36
|
-
end
|
data/tasks/rspec.rake
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
-
require 'spec'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
rescue LoadError
|
10
|
-
puts <<-EOS
|
11
|
-
To use rspec for testing you must install rspec gem:
|
12
|
-
gem install rspec
|
13
|
-
EOS
|
14
|
-
exit(0)
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|