Merge pull request #4543 from reitermarkus/verbose-system_command

Pass `verbose` to unpack strategies.
This commit is contained in:
Markus Reiter 2018-08-03 10:47:51 +02:00 committed by GitHub
commit 28fd59672a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 80 additions and 41 deletions

View File

@ -357,7 +357,8 @@ end
class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy
def stage
UnpackStrategy::Uncompressed.new(cached_location)
.extract(basename: basename_without_params)
.extract(basename: basename_without_params,
verbose: ARGV.verbose? && !shutup)
end
end

View File

@ -28,8 +28,9 @@ class SystemCommand
end
def run!
puts command.shelljoin.gsub(/\\=/, "=") if verbose? || ARGV.debug?
@merged_output = []
odebug command.shelljoin
each_output_line do |type, line|
case type
@ -46,13 +47,16 @@ class SystemCommand
result
end
def initialize(executable, args: [], sudo: false, input: [], print_stdout: false, print_stderr: true, must_succeed: false, env: {}, **options)
def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false,
print_stdout: false, print_stderr: true, verbose: false, **options)
@executable = executable
@args = args
@sudo = sudo
@input = [*input]
@print_stdout = print_stdout
@print_stderr = print_stderr
@verbose = verbose
@must_succeed = must_succeed
options.assert_valid_keys!(:chdir)
@options = options
@ -71,7 +75,7 @@ class SystemCommand
attr_reader :executable, :args, :input, :options, :env
attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed?
attr_predicate :sudo?, :print_stdout?, :print_stderr?, :verbose?, :must_succeed?
def env_args
set_variables = env.reject { |_, value| value.nil? }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module UnpackStrategy
class Air
include UnpackStrategy
@ -17,13 +19,17 @@ module UnpackStrategy
@dependencies ||= [Hbc::CaskLoader.load("adobe-air")]
end
AIR_APPLICATION_INSTALLER =
"/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer"
private_constant :AIR_APPLICATION_INSTALLER
private
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command!(
"/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer",
system_command! AIR_APPLICATION_INSTALLER,
args: ["-silent", "-location", unpack_dir, path],
)
verbose: verbose
end
end
end

View File

@ -17,7 +17,9 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
FileUtils.cp path, unpack_dir/basename, preserve: true
quiet_flags = verbose ? [] : ["-q"]
system_command! "bunzip2", args: [*quiet_flags, unpack_dir/basename]
system_command! "bunzip2",
args: [*quiet_flags, unpack_dir/basename],
verbose: verbose
end
end
end

View File

@ -15,7 +15,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "cabextract",
args: ["-d", unpack_dir, "--", path],
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
def dependencies

View File

@ -4,8 +4,6 @@ module UnpackStrategy
class Dmg
include UnpackStrategy
using Magic
module Bom
DMG_METADATA = Set.new %w[
.background
@ -51,7 +49,7 @@ module UnpackStrategy
class Mount
include UnpackStrategy
def eject
def eject(verbose: false)
tries ||= 3
return unless path.exist?
@ -59,11 +57,13 @@ module UnpackStrategy
if tries > 1
system_command! "diskutil",
args: ["eject", path],
print_stderr: false
print_stderr: false,
verbose: verbose
else
system_command! "diskutil",
args: ["unmount", "force", path],
print_stderr: false
print_stderr: false,
verbose: verbose
end
rescue ErrorDuringExecution => e
raise e if (tries -= 1).zero?
@ -81,10 +81,14 @@ module UnpackStrategy
filelist.puts(path.bom)
filelist.close
system_command! "mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path]
system_command! "mkbom",
args: ["-s", "-i", filelist.path, "--", bomfile.path],
verbose: verbose
end
system_command! "ditto", args: ["--bom", bomfile.path, "--", path, unpack_dir]
system_command! "ditto",
args: ["--bom", bomfile.path, "--", path, unpack_dir],
verbose: verbose
FileUtils.chmod "u+w", Pathname.glob(unpack_dir/"**/*").reject(&:symlink?)
end
@ -111,7 +115,7 @@ module UnpackStrategy
raise "No mounts found in '#{path}'; perhaps it is a bad disk image?" if mounts.empty?
mounts.each do |mount|
mount.extract(to: unpack_dir)
mount.extract(to: unpack_dir, verbose: verbose)
end
end
end
@ -120,10 +124,11 @@ module UnpackStrategy
Dir.mktmpdir do |mount_dir|
mount_dir = Pathname(mount_dir)
without_eula = system_command("hdiutil",
without_eula = system_command "hdiutil",
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", mount_dir, path],
input: "qn\n",
print_stderr: false)
print_stderr: false,
verbose: verbose
# If mounting without agreeing to EULA succeeded, there is none.
plist = if without_eula.success?
@ -131,12 +136,13 @@ module UnpackStrategy
else
cdr_path = mount_dir/path.basename.sub_ext(".cdr")
system_command!("hdiutil", args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path])
system_command! "hdiutil",
args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path],
verbose: verbose
with_eula = system_command!(
"/usr/bin/hdiutil",
with_eula = system_command! "hdiutil",
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", mount_dir, cdr_path],
)
verbose: verbose
if verbose && !(eula_text = without_eula.stdout).empty?
ohai "Software License Agreement for '#{path}':"
@ -158,7 +164,9 @@ module UnpackStrategy
begin
yield mounts
ensure
mounts.each(&:eject)
mounts.each do |mount|
mount.eject(verbose: verbose)
end
end
end
end

View File

@ -28,7 +28,8 @@ module UnpackStrategy
system_command! "fossil",
args: ["open", path, *args],
chdir: unpack_dir,
env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -21,7 +21,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "unar",
args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", path],
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -18,7 +18,8 @@ module UnpackStrategy
FileUtils.cp path, unpack_dir/basename, preserve: true
quiet_flags = verbose ? [] : ["-q"]
system_command! "gunzip",
args: [*quiet_flags, "-N", "--", unpack_dir/basename]
args: [*quiet_flags, "-N", "--", unpack_dir/basename],
verbose: verbose
end
end
end

View File

@ -21,7 +21,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "lha",
args: ["xq2w=#{unpack_dir}", path],
env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -23,7 +23,8 @@ module UnpackStrategy
quiet_flags = verbose ? [] : ["-q"]
system_command! "lzip",
args: ["-d", *quiet_flags, unpack_dir/basename],
env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -17,7 +17,8 @@ module UnpackStrategy
quiet_flags = verbose ? [] : ["-q"]
system_command! "unlzma",
args: [*quiet_flags, "--", unpack_dir/basename],
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
def dependencies

View File

@ -13,7 +13,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "hg",
args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir],
env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -21,7 +21,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "7zr",
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -21,7 +21,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "unrar",
args: ["x", "-inul", path, unpack_dir],
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -13,7 +13,8 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "svn",
args: ["export", "--force", ".", unpack_dir],
chdir: path.to_s
chdir: path.to_s,
verbose: verbose
end
end
end

View File

@ -35,11 +35,13 @@ module UnpackStrategy
if DependencyCollector.tar_needs_xz_dependency? && Xz.can_extract?(path)
tmpdir = Pathname(tmpdir)
Xz.new(path).extract(to: tmpdir)
Xz.new(path).extract(to: tmpdir, verbose: verbose)
tar_path = tmpdir.children.first
end
system_command! "tar", args: ["xf", tar_path, "-C", unpack_dir]
system_command! "tar",
args: ["xf", tar_path, "-C", unpack_dir],
verbose: verbose
end
end
end

View File

@ -15,7 +15,9 @@ module UnpackStrategy
private
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "xar", args: ["-x", "-f", path, "-C", unpack_dir]
system_command! "xar",
args: ["-x", "-f", path, "-C", unpack_dir],
verbose: verbose
end
end
end

View File

@ -23,7 +23,8 @@ module UnpackStrategy
quiet_flags = verbose ? [] : ["-q"]
system_command! "unxz",
args: [*quiet_flags, "-T0", "--", unpack_dir/basename],
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) }
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) },
verbose: verbose
end
end
end

View File

@ -16,7 +16,9 @@ module UnpackStrategy
def extract_to_dir(unpack_dir, basename:, verbose:)
quiet_flags = verbose ? [] : ["-qq"]
system_command! "unzip", args: [*quiet_flags, path, "-d", unpack_dir]
system_command! "unzip",
args: [*quiet_flags, path, "-d", unpack_dir],
verbose: verbose
end
end
end