class Rake::Task

Public Class Methods

gl_run(*args, &aBlock) click to toggle source

Execute command (as is) on local_host using greenletters to enable expect like behaviour (useful for dealling with passwords).

# File lib/rake/config.rb, line 654
def self.gl_run(*args, &aBlock)
  $TRACE = Rake.application.options.trace;

  options = Hash.new;
  if args.last.is_a?(Construct) then 
    raise ConfigurationError, "gl_run should not be passed a Construct";
  elsif args.last.is_a?(Hash)
    options = args.pop;
  end
  Conf.timeout = Hash.new() unless Conf.has_key?(:timeout);
  Conf.timeout.maxTimeout = 10 unless Conf.timeout.has_key?(:maxTimeout);
  if options.has_key?(:timeout) then
    options[:timeout] = Conf.timeout.maxTimeout if Conf.timeout.maxTimeout.to_i < options[:timeout].to_i ;
  else
    options[:timeout] = 10;
  end
  Conf.retries = 5 unless Conf.has_key?(:retries)
  options[:retries] = Conf.retries unless options.has_key?(:retries)

  Rake::Application.mesg args.join(' ') if $TRACE
  Rake::Application.mesg "Timeout: #{options[:timeout]}" if $TRACE
  Rake::Application.mesg "#{options}" if $TRACE && !options.empty?() && options.has_key?(:verbose);
  Rake::Application.mesg "Retries: #{options[:retries]}" if $TRACE

  asyncTriggersBlocks = Array.new;
  if options.has_key? :asyncTriggersBlocks then
    asyncTriggersBlocks = options[:asyncTriggersBlocks];
  end

  exitStatus = 0;
  if options.has_key? :exitStatus then
    exitStatus = options[:exitStatus];
  end

  options[:env] = ENV unless options.has_key?(:env);
  options[:transcript] = Rake::Application.logger unless options.has_key?(:transcript);

  attempt = 0
  tryAgain = true
  cmdProcess = nil
  while(tryAgain) do 
    attempt += 1
    tryAgain = false
    begin
      cmdProcess = Greenletters::Process.new(*args, options);
      cmdProcess.start!;

      asyncTriggersBlocks.each do | asyncTriggersBlock |
        if asyncTriggersBlock.kind_of? Proc then
          asyncTriggersBlock.call(cmdProcess);
        end
      end

      aBlock.call(cmdProcess) unless aBlock.nil?;

      cmdProcess.wait_for(:exit, exitStatus);
    rescue StandardError => se
      Rake::Application.mesg "Failed attempt #{attempt}" if $TRACE
      tryAgain = true
      raise se unless attempt < options[:retries]
    end
  end

  cmdProcess
end
local_sh(*args, &aBlock) click to toggle source

Execute command using sh on local_host using greenletters.

# File lib/rake/config.rb, line 639
def self.local_sh(*args, &aBlock)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  options = Conf.sh.data.merge(options);
  cmd     = [options[:command], 
             options[:cmdOptions],
             "-c", 
             args.flatten.join(' ')
            ].flatten

  gl_run(*cmd, options, &aBlock);
end
remote_ssh(*args, &aBlock) click to toggle source

Execute command using ssh to remote_host using greenletters.

# File lib/rake/config.rb, line 617
def self.remote_ssh(*args, &aBlock)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  options = Conf.ssh.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  sshPort = Array.new();
  sshPort = [ '-p', options[:remotePort]] if options.has_key?(:remotePort);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             '-l',
             options[:userId],
             sshPort,
             options[:remoteHost]
            ].flatten

  gl_run(*cmd, options) do | p |
    p.wait_for(:output, Regexp.new(options[:commandPromptRegExp]));
    Rake::Application.mesg args.flatten.join(' ') if Rake.application.options.trace;
    p.puts args.flatten.join(' ') + '; exit';
  end
end
rsync_from_remote(remotePath, localPath, options = {}, &aBlock) click to toggle source

Execute the rsync command on the arguments provided using greenletters.

# File lib/rake/config.rb, line 604
def self.rsync_from_remote(remotePath, localPath, options = {}, &aBlock)
  options = Conf.rsync.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
             localPath,
            ].flatten

  gl_run(*cmd, options, &aBlock);
end
rsync_to_remote(localPath, remotePath, options = {}, &aBlock) click to toggle source

Execute the rsync command on the arguments provided using greenletters.

# File lib/rake/config.rb, line 588
def self.rsync_to_remote(localPath, remotePath, options = {}, &aBlock)
  if localPath =~ /\*/ then
    localPath = Dir.glob(localPath);
  end
  options = Conf.rsync.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             localPath,
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
            ].flatten

  gl_run(*cmd, options, &aBlock);
end
scp_from_remote(remotePath, localPath, options = {}, &aBlock) click to toggle source

Execute the rsync command on the arguments provided using greenletters.

# File lib/rake/config.rb, line 575
def self.scp_from_remote(remotePath, localPath, options = {}, &aBlock)
  options = Conf.scp.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
             localPath,
            ].flatten

  gl_run(*cmd, options, &aBlock);
end
scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock) click to toggle source

Execute the rsync command on the arguments provided using greenletters.

# File lib/rake/config.rb, line 562
def self.scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock)
  options = Conf.scp.data.merge(options);
  options[:timeout] = 10 unless options.has_key?(:timeout);
  cmd     = [options[:command], 
             options[:cmdOptions], 
             localPath,
             "#{options[:userId]}@#{options[:remoteHost]}:#{remotePath}",
            ].flatten

  gl_run(*cmd, options, &aBlock);
end

Public Instance Methods

execute(args=nil) click to toggle source

Execute the actions associated with this task.

# File lib/rake/extensions.rb, line 250
def execute(args=nil)
  args ||= EMPTY_TASK_ARGS
  if application.options.dryrun then
    Rake::Application.mesg "** Execute (dry run) #{name}"
    return
  end
  if application.options.trace then
    Rake::Application.mesg "** Execute #{name}"
  end
  application.enhance_with_matching_rule(name) if @actions.empty?
  @actions.each do |act|
    case act.arity
    when 1
      act.call(self)
    else
      act.call(self, args)
    end
  end
end