Method: Rake::Task.gl_run
- Defined in:
- lib/rake/config.rb
.gl_run(*args, &aBlock) ⇒ Object
Execute command (as is) on local_host using greenletters to enable expect like behaviour (useful for dealling with passwords).
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'lib/rake/config.rb', line 654 def self.gl_run(*args, &aBlock) $TRACE = Rake.application..trace; = 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) = args.pop; end Conf.timeout = Hash.new() unless Conf.has_key?(:timeout); Conf.timeout.maxTimeout = 10 unless Conf.timeout.has_key?(:maxTimeout); if .has_key?(:timeout) then [:timeout] = Conf.timeout.maxTimeout if Conf.timeout.maxTimeout.to_i < [:timeout].to_i ; else [:timeout] = 10; end Conf.retries = 5 unless Conf.has_key?(:retries) [:retries] = Conf.retries unless .has_key?(:retries) Rake::Application.mesg args.join(' ') if $TRACE Rake::Application.mesg "Timeout: #{[:timeout]}" if $TRACE Rake::Application.mesg "#{}" if $TRACE && !.empty?() && .has_key?(:verbose); Rake::Application.mesg "Retries: #{[:retries]}" if $TRACE asyncTriggersBlocks = Array.new; if .has_key? :asyncTriggersBlocks then asyncTriggersBlocks = [:asyncTriggersBlocks]; end exitStatus = 0; if .has_key? :exitStatus then exitStatus = [:exitStatus]; end [:env] = ENV unless .has_key?(:env); [:transcript] = Rake::Application.logger unless .has_key?(:transcript); attempt = 0 tryAgain = true cmdProcess = nil while(tryAgain) do attempt += 1 tryAgain = false begin cmdProcess = Greenletters::Process.new(*args, ); 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 < [:retries] end end cmdProcess end |