Module: Bunchr::Utils

Included in:
Packages, Software
Defined in:
lib/bunchr/utils.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject

handle to the top level logger



26
27
28
# File 'lib/bunchr/utils.rb', line 26

def logger
  Bunchr::Logger.logger
end

#ohaiObject

handle to the top level ohai for generic system information



31
32
33
# File 'lib/bunchr/utils.rb', line 31

def ohai
  Bunchr::Ohai.ohai
end

#sh(cmd, env = {}, dir = nil) ⇒ Object

Execute a shell command, with optional environment. stdout and stderr will be sent to the logger if the command exits with non-zero status.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bunchr/utils.rb', line 10

def sh(cmd, env={}, dir=nil)
  logger.info("Executing: [#{cmd.gsub(/\s{2,}/, ' ')}]")

  output = ''
  status = systemu("#{cmd}", 
                   :stdout => output,
                   :stderr => output,
                   :env => env,
                   :cwd => dir)
  if status.exitstatus > 0
    logger << output
    fail "Command failed with status (#{status.exitstatus}): [#{cmd.gsub(/\s{2,}/, ' ')}]."
  end
end