lib/rudy/utils.rb in rudy-0.6.8 vs lib/rudy/utils.rb in rudy-0.7.0

- old
+ new

@@ -68,11 +68,11 @@ # Wait for something to happen. # * +duration+ seconds to wait between tries (default: 2). # * +max+ maximum time to wait (default: 120). Throws an exception when exceeded. # * +logger+ IO object to print +dot+ to. - # * +msg+ the message to print on success + # * +msg+ the message to print before executing the block. # * +bells+ number of terminal bells to ring. Set to nil or false to keep the waiter silent # # The +check+ block must return false while waiting. Once it returns true # the waiter will return true too. def waiter(duration=2, max=120, logger=STDOUT, msg=nil, bells=0, &check) @@ -80,10 +80,14 @@ raise "The waiter needs a block!" unless check duration = 1 if duration < 1 max = duration*2 if max < duration dot = '.' begin + if msg && logger + logger.print msg + logger.flush + end Timeout::timeout(max) do while !check.call sleep duration logger.print dot if logger.respond_to?(:print) logger.flush if logger.respond_to?(:flush) @@ -91,11 +95,16 @@ end rescue Timeout::Error => ex retry if Annoy.pose_question(" Keep waiting?\a ", /yes|y|ya|sure|you bet!/i, logger) return false end - logger.puts msg if msg + + if msg && logger + logger.puts " done" + logger.flush + end + Rudy::Utils.bell(bells, logger) true end # Make a terminal bell chime @@ -272,38 +281,11 @@ ######### Everything below here is TO BE REMOVED. - # - # - # Run a shell command (TO BE REMOVED) - def sh(command, chdir=false, verbose=false) - prevdir = Dir.pwd - Dir.chdir chdir if chdir - puts command if verbose - system(command) - Dir.chdir prevdir if chdir - end - - # - # Run an SSH command (TO BE REMOVED) - def ssh_command(host, keypair, user, command=false, printonly=false, verbose=false) - #puts "CONNECTING TO #{host}..." - cmd = "ssh -i #{keypair} #{user}@#{host} " - cmd += " '#{command}'" if command - puts cmd if verbose - return cmd if printonly - # backticks returns STDOUT - # exec replaces current process (it's just like running ssh) - # -- UPDATE -- Some problem with exec. "Operation not supported" - # using system (http://www.mail-archive.com/mongrel-users@rubyforge.org/msg02018.html) - (command) ? `#{cmd}` : Kernel.system(cmd) - end - - # (TO BE REMOVED) - # TODO: This is old and insecure. + # TODO: This is old and nasty. def scp_command(host, keypair, user, paths, to_path, to_local=false, verbose=false, printonly=false) paths = [paths] unless paths.is_a?(Array) from_paths = "" if to_local \ No newline at end of file