X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Fsimple_config.py;h=d4893b11ebba4c05e07b3cd24b5ec44d686ff5e8;hb=34f0a65c49492ed62f399fd74aa25a6a4edcfc33;hp=b70e5c96e85ecd2c47e5e32a92f91970265be97f;hpb=221fa5848f0348bd02586c86a50feb9916c7cea2;p=electrum-nvc.git diff --git a/lib/simple_config.py b/lib/simple_config.py index b70e5c9..d4893b1 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -135,10 +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.""" result = {} - if os.path.exists(SYSTEM_CONFIG_PATH): + if os.path.exists(path): try: import ConfigParser except ImportError: @@ -146,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 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 = {} - return d + if not type(result) is dict: + return {} + + return result