class Command(object):
Known subclasses: gbp.command_wrappers.CatenateTarArchive
, gbp.command_wrappers.CatenateZipArchive
, gbp.command_wrappers.DpkgSourceExtract
, gbp.command_wrappers.GitCommand
, gbp.command_wrappers.PackTarArchive
, gbp.command_wrappers.RemoveTree
, gbp.command_wrappers.RunAtCommand
, gbp.command_wrappers.UnpackTarArchive
, gbp.command_wrappers.UnpackZipArchive
, gbp.deb.DpkgCompareVersions
, gbp.pkg.pristinetar.PristineTar
Wraps a shell command, so we don't have to store any kind of command line options in one of the git-buildpackage commands
Note that it does not do any shell quoting even with shell=True so you have to quote arguments yourself if necessary.
If cmd doesn't contain a path component it will be looked up in $PATH.
Method | __call__ |
Run the command and raise exception on errors |
Method | __init__ |
Undocumented |
Method | call |
Like __call__ but let the caller handle the return status. |
Instance Variable | args |
Undocumented |
Instance Variable | capture |
Undocumented |
Instance Variable | capture |
Undocumented |
Instance Variable | cmd |
Undocumented |
Instance Variable | cwd |
Undocumented |
Instance Variable | env |
Undocumented |
Instance Variable | err |
Undocumented |
Instance Variable | retcode |
Undocumented |
Instance Variable | run |
Undocumented |
Instance Variable | shell |
Undocumented |
Instance Variable | stderr |
Undocumented |
Instance Variable | stdout |
Undocumented |
Static Method | _f |
Build error string template |
Method | __call |
Wraps subprocess.call so we can be verbose and fix Python's SIGPIPE handling |
Method | _format |
Log an error message |
Method | _log |
Log an error message |
Method | _reset |
Undocumented |
gbp.command_wrappers.CatenateTarArchive
, gbp.command_wrappers.CatenateZipArchive
, gbp.command_wrappers.DpkgSourceExtract
, gbp.command_wrappers.RunAtCommand
, gbp.deb.DpkgCompareVersions
Run the command and raise exception on errors
If run quietly it will not print an error message via the gbp.log
logging API.
Whether the command prints anything to stdout/stderr depends on the capture_stderr, capture_stdout instance variables.
All errors will be reported as subclass of the CommandExecFailed
exception including a non zero exit status of the run command.
Parameters | |
args:list of strings | additional command line arguments |
quiet: bool >>> Command("/bin/true")(["foo", "bar"]) >>> Command("/foo/bar")(quiet=True) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... gbp.command_wrappers.CommandExecFailed | don't log failed execution to stderr. Mostly useful during unit testing |
gbp.command_wrappers.CatenateTarArchive
, gbp.command_wrappers.CatenateZipArchive
, gbp.command_wrappers.DpkgSourceExtract
, gbp.command_wrappers.GitCommand
, gbp.command_wrappers.PackTarArchive
, gbp.command_wrappers.RemoveTree
, gbp.command_wrappers.UnpackTarArchive
, gbp.command_wrappers.UnpackZipArchive
, gbp.deb.DpkgCompareVersions
, gbp.pkg.pristinetar.PristineTar
, gbp.scripts.common.hook.Hook
Undocumented
Like __call__
but let the caller handle the return status.
Only raise CommandExecFailed
if we failed to launch the command at all (i.e. if it does not exist) not if the command returned nonzero.
Logs errors using gbp.log
by default.
Parameters | |
args:list of strings | additional command line arguments |
quiet:bool | don't log failed execution to stderr. Mostly useful during unit testing |
Returns | |
int >>> Command("/bin/true").call(["foo", "bar"]) 0 >>> Command("/foo/bar").call(["foo", "bar"]) # doctest:+ELLIPSIS Traceback (most recent call last): ... gbp.command_wrappers.CommandExecFailed: execution failed: ... >>> c = Command("/bin/true", capture_stdout=True, ... extra_env={'LC_ALL': 'C'}) >>> c.call(["--version"]) 0 >>> c.stdout.startswith('true') True >>> c = Command("/bin/false", capture_stdout=True, ... extra_env={'LC_ALL': 'C'}) >>> c.call(["--help"]) 1 >>> c.stdout.startswith('Usage:') True | the exit status of the run command |
gbp.command_wrappers.CatenateZipArchive
, gbp.command_wrappers.DpkgSourceExtract
, gbp.command_wrappers.GitCommand
, gbp.command_wrappers.PackTarArchive
, gbp.command_wrappers.RemoveTree
, gbp.command_wrappers.UnpackTarArchive
, gbp.command_wrappers.UnpackZipArchive
, gbp.deb.DpkgCompareVersions
, gbp.pkg.pristinetar.PristineTar
, gbp.scripts.common.hook.Hook
Undocumented
Build error string template
'%' expansion is performed while curly braces in args are quoted so we don't accidentally try to expand them when printing an error message later that uses one of our predefined error variables stdout, stderr, stderr_or_reason and self.err_reason.
>>> Command._f("foo %s", "bar") 'foo bar' >>> Command._f("{foo} %s %s", "bar", "baz") '{foo} bar baz' >>> Command._f("{foo} bar") '{foo} bar'