[mousetrap/gnome3-wip: 136/240] Add configuration search path.



commit 33d370668d895b787fb7bb756ea05bad6fdc9eca
Author: Stoney Jackson <dr stoney gmail com>
Date:   Mon Jun 23 19:05:58 2014 -0400

    Add configuration search path.

 src/mousetrap/config.py |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/mousetrap/config.py b/src/mousetrap/config.py
index aba91db..80c9a86 100644
--- a/src/mousetrap/config.py
+++ b/src/mousetrap/config.py
@@ -1,15 +1,23 @@
 from yaml import safe_load
-from os.path import dirname
+from os.path import dirname, expanduser, exists
+from os import getcwd
 from copy import deepcopy
 
 
 class Config(dict):
-    DEFAULT_CONFIG_PATH = dirname(__file__) + '/' + 'config_default.yaml'
+    SEARCH_PATH = [
+            dirname(__file__) + '/' + 'config_default.yaml',
+            expanduser('~') + '/.mousetrap.yaml',
+            getcwd() + '/mousetrap.yaml'
+            ]
 
     def __init__(self):
-        with open(self.DEFAULT_CONFIG_PATH) as config_file:
-            defaults = safe_load(config_file)
-            _rmerge(self, defaults)
+        for path in self.SEARCH_PATH:
+            if exists(path):
+                print("loading %s" % (path))
+                with open(path) as config_file:
+                    config = safe_load(config_file)
+                    _rmerge(self, config)
 
     def __getitem__(self, key):
         '''


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]