]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Merge pull request #46 from HyperBaton/master
authorPhillip Berndt <phillip.berndt@googlemail.com>
Mon, 28 Mar 2016 12:50:08 +0000 (14:50 +0200)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Mon, 28 Mar 2016 12:50:08 +0000 (14:50 +0200)
Add ability to remove profile

README.md
autorandr.py
contrib/bash_completion/autorandr

index fca170c1190923d4eeeb7e879da28d98ef79db8a..52867d176952bf4cbafcf193ca733424896ba440 100644 (file)
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ Contributors to this version of autorandr are:
 * stormc
 * tachylatus
 * andersonjacob
+* Simon Wydooghe
 
 ## How to use
 
index 596d3ffb504d20f04d3cbad2dba2956efe660ddf..a65322d90c4ea4168a4748ba47befb5423e1de85 100755 (executable)
@@ -33,12 +33,17 @@ import posix
 import re
 import subprocess
 import sys
+import shutil
 
 from collections import OrderedDict
 from distutils.version import LooseVersion as Version
 from functools import reduce
 from itertools import chain
 
+try:
+    input = raw_input
+except NameError:
+    pass
 
 virtual_profiles = [
     # (name, description, callback)
@@ -53,6 +58,7 @@ Usage: autorandr [options]
 -h, --help              get this small help
 -c, --change            reload current setup
 -s, --save <profile>    save your current setup to profile <profile>
+-r, --remove <profile>  remove profile <profile>
 -l, --load <profile>    load profile <profile>
 -d, --default <profile> make profile <profile> the default profile
 --skip-options <option> comma separated list of xrandr arguments (e.g. "gamma")
@@ -731,7 +737,7 @@ def exec_scripts(profile_path, script_name, meta_information=None):
 
 def main(argv):
     try:
-       options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "debug", "skip-options=", "help" ])[0])
+        options = dict(getopt.getopt(argv[1:], "s:r:l:d:cfh", [ "dry-run", "change", "default=", "save=", "remove=", "load=", "force", "fingerprint", "config", "debug", "skip-options=", "help" ])[0])
     except getopt.GetoptError as e:
         print("Failed to parse options: {0}.\n"
               "Use --help to get usage information.".format(str(e)),
@@ -791,6 +797,33 @@ def main(argv):
         print("Saved current configuration as profile '%s'" % options["--save"])
         sys.exit(0)
 
+    if "-r" in options:
+        options["--remove"] = options["-r"]
+    if "--remove" in options:
+        if options["--remove"] in ( x[0] for x in virtual_profiles ):
+            raise AutorandrException("Cannot remove profile '%s':\nThis configuration name is a reserved virtual configuration." % options["--remove"])
+        if options["--remove"] not in profiles.keys():
+            raise AutorandrException("Cannot remove profile '%s':\nThis profile does not exist." % options["--remove"])
+        try:
+            remove = True
+            profile_folder = os.path.join(profile_path, options["--remove"])
+            profile_dirlist = os.listdir(profile_folder)
+            profile_dirlist.remove("config")
+            profile_dirlist.remove("setup")
+            if profile_dirlist:
+                print("Profile folder '%s' contains the following additional files:\n---\n%s\n---" % (options["--remove"], "\n".join(profile_dirlist)))
+                response = input("Do you really want to remove profile '%s'? If so, type 'yes': " % options["--remove"]).strip()
+                if response != "yes":
+                    remove = False
+            if remove is True:
+                shutil.rmtree(profile_folder)
+                print("Removed profile '%s'" % options["--remove"])
+            else:
+                print("Profile '%s' was not removed" % options["--remove"])
+        except Exception as e:
+            raise AutorandrException("Failed to remove profile '%s'" % (options["--remove"],), e)
+        sys.exit(0)
+
     if "-h" in options or "--help" in options:
         exit_help()
 
index 7a8b81b5dc4d0714619c5e3bbdd760d78ba20dd3..a106b7e2ff3bb3ed82edf3a7f31571dacd2cb189 100644 (file)
@@ -8,8 +8,8 @@ _autorandr ()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 
-       opts="-h -c -s -l -d"
-       lopts="--help --change --save --load --default --force --fingerprint --config --dry-run"
+       opts="-h -c -s -r -l -d"
+       lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
        if [ -d ~/.autorandr ]; then
                prfls="`find ~/.autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
        elif [ -d ~/.config/autorandr ]; then
@@ -35,7 +35,7 @@ _autorandr ()
                esac
 
        case "${prev}" in
-               -l|--load|-d|--default)
+               -r|--remove|-l|--load|-d|--default)
                        COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) )
                        return 0
                        ;;