[Yum-devel] [PATCH 1/2] Allow changing the exit code on non-fatal errors.
Zdeněk Pavlas
zpavlas at redhat.com
Tue Mar 6 12:06:01 UTC 2012
Currently, doCommand() may return result=1 to indicate a fatal error,
or result=0/2 to signal success. Minor errors are usually handled just
by printing an error message, but they can't change the exit code.
Use a read-write attribute instead of 0 as the exit code, so that minor
errors can change it without disturbing the control flow.
---
yum/__init__.py | 1 +
yummain.py | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/yum/__init__.py b/yum/__init__.py
index fab3553..eb946d9 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -210,6 +210,7 @@ class YumBase(depsolve.Depsolve):
self.run_with_package_names = set()
self._cleanup = []
+ self.exit_code = 0
def __del__(self):
self.close()
diff --git a/yummain.py b/yummain.py
index e1a9702..c473df6 100755
--- a/yummain.py
+++ b/yummain.py
@@ -160,7 +160,7 @@ def main(args):
for msg in resultmsgs:
verbose_logger.log(logginglevels.INFO_2, '%s', msg)
if unlock(): return 200
- return 0
+ return base.exit_code
elif result == 1:
# Fatal error
for msg in resultmsgs:
@@ -199,7 +199,7 @@ def main(args):
if result == 0:
# Normal exit
if unlock(): return 200
- return 0
+ return base.exit_code
elif result == 1:
# Fatal error
for msg in resultmsgs:
@@ -257,7 +257,7 @@ def main(args):
verbose_logger.log(logginglevels.INFO_2, _('Complete!'))
if unlock(): return 200
- return return_code
+ return return_code or base.exit_code
def hotshot(func, *args, **kwargs):
"""Profile the given function using the hotshot profiler.
--
1.7.4.4
More information about the Yum-devel
mailing list