Module: Rigup::Utils::Run

Included in:
Cli, DeployBase, GitRepo
Defined in:
lib/rigup/utils/run.rb

Instance Method Summary collapse

Instance Method Details

#bashObject



5
6
7
# File 'lib/rigup/utils/run.rb', line 5

def bash
  @bash ||= ::Session::Bash.new
end

#cd(aPath, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rigup/utils/run.rb', line 13

def cd(aPath,&block)
  if block_given?
    begin
      before_path = pwd
      cd(aPath)
      yield aPath,before_path
    rescue Exception => e
      logger.info e.message
    ensure
      cd(before_path)
    end
  else
    aPath = File.expand_path(aPath)
    Dir.chdir(aPath)
    bash.execute("cd \"#{aPath}\"")
  end
  aPath
end

#pwdObject



9
10
11
# File 'lib/rigup/utils/run.rb', line 9

def pwd
  bash.execute("pwd", stdout: nil).first.strip
end

#run(aCommand, aOptions = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rigup/utils/run.rb', line 32

def run(aCommand,aOptions=nil)
  aOptions ||= {}
  logger.debug aCommand
  response,errout = bash.execute(aCommand,stdout: STDOUT)  #   ::POpen4::shell(aCommand,aDir || @context.pwd)
  logger.debug errout if errout.to_nil
  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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rigup/utils/run.rb', line 42

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