download_strategy: allow to suppress output

This commit is contained in:
Vlad Shablinsky 2016-07-12 10:03:32 +03:00 committed by Xu Cheng
parent 1693ddbdcb
commit 09d21ad258
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE

View File

@ -6,6 +6,7 @@ class AbstractDownloadStrategy
include FileUtils
attr_reader :meta, :name, :version, :resource
attr_reader :shutup
def initialize(name, resource)
@name = name
@ -19,6 +20,19 @@ class AbstractDownloadStrategy
def fetch
end
# Supress output
def shutup!
@shutup = true
end
def puts(*args)
super(*args) unless shutup
end
def ohai(*args)
super(*args) unless shutup
end
# Unpack {#cached_location} into the current working directory, and possibly
# chdir into the newly-unpacked directory.
# Unlike {Resource#stage}, this does not take a block.
@ -59,6 +73,14 @@ class AbstractDownloadStrategy
args
end
def safe_system(*args)
if @shutup
quiet_system(*args) || raise(ErrorDuringExecution.new(args.shift, *args))
else
super(*args)
end
end
def quiet_safe_system(*args)
safe_system(*expand_safe_system_args(args))
end