]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Add a configuration file for default option values work
authorPhillip Berndt <phillip.berndt@googlemail.com>
Wed, 13 Dec 2017 21:08:11 +0000 (22:08 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Wed, 13 Dec 2017 21:08:11 +0000 (22:08 +0100)
See #94

README.md
autorandr.py

index bdaf638e7baeeb5e84d19fd68cdae5389b0193f7..4d92fedfce87a07e6e6cb11016a38acb7f467780 100644 (file)
--- a/README.md
+++ b/README.md
@@ -142,6 +142,10 @@ names in your configuration directory to have autorandr use any of them
 as the default configuration without you having to change the system-wide
 configuration.
 
+You can store default values for any option in an INI-file in
+`~/config/autorandr/settings.ini` in a section `config`. The most useful
+candidate for doing that is `skip-options`, if you need it.
+
 ## Hook scripts
 
 Three more scripts can be placed in the configuration directory (as 
index eae65a801b0254ad01687927aa09125b8727a21a..9c272a79f05b8b199ae43580fe212bd3a569b7fd 100755 (executable)
@@ -42,6 +42,11 @@ from distutils.version import LooseVersion as Version
 from functools import reduce
 from itertools import chain
 
+if sys.version_info.major == 2:
+    import ConfigParser as configparser
+else:
+    import configparser
+
 try:
     input = raw_input
 except NameError:
@@ -1008,6 +1013,14 @@ def dispatch_call_to_sessions(argv):
             X11_displays_done.add(display)
 
 
+def read_config(options, directory):
+    """Parse a configuration config.ini from directory and merge it into
+    the options dictionary"""
+    config = configparser.ConfigParser()
+    config.read(os.path.join(directory, "settings.ini"))
+    for key, value in config.items("config"):
+        options.setdefault("--%s" % key, value)
+
 def main(argv):
     try:
         opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh",
@@ -1046,6 +1059,7 @@ def main(argv):
             if os.path.isdir(system_profile_path):
                 profiles.update(load_profiles(system_profile_path))
                 profile_symlinks.update(get_symlinks(system_profile_path))
+                read_config(options, system_profile_path)
         # For the user's profiles, prefer the legacy ~/.autorandr if it already exists
         # profile_path is also used later on to store configurations
         profile_path = os.path.expanduser("~/.autorandr")
@@ -1055,6 +1069,7 @@ def main(argv):
         if os.path.isdir(profile_path):
             profiles.update(load_profiles(profile_path))
             profile_symlinks.update(get_symlinks(profile_path))
+            read_config(options, profile_path)
         # Sort by descending mtime
         profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"]))
     except Exception as e: