Class: Rake::Task
- Inherits:
-
Object
- Object
- Rake::Task
- Defined in:
- lib/rake/config.rb,
lib/rake/extensions.rb
Class Method Summary collapse
-
.gl_run(*args, &aBlock) ⇒ Object
Execute
command(as is) on local_host using greenletters to enable expect like behaviour (useful for dealling with passwords). -
.local_sh(*args, &aBlock) ⇒ Object
Execute
commandusing sh on local_host using greenletters. -
.remote_ssh(*args, &aBlock) ⇒ Object
Execute
commandusing ssh to remote_host using greenletters. -
.rsync_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
-
.rsync_to_remote(localPath, remotePath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
-
.scp_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
-
.scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
Instance Method Summary collapse
-
#execute(args = nil) ⇒ Object
Execute the actions associated with this task.
-
#invoke_with_call_chain(task_args, invocation_chain) ⇒ Object
Same as invoke, but explicitly pass a call chain to detect circular dependencies.
Class Method Details
.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 |
.local_sh(*args, &aBlock) ⇒ Object
Execute command using sh on local_host using greenletters.
639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/rake/config.rb', line 639 def self.local_sh(*args, &aBlock) = if args.last.is_a?(Hash) then args.pop else {} end = Conf.sh.data.merge(); cmd = [[:command], [:cmdOptions], "-c", args.flatten.join(' ') ].flatten gl_run(*cmd, , &aBlock); end |
.remote_ssh(*args, &aBlock) ⇒ Object
Execute command using ssh to remote_host using greenletters.
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/rake/config.rb', line 617 def self.remote_ssh(*args, &aBlock) = if args.last.is_a?(Hash) then args.pop else {} end = Conf.ssh.data.merge(); [:timeout] = 10 unless .has_key?(:timeout); sshPort = Array.new(); sshPort = [ '-p', [:remotePort]] if .has_key?(:remotePort); cmd = [[:command], [:cmdOptions], '-l', [:userId], sshPort, [:remoteHost] ].flatten gl_run(*cmd, ) do | p | p.wait_for(:output, Regexp.new([:commandPromptRegExp])); Rake::Application.mesg args.flatten.join(' ') if Rake.application..trace; p.puts args.flatten.join(' ') + '; exit'; end end |
.rsync_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/rake/config.rb', line 604 def self.rsync_from_remote(remotePath, localPath, = {}, &aBlock) = Conf.rsync.data.merge(); [:timeout] = 10 unless .has_key?(:timeout); cmd = [[:command], [:cmdOptions], "#{[:userId]}@#{[:remoteHost]}:#{remotePath}", localPath, ].flatten gl_run(*cmd, , &aBlock); end |
.rsync_to_remote(localPath, remotePath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/rake/config.rb', line 588 def self.rsync_to_remote(localPath, remotePath, = {}, &aBlock) if localPath =~ /\*/ then localPath = Dir.glob(localPath); end = Conf.rsync.data.merge(); [:timeout] = 10 unless .has_key?(:timeout); cmd = [[:command], [:cmdOptions], localPath, "#{[:userId]}@#{[:remoteHost]}:#{remotePath}", ].flatten gl_run(*cmd, , &aBlock); end |
.scp_from_remote(remotePath, localPath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/rake/config.rb', line 575 def self.scp_from_remote(remotePath, localPath, = {}, &aBlock) = Conf.scp.data.merge(); [:timeout] = 10 unless .has_key?(:timeout); cmd = [[:command], [:cmdOptions], "#{[:userId]}@#{[:remoteHost]}:#{remotePath}", localPath, ].flatten gl_run(*cmd, , &aBlock); end |
.scp_to_remote_scp(localPath, remotePath, options = {}, &aBlock) ⇒ Object
Execute the rsync command on the arguments provided using greenletters.
562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/rake/config.rb', line 562 def self.scp_to_remote_scp(localPath, remotePath, = {}, &aBlock) = Conf.scp.data.merge(); [:timeout] = 10 unless .has_key?(:timeout); cmd = [[:command], [:cmdOptions], localPath, "#{[:userId]}@#{[:remoteHost]}:#{remotePath}", ].flatten gl_run(*cmd, , &aBlock); end |
Instance Method Details
#execute(args = nil) ⇒ Object
Execute the actions associated with this task.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/rake/extensions.rb', line 250 def execute(args=nil) args ||= EMPTY_TASK_ARGS if application..dryrun then Rake::Application.mesg "** Execute (dry run) #{name}" return end if application..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 |
#invoke_with_call_chain(task_args, invocation_chain) ⇒ Object
Same as invoke, but explicitly pass a call chain to detect circular dependencies.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/rake/extensions.rb', line 233 def invoke_with_call_chain(task_args, invocation_chain) # :nodoc: new_chain = InvocationChain.append(self, invocation_chain) @lock.synchronize do if application..trace then Rake::Application.mesg "** Invoke #{name} #{format_trace_flags}" end return if @already_invoked @already_invoked = true invoke_prerequisites(task_args, new_chain) execute(task_args) if needed? end rescue Exception => ex add_chain_to(ex, new_chain) raise ex end |