read_user_config_function=None, read_user_dir_function=None):
# This is the holder of actual options for the current user.
- self.current_options = {}
+ self.read_only_options = {}
# This lock needs to be acquired for updating and reading the config in
# a thread-safe way.
self.lock = threading.RLock()
# system conf
system_config = read_system_config_function()
self.system_config_keys = system_config.keys()
- self.current_options.update(system_config)
+ self.read_only_options.update(system_config)
# update the current options with the command line options last (to
# override both others).
- self.current_options.update(options)
+ self.read_only_options.update(options)
# init path
self.init_path()
# user config.
self.user_config = read_user_config_function(self.path)
- # The user config is overwritten by the current config!
- self.user_config.update(self.current_options)
- self.current_options = self.user_config
set_config(self) # Make a singleton instance of 'self'
def init_path(self):
-
# Read electrum path in the command line configuration
- self.path = self.current_options.get('electrum_path')
+ self.path = self.read_only_options.get('electrum_path')
# If not set, use the user's default data directory.
if self.path is None:
with self.lock:
self.user_config[key] = value
- self.current_options[key] = value
if save:
self.save_user_config()
def get(self, key, default=None):
out = None
with self.lock:
- out = self.current_options.get(key, default)
+ out = self.read_only_options.get(key)
+ if not out:
+ out = self.user_config.get(key, default)
return out
def is_modifiable(self, key):
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:
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