# Otherwise just exit
sys.exit(0)
+ @staticmethod
+ def terminate(message, code=2):
+ """
+ Convenience function to terminate the program gracefully with a message
+ """
+ # Print the message
+ if message:
+ sys.stderr.write("%s\n" % message)
+
+ # Terminate with the given code
+ raise SystemExit(code)
+
def __get_list(self, backend, slug):
"""
Fetches a list or terminates the program if we could not find the list.
# Terminate because we could not find the list
if not list:
- sys.stderr.write("Could not find list '%s'\n" % slug)
- raise SystemExit(2)
+ self.terminate("Could not find list '%s'" % slug)
return list
# If we could not find a key, we cannot delete it
if not key:
- print("Could not find key %s" % args.key)
- return 2
+ self.terminate("Could not find key %s" % args.key)
# Delete the key
key.delete(deleted_by=args.deleted_by)
# Fail if we cannot find the report
if not report:
- print("Could not find report %s" % args.id)
- return 2
+ self.terminate("Could not find report %s" % args.id)
# Close the report
report.close(