]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr.py
Python version: Option handling for unrecognized options
[deb_pkgs/autorandr.git] / autorandr.py
index ce6856a0830a254449857003145041cb8dd62663..7c12b5fc0cf981d171dca047cab082bc4dbfe45d 100755 (executable)
@@ -416,19 +416,23 @@ def exec_scripts(profile_path, script_name):
             subprocess.call(script)
 
 def main(argv):
-    options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "help" ])[0])
+    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 }
 
     profile_path = os.path.expanduser("~/.autorandr")
 
     try:
         profiles = load_profiles(profile_path)
-    except Exception, e:
+    except Exception as e:
         print("Failed to load profiles:\n%s" % str(e), file=sys.stderr)
         sys.exit(1)
 
     try:
         config, modes = parse_xrandr_output()
-    except Exception, e:
+    except Exception as e:
         print("Failed to parse current configuration from XRandR:\n%s" % str(e), file=sys.stderr)
         sys.exit(1)
 
@@ -448,7 +452,7 @@ def main(argv):
             sys.exit(1)
         try:
             save_configuration(os.path.join(profile_path, options["--save"]), config)
-        except Exception, e:
+        except Exception as e:
             print("Failed to save current configuration as profile '%s':\n%s" % (options["--save"], str(e)), file=sys.stderr)
             sys.exit(1)
         print("Saved current configuration as profile '%s'" % options["--save"])
@@ -497,7 +501,7 @@ def main(argv):
                 exec_scripts(os.path.join(profile_path, load_profile), "preswitch")
                 apply_configuration(profile, True)
                 exec_scripts(os.path.join(profile_path, load_profile), "postswitch")
-        except Exception, e:
+        except Exception as e:
             print("Failed to apply profile '%s':\n%s" % (load_profile, str(e)), file=sys.stderr)
             sys.exit(1)
 
@@ -506,6 +510,6 @@ def main(argv):
 if __name__ == '__main__':
     try:
         main(sys.argv)
-    except Exception, e:
+    except Exception as e:
         print("General failure. Please report this as a bug:\n%s" % (str(e),), file=sys.stderr)
         sys.exit(1)