Bumped version 1.5.2
[rainbowstream.git] / rainbowstream / config.py
index 9cc2310af1209112296ee9506db7e196a48fe60d..f97b2099740da2a5dc22ee26e2cf50254509dbed 100644 (file)
@@ -6,13 +6,21 @@ from collections import OrderedDict
 
 # Regular expression for comments in config file
 comment_re = re.compile(
-    '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
+    '(^)[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
     re.DOTALL | re.MULTILINE
 )
 
 # Config dictionary
 c = {}
 
+def user_filepath():
+    """
+    Determine the user's config file location
+    """
+    if 'RAINBOW_CONFIG' in os.environ:
+        return os.environ['RAINBOW_CONFIG']
+
+    return os.path.expanduser("~") + os.sep + '.rainbow_config.json'
 
 def fixup(adict, k, v):
     """
@@ -43,12 +51,14 @@ def get_all_config():
     Get all config
     """
     try:
-        path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+        path = user_filepath()
         data = load_config(path)
         # Hard to set from prompt
         data.pop('ONLY_LIST', None)
         data.pop('IGNORE_LIST', None)
         data.pop('FORMAT', None)
+        data.pop('QUOTE_FORMAT', None)
+        data.pop('NOTIFY_FORMAT', None)
         return data
     except:
         return []
@@ -87,7 +97,7 @@ def set_config(key, value):
     # Update global config
     c[key] = value
     # Load current user config
-    path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+    path = user_filepath()
     data = {}
     try:
         data = load_config(path)
@@ -108,7 +118,7 @@ def delete_config(key):
     """
     Delete a config key
     """
-    path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+    path = user_filepath()
     try:
         data = load_config(path)
     except:
@@ -134,8 +144,7 @@ def reload_config():
     Reload config
     """
     try:
-        rainbow_config = os.path.expanduser("~") + \
-            os.sep + '.rainbow_config.json'
+        rainbow_config = user_filepath()
         data = load_config(rainbow_config)
         for d in data:
             c[d] = data[d]
@@ -157,12 +166,12 @@ def init_config():
     except:
         pass
     # Load user's config
-    rainbow_config = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+    rainbow_config = user_filepath()
     try:
         data = load_config(rainbow_config)
         for d in data:
             c[d] = data[d]
-    except ValueError as e:
+    except (IOError, ValueError) as e:
         c['USER_JSON_ERROR'] = str(e)
     # Load default theme
     theme_file = os.path.dirname(__file__) + \