Added more tests for user config parsing.
[electrum-nvc.git] / lib / simple_config.py
index b4455bb..d4893b1 100644 (file)
@@ -135,9 +135,10 @@ class SimpleConfig(object):
             import stat
             os.chmod(path, stat.S_IREAD | stat.S_IWRITE)
 
-def read_system_config():
+def read_system_config(path=SYSTEM_CONFIG_PATH):
     """Parse and return the system config settings in /etc/electrum.conf."""
-    if os.path.exists(SYSTEM_CONFIG_PATH):
+    result = {}
+    if os.path.exists(path):
         try:
             import ConfigParser
         except ImportError:
@@ -145,30 +146,33 @@ def read_system_config():
             return
 
         p = ConfigParser.ConfigParser()
-        p.read(SYSTEM_CONFIG_PATH)
-        result = {}
         try:
+            p.read(path)
             for k, v in p.items('client'):
                 result[k] = v
-        except ConfigParser.NoSectionError:
+        except (ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError):
             pass
-        return result
+
+    return result
 
 def read_user_config(path):
     """Parse and store the user config settings in electrum.conf into user_config[]."""
-    if not path: return
+    if not path: return {}  # Return a dict, since we will call update() on it.
 
     config_path = os.path.join(path, "config")
+    result = {}
     if os.path.exists(config_path):
         try:
+
             with open(config_path, "r") as f:
                 data = f.read()
-        except IOError:
-            return
-        try:
-            d = ast.literal_eval( data )  #parse raw data from reading wallet file
+            result = ast.literal_eval( data )  #parse raw data from reading wallet file
+
         except Exception:
             print_msg("Error: Cannot read config file.")
-            return
+            result = {}
+
+        if not type(result) is dict:
+            return {}
 
-        return d
+    return result