From 2fcbc7f5433fab36b60bedf5a97dd610ef231721 Mon Sep 17 00:00:00 2001 From: luke Date: Sun, 28 May 2006 22:13:46 +0000 Subject: Adding an "execute" method to Puppet::Util, and including the module in element.rb git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1227 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/element.rb | 1 + lib/puppet/util.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'lib') diff --git a/lib/puppet/element.rb b/lib/puppet/element.rb index 916177d9c..7abc18fda 100644 --- a/lib/puppet/element.rb +++ b/lib/puppet/element.rb @@ -6,6 +6,7 @@ require 'puppet' # and provides a few simple across-the-board functions like 'noop' class Puppet::Element include Puppet + include Puppet::Util attr_writer :noop class << self diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 50a2e1e02..2f6136ef0 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -4,6 +4,9 @@ require 'sync' require 'puppet/lock' module Puppet + # A command failed to execute. + class ExecutionFailure < RuntimeError + end module Util require 'benchmark' @@ -346,6 +349,19 @@ module Util end end + # Execute the desired command, and return the status and output. + def execute(command, failonfail = true) + output = %x{#{command}} + + if failonfail + unless $? == 0 + raise ExecutionFailure, output + end + end + + return output + end + module_function :benchmark def memory -- cgit