Alon Bar-Lev has uploaded a new change for review.

Change subject: core: support different exit codes
......................................................................

core: support different exit codes

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1079726
Change-Id: I7b330bb3eaccc05798343931ff3feb70e43e0259
Signed-off-by: Alon Bar-Lev <alo...@redhat.com>
---
M ChangeLog
M README.environment
M src/otopi/__main__.py
M src/otopi/constants.py
M src/otopi/context.py
5 files changed, 33 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/32/35632/1

diff --git a/ChangeLog b/ChangeLog
index e9c0e00..436ff2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
 ????-??-?? - Version 1.3.1
 
+ * core: support different exit codes.
  * core: better message when executing process using invalid
    arguments or environment.
 
diff --git a/README.environment b/README.environment
index 5bfca8e..99f5c8e 100644
--- a/README.environment
+++ b/README.environment
@@ -46,6 +46,11 @@
     Directory where instaler was executed.
     Installer changes to '/' to avoid errors during program execution.
 
+BASE/exitCode(list)
+    List of dictionary entires, keys are priority, code.
+    Highest priority wins.
+    Keys should be based on Stages.PRIORITY_*.
+
 BASE/suppressEnvironmentKeys(list)
     Suppress output of environment keys.
 
diff --git a/src/otopi/__main__.py b/src/otopi/__main__.py
index f052f0b..028bff6 100644
--- a/src/otopi/__main__.py
+++ b/src/otopi/__main__.py
@@ -74,6 +74,12 @@
                     else:
                         environment[key] = value
 
+    def _getExitCode(self, environment):
+        return sorted(
+            environment[constants.BaseEnv.EXIT_CODE],
+            key=lambda x: x['priority'],
+        )[0]['code']
+
     def __init__(self):
         self._debug = int(
             os.environ.get(
@@ -97,7 +103,7 @@
                     constants.BaseEnv.EXECUTION_DIRECTORY
                 ]
             )
-            return True
+            return self._getExitCode(installer.environment)
         except main.PluginLoadException as e:
             print(
                 '***L:ERROR %s: %s' % (
@@ -107,7 +113,7 @@
             )
             if self._debug > 0:
                 traceback.print_exc()
-            return False
+            return constants.Const.EXIT_CODE_INITIALIZATION_ERROR
         except Exception as e:
             if self._debug > 0:
                 print(
@@ -116,11 +122,18 @@
                     ),
                 )
                 traceback.print_exc()
-            return False
+
+            # return failure if someone set, never success
+            code = self._getExitCode(installer.environment)
+            return (
+                constants.Const.EXIT_CODE_GENERAL_ERROR
+                if code == constants.Const.EXIT_CODE_SUCCESS
+                else code
+            )
 
 if __name__ == '__main__':
     installer = Installer()
-    sys.exit(0 if installer.main() else 1)
+    sys.exit(installer.main())
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/otopi/constants.py b/src/otopi/constants.py
index 808039e..f2fcea8 100644
--- a/src/otopi/constants.py
+++ b/src/otopi/constants.py
@@ -81,6 +81,9 @@
     CONFIG_SECTION_ENFORCE = 'environment:enforce'
     DIALOG_DIALECT_MACHINE = 'machine'
     DIALOG_DIALECT_HUMAN = 'human'
+    EXIT_CODE_SUCCESS = 0
+    EXIT_CODE_GENERAL_ERROR = 1
+    EXIT_CODE_INITIALIZATION_ERROR = 2
 
 
 @util.export
@@ -99,6 +102,7 @@
     ERROR = 'BASE/error'
     ABORTED = 'BASE/aborted'
     EXCEPTION_INFO = 'BASE/exceptionInfo'
+    EXIT_CODE = 'BASE/exitCode'
     LOG = 'BASE/log'
     PLUGIN_PATH = 'BASE/pluginPath'
     PLUGIN_GROUPS = 'BASE/pluginGroups'
diff --git a/src/otopi/context.py b/src/otopi/context.py
index db67025..c5d8fa6 100644
--- a/src/otopi/context.py
+++ b/src/otopi/context.py
@@ -208,6 +208,12 @@
             constants.BaseEnv.ERROR: False,
             constants.BaseEnv.ABORTED: False,
             constants.BaseEnv.EXCEPTION_INFO: [],
+            constants.BaseEnv.EXIT_CODE: [
+                {
+                    'priority': plugin.Stages.PRIORITY_LAST + 1,
+                    'code': constants.Const.EXIT_CODE_SUCCESS,
+                },
+            ],
             constants.BaseEnv.EXECUTION_DIRECTORY: '.',
             constants.BaseEnv.SUPPRESS_ENVIRONMENT_KEYS: [],
             constants.BaseEnv.LOG: False,


-- 
To view, visit http://gerrit.ovirt.org/35632
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b330bb3eaccc05798343931ff3feb70e43e0259
Gerrit-PatchSet: 1
Gerrit-Project: otopi
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to