1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Set :actor key on SSH channel instances. Add Actor.default_io_proc

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3381 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2006-01-05 14:51:16 +00:00
parent fb521454f6
commit 1320e07f8c
3 changed files with 22 additions and 8 deletions

View file

@ -1,3 +1,10 @@
*0.11.0* *SVN*
* Added Actor.default_io_proc
* Set :actor key on SSH channel instances
*0.10.0* (January 2nd, 2006) *0.10.0* (January 2nd, 2006)
* Handle ssh password prompts like "someone's password:" * Handle ssh password prompts like "someone's password:"

View file

@ -29,12 +29,18 @@ module SwitchTower
attr_accessor :connection_factory attr_accessor :connection_factory
attr_accessor :command_factory attr_accessor :command_factory
attr_accessor :transfer_factory attr_accessor :transfer_factory
attr_accessor :default_io_proc
end end
self.connection_factory = DefaultConnectionFactory self.connection_factory = DefaultConnectionFactory
self.command_factory = Command self.command_factory = Command
self.transfer_factory = Transfer self.transfer_factory = Transfer
self.default_io_proc = Proc.new do |ch, stream, out|
level = out == :error ? :important : :info
ch[:actor].logger.send(level, out, "#{stream} :: #{ch[:host]}")
end
# The configuration instance associated with this actor. # The configuration instance associated with this actor.
attr_reader :configuration attr_reader :configuration
@ -105,7 +111,7 @@ module SwitchTower
# Define a new task for this actor. The block will be invoked when this # Define a new task for this actor. The block will be invoked when this
# task is called. # task is called.
def define_task(name, options={}, &block) def define_task(name, options={}, &block)
@tasks[name] = Task.new(name, options) @tasks[name] = (options[:task_class] || Task).new(name, options)
define_method(name) do define_method(name) do
send "before_#{name}" if respond_to? "before_#{name}" send "before_#{name}" if respond_to? "before_#{name}"
logger.trace "executing task #{name}" logger.trace "executing task #{name}"
@ -129,10 +135,7 @@ module SwitchTower
# #
# If +pretend+ mode is active, this does nothing. # If +pretend+ mode is active, this does nothing.
def run(cmd, options={}, &block) def run(cmd, options={}, &block)
block ||= Proc.new do |ch, stream, out| block ||= default_io_proc
logger.debug(out, "#{stream} :: #{ch[:host]}")
end
logger.debug "executing #{cmd.strip.inspect}" logger.debug "executing #{cmd.strip.inspect}"
execute_on_servers(options) do |servers| execute_on_servers(options) do |servers|
@ -176,9 +179,7 @@ module SwitchTower
# the sudo password (if required) is the same as the password for logging # the sudo password (if required) is the same as the password for logging
# in to the server. # in to the server.
def sudo(command, options={}, &block) def sudo(command, options={}, &block)
block ||= Proc.new do |ch, stream, out| block ||= default_io_proc
logger.debug(out, "#{stream} :: #{ch[:host]}")
end
# in order to prevent _each host_ from prompting when the password was # in order to prevent _each host_ from prompting when the password was
# wrong, let's track which host prompted first and only allow subsequent # wrong, let's track which host prompted first and only allow subsequent
@ -320,6 +321,11 @@ module SwitchTower
task_call_frames.last.rollback = block task_call_frames.last.rollback = block
end end
# An instance-level reader for the class' #default_io_proc attribute.
def default_io_proc
self.class.default_io_proc
end
private private
def metaclass def metaclass

View file

@ -56,6 +56,7 @@ module SwitchTower
@servers.map do |server| @servers.map do |server|
@actor.sessions[server].open_channel do |channel| @actor.sessions[server].open_channel do |channel|
channel[:host] = server channel[:host] = server
channel[:actor] = @actor # so callbacks can access the actor instance
channel.request_pty :want_reply => true channel.request_pty :want_reply => true
channel.on_success do |ch| channel.on_success do |ch|