Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7387

Show
Ignore:
Timestamp:
09/01/07 03:23:51 (11 months ago)
Author:
minam
Message:

Don't request a pty by default when running a command

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/CHANGELOG

    r7386 r7387  
    11*SVN* 
     2 
     3* Don't request a pty by default [Jamis Buck] 
    24 
    35* Add a "match" remote dependency method [Adam Greene] 
  • tools/capistrano/lib/capistrano/command.rb

    r7112 r7387  
    8484            channel[:host] = server.host 
    8585            channel[:options] = options 
    86             channel.request_pty :want_reply => true 
    8786 
    88             channel.on_success do |ch| 
     87            execute_command = Proc.new do |ch| 
    8988              logger.trace "executing command", ch[:server] if logger 
    9089              escaped = replace_placeholders(command, ch).gsub(/[$\\`"]/) { |m| "\\#{m}" } 
     
    9493            end 
    9594 
    96             channel.on_failure do |ch| 
    97               # just log it, don't actually raise an exception, since the 
    98               # process method will see that the status is not zero and will 
    99               # raise an exception then. 
    100               logger.important "could not open channel", ch[:server] if logger 
    101               ch.close 
     95            if options[:pty] 
     96              channel.request_pty(:want_reply => true) 
     97              channel.on_success(&execute_command) 
     98              channel.on_failure do |ch| 
     99                # just log it, don't actually raise an exception, since the 
     100                # process method will see that the status is not zero and will 
     101                # raise an exception then. 
     102                logger.important "could not open channel", ch[:server] if logger 
     103                ch.close 
     104              end 
     105            else 
     106              execute_command.call(channel) 
    102107            end 
    103  
     108               
    104109            channel.on_data do |ch, data| 
    105110              @callback[ch, :out, data] if @callback 
  • tools/capistrano/lib/capistrano/configuration/actions/invocation.rb

    r6947 r7387  
    2424          initialize_without_invocation(*args) 
    2525          set :default_environment, {} 
     26          set :default_run_options, {} 
    2627        end 
    2728 
     
    111112        #   it will be used. Otherwise, no :shell key is added. 
    112113        def add_default_command_options(options) 
    113           options = options.dup 
     114          defaults = self[:default_run_options] 
     115          options = defaults.merge(options) 
    114116 
    115117          env = self[:default_environment] 
  • tools/capistrano/test/command_test.rb

    r7145 r7387  
    2020  end 
    2121 
     22  def test_command_with_pty_should_request_pty_and_register_success_callback 
     23    session = setup_for_extracting_channel_action(:on_success) do |ch| 
     24      ch.expects(:request_pty).with(:want_reply => true) 
     25      ch.expects(:exec).with(%(sh -c "ls")) 
     26    end 
     27    Capistrano::Command.new("ls", [session], :pty => true) 
     28  end 
     29 
    2230  def test_command_with_env_key_should_have_environment_constructed_and_prepended 
    23     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     31    session = setup_for_extracting_channel_action do |ch| 
     32      ch.expects(:request_pty).never 
    2433      ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 
    2534    end 
     
    2837 
    2938  def test_env_with_symbolic_key_should_be_accepted_as_a_string 
    30     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     39    session = setup_for_extracting_channel_action do |ch| 
    3140      ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 
    3241    end 
     
    3544 
    3645  def test_env_as_string_should_be_substituted_in_directly 
    37     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     46    session = setup_for_extracting_channel_action do |ch| 
    3847      ch.expects(:exec).with(%(env HOWDY=there sh -c "ls")) 
    3948    end 
     
    4251 
    4352  def test_env_with_symbolic_value_should_be_accepted_as_string 
    44     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     53    session = setup_for_extracting_channel_action do |ch| 
    4554      ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 
    4655    end 
     
    4958 
    5059  def test_env_value_should_be_escaped 
    51     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     60    session = setup_for_extracting_channel_action do |ch| 
    5261      ch.expects(:exec).with(%(env FOO=(\\ \\\"bar\\\"\\ ) sh -c "ls")) 
    5362    end 
     
    5665 
    5766  def test_env_with_multiple_keys_should_chain_the_entries_together 
    58     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     67    session = setup_for_extracting_channel_action do |ch| 
    5968      ch.expects(:exec).with do |command| 
    6069        command =~ /^env / && 
     
    7483    session.expects(:open_channel).yields(channel) 
    7584    channel.expects(:[]=).with(:host, "capistrano") 
     85    channel.stubs(:[]).with(:host).returns("capistrano") 
    7686 
    7787    Capistrano::Command.new("ls", [session]) 
     
    8494    session.expects(:open_channel).yields(channel) 
    8595    channel.expects(:[]=).with(:options, {:data => "here we go"}) 
     96    channel.stubs(:[]).with(:host).returns("capistrano") 
    8697 
    8798    Capistrano::Command.new("ls", [session], :data => "here we go") 
    8899  end 
    89100 
    90   def test_open_channel_should_request_pty 
    91     session = mock(:xserver => server("capistrano")) 
    92     channel = stub_everything 
    93  
    94     session.expects(:open_channel).yields(channel) 
    95     channel.expects(:request_pty).with(:want_reply => true) 
    96  
     101  def test_successful_channel_should_send_command 
     102    session = setup_for_extracting_channel_action do |ch| 
     103      ch.expects(:exec).with(%(sh -c "ls")) 
     104    end 
    97105    Capistrano::Command.new("ls", [session]) 
    98106  end 
    99107 
    100   def test_successful_channel_should_send_command 
    101     session = setup_for_extracting_channel_action(:on_success) do |ch| 
    102       ch.expects(:exec).with(%(sh -c "ls")) 
    103     end 
    104     Capistrano::Command.new("ls", [session]) 
    105   end 
    106  
    107108  def test_successful_channel_with_shell_option_should_send_command_via_specified_shell 
    108     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     109    session = setup_for_extracting_channel_action do |ch| 
    109110      ch.expects(:exec).with(%(/bin/bash -c "ls")) 
    110111    end 
     
    113114 
    114115  def test_successful_channel_should_send_data_if_data_key_is_present 
    115     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     116    session = setup_for_extracting_channel_action do |ch| 
    116117      ch.expects(:exec).with(%(sh -c "ls")) 
    117118      ch.expects(:send_data).with("here we go") 
     
    120121  end 
    121122 
    122   def test_unsuccessful_channel_should_close_channel 
     123  def test_unsuccessful_pty_request_should_close_channel 
    123124    session = setup_for_extracting_channel_action(:on_failure) do |ch| 
    124125      ch.expects(:close) 
    125126    end 
    126     Capistrano::Command.new("ls", [session]
     127    Capistrano::Command.new("ls", [session], :pty => true
    127128  end 
    128129 
     
    259260 
    260261  def test_process_with_host_placeholder_should_substitute_placeholder_with_each_host 
    261     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     262    session = setup_for_extracting_channel_action do |ch| 
    262263      ch.expects(:exec).with(%(sh -c "echo capistrano")) 
    263264    end 
     
    266267 
    267268  def test_process_with_unknown_placeholder_should_not_replace_placeholder 
    268     session = setup_for_extracting_channel_action(:on_success) do |ch| 
     269    session = setup_for_extracting_channel_action do |ch| 
    269270      ch.expects(:exec).with(%(sh -c "echo \\$CAPISTRANO:OTHER\\$")) 
    270271    end 
     
    284285    end 
    285286 
    286     def setup_for_extracting_channel_action(action, *args) 
     287    def setup_for_extracting_channel_action(action=nil, *args) 
    287288      s = server("capistrano") 
    288289      session = mock("session", :xserver => s) 
     
    291292      session.expects(:open_channel).yields(channel) 
    292293 
    293       ch = mock 
    294       ch.stubs(:[]).with(:server).returns(s) 
    295       ch.stubs(:[]).with(:host).returns(s.host) 
    296       channel.expects(action).yields(ch, *args) 
    297  
    298       yield ch if block_given? 
     294      channel.stubs(:[]).with(:server).returns(s) 
     295      channel.stubs(:[]).with(:host).returns(s.host) 
     296      channel.expects(action).yields(channel, *args) if action 
     297 
     298      yield channel if block_given? 
    299299 
    300300      session