|
@@ -361,16 +361,16 @@ def make_command(
|
|
|
def handle_errors(returncode, result, args, kwargs):
|
|
|
"""Error handler for :func:`run_command()` and similar functions
|
|
|
|
|
|
- The function returns *result* if *returncode* is equal to 0,
|
|
|
- otherwise it reports errors based on the current settings.
|
|
|
-
|
|
|
The functions which are using this function to handle errors,
|
|
|
can be typically called with an *errors* parameter.
|
|
|
This function can handle one of the following values: raise,
|
|
|
fatal, status, exit, and ignore. The value raise is a default.
|
|
|
|
|
|
+ If returncode is 0, *result* is returned, unless
|
|
|
+ ``errors="status"`` is set.
|
|
|
+
|
|
|
If *kwargs* dictionary contains key ``errors``, the value is used
|
|
|
- to determine the behavior on error.
|
|
|
+ to determine the return value and the behavior on error.
|
|
|
The value ``errors="raise"`` is a default in which case a
|
|
|
``CalledModuleError`` exception is raised.
|
|
|
|
|
@@ -406,13 +406,13 @@ def handle_errors(returncode, result, args, kwargs):
|
|
|
code = " ".join(args)
|
|
|
return module, code
|
|
|
|
|
|
+ handler = kwargs.get("errors", "raise")
|
|
|
+ if handler.lower() == "status":
|
|
|
+ return returncode
|
|
|
if returncode == 0:
|
|
|
return result
|
|
|
- handler = kwargs.get("errors", "raise")
|
|
|
if handler.lower() == "ignore":
|
|
|
return result
|
|
|
- elif handler.lower() == "status":
|
|
|
- return returncode
|
|
|
elif handler.lower() == "fatal":
|
|
|
module, code = get_module_and_code(args, kwargs)
|
|
|
fatal(
|
|
@@ -695,7 +695,7 @@ def write_command(*args, **kwargs):
|
|
|
returncode = process.poll()
|
|
|
if _capture_stderr and returncode:
|
|
|
sys.stderr.write(stderr)
|
|
|
- return handle_errors(returncode, returncode, args, kwargs)
|
|
|
+ return handle_errors(returncode, None, args, kwargs)
|
|
|
|
|
|
|
|
|
def exec_command(
|