Skip to content

Commit

Permalink
Use non-zero exit codes to indicate various situations; See #46
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Dec 8, 2015
1 parent 3b61836 commit 6c7ec4e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ and ``/etc/tracer/hooks/``. Such hook will be called when tracer determines, tha
If you want to run tracer's hooks and print no other output, use ``tracer --hooks-only``


Exit codes
----------

In some use-cases you may want to examine Tracer's results through exit codes (also known as status codes). See their
meanings:

======= ================================
1-99 Error exit codes
0 No affected applications
101 Found some affected applications
102 Found some affected daemons
103 Session restart needed
104 Reboot needed
======= ================================


Data structures
---------------

Expand Down
23 changes: 23 additions & 0 deletions tracer/controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def render(self):
view.assign("applications", self.applications)
view.assign("args", self.args)
view.render()
exit(self.status_code())

def render_helpers(self):
helper_controller = HelperController(self.args)
Expand Down Expand Up @@ -113,6 +114,28 @@ def render_interactive(self):
sys.stdout.write("\n-- " + _("Press <enter> to get list of applications") + " --")
input()

def status_code(self):
"""
0 - No affected applications
101 - Found some affected applications
102 - Found some affected daemons
103 - Session restart needed
104 - Reboot needed
"""
code = 0
if len(self.applications) > 0:
code = 101

if self.applications.count_type(Applications.TYPES['DAEMON']):
code = 102

if self.applications.count_type(Applications.TYPES['SESSION']):
code = 103

if self.applications.count_type(Applications.TYPES['STATIC']):
code = 104
return code

def _restartable_applications(self, applications, args):
return applications.exclude_types([
Applications.TYPES['STATIC'],
Expand Down
1 change: 1 addition & 0 deletions tracer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ def run():

except (UnsupportedDistribution, PathNotFound, LockedDatabase) as ex:
print(ex)
exit(1)
except (KeyboardInterrupt, EOFError):
print("")

0 comments on commit 6c7ec4e

Please sign in to comment.