Module: Rigup::Runability
- Included in:
- Cli, DeployBase, GitRepo
- Defined in:
- lib/rigup/runability.rb
Instance Method Summary collapse
- #bash ⇒ Object
- #cd(aPath, &block) ⇒ Object
- #pwd ⇒ Object
- #run(aCommand, aOptions = nil) ⇒ Object
- #run_for_all(aCommand, aPath, aFilesOrDirs, aPattern = nil, aInvertPattern = false, aSudo = false) ⇒ Object
Instance Method Details
#bash ⇒ Object
4 5 6 |
# File 'lib/rigup/runability.rb', line 4 def bash @bash ||= ::Session::Bash.new end |
#cd(aPath, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rigup/runability.rb', line 12 def cd(aPath,&block) if block_given? begin before_path = pwd cd(aPath) yield aPath,before_path rescue Exception => e @context.logger.info e. ensure cd(before_path) end else aPath = File.(aPath) Dir.chdir(aPath) bash.execute("cd \"#{aPath}\"") end aPath end |
#pwd ⇒ Object
8 9 10 |
# File 'lib/rigup/runability.rb', line 8 def pwd bash.execute("pwd", stdout: nil).first.strip end |
#run(aCommand, aOptions = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/rigup/runability.rb', line 31 def run(aCommand,aOptions=nil) aOptions ||= {} @context.logger.debug aCommand response,errout = bash.execute(aCommand,stdout: STDOUT) # ::POpen4::shell(aCommand,aDir || @context.pwd) @context.logger.debug errout if errout.to_nil @context.logger.debug response if response.to_nil raise "Command Failed" unless bash.exit_status==0 or aOptions[:raise]==false return response end |
#run_for_all(aCommand, aPath, aFilesOrDirs, aPattern = nil, aInvertPattern = false, aSudo = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rigup/runability.rb', line 41 def run_for_all(aCommand,aPath,aFilesOrDirs,aPattern=nil,aInvertPattern=false,aSudo=false) #run "#{sudo} find . -wholename '*/.svn' -prune -o -type d -print0 |xargs -0 #{sudo} chmod 750" #sudo find . -type f -exec echo {} \; cmd = [] cmd << "sudo" if aSudo cmd << "find #{aPath.ensure_suffix('/')}" cmd << "-wholename '#{aPattern}'" if aPattern cmd << "-prune -o" if aInvertPattern cmd << case aFilesOrDirs.to_s[0,1] when 'f' then '-type f' when 'd' then '-type d' else '' end cmd << "-exec" cmd << aCommand cmd << "'{}' \\;" cmd = cmd.join(' ') run cmd end |