]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr.py
Improve usage information with GetoptError
[deb_pkgs/autorandr.git] / autorandr.py
index 1658f26e6a097b2733034c5e5fbdf6d5fe443bda..285c751bda4294e4dd0e07846320d37c5deebd2f 100755 (executable)
@@ -37,6 +37,9 @@ from distutils.version import LooseVersion as Version
 from itertools import chain
 from collections import OrderedDict
 
+import posix
+
+
 virtual_profiles = [
     # (name, description, callback)
     ("common", "Clone all connected outputs at the largest common resolution", None),
@@ -606,8 +609,10 @@ def main(argv):
     try:
        options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "help" ])[0])
     except getopt.GetoptError as e:
-        print(str(e))
-        options = { "--help": True }
+        print("Failed to parse options: {0}.\n"
+              "Use --help to get usage information.".format(str(e)),
+              file=sys.stderr)
+        sys.exit(posix.EX_USAGE)
 
     profiles = {}
     try:
@@ -713,12 +718,12 @@ if __name__ == '__main__':
     try:
         main(sys.argv)
     except AutorandrException as e:
-        print(file=sys.stderr)
         print(e, file=sys.stderr)
         sys.exit(1)
     except Exception as e:
-        trace = sys.exc_info()[2]
-        while trace.tb_next:
-            trace = trace.tb_next
-            print("\nUnhandled exception in line %d. Please report this as a bug:\n  %s" % (trace.tb_lineno, "\n  ".join(str(e).split("\n")),), file=sys.stderr)
-        sys.exit(1)
+        if not len(str(e)):  # BdbQuit
+            print("Exception: {0}".format(e.__class__.__name__))
+            sys.exit(2)
+
+        print("Unhandled exception ({0}). Please report this as a bug.".format(e), file=sys.stderr)
+        raise