-import json, ast
-import os, ast
-from util import user_dir, print_error
-
-from version import ELECTRUM_VERSION, SEED_VERSION
+import json
+import ast
+import threading
+import os
+from util import user_dir, print_error, print_msg
+config = None
+def get_config():
+ global config
+ return config
+def set_config(c):
+ global config
+ config = c
class SimpleConfig:
a SimpleConfig instance then reads the wallet file.
"""
def __init__(self, options={}):
+ self.lock = threading.Lock()
# system conf, readonly
self.system_config = {}
if options.get('portable') is not True:
self.read_system_config()
- # read path
- self.path = self.system_config.get('electrum_path')
- if self.path is None:
- self.path = user_dir()
-
- # user conf, writeable
- self.user_config = {}
- if options.get('portable') == False:
- self.read_user_config()
-
# command-line options
self.options_config = options
# init path
self.init_path()
- print_error( "electrum path", self.path)
+ # user conf, writeable
+ self.user_config = {}
+ self.read_user_config()
+
+ set_config(self)
+
def init_path(self):
- # Look for wallet file in the default data directory.
- # Make wallet directory if it does not yet exist.
+ # Read electrum path in the command line configuration
+ self.path = self.options_config.get('electrum_path')
+
+ # Read electrum path in the system configuration
+ if self.path is None:
+ self.path = self.system_config.get('electrum_path')
+
+ # If not set, use the user's default data directory.
+ if self.path is None:
+ self.path = user_dir()
+
+ # Make directory if it does not yet exist.
if not os.path.exists(self.path):
os.mkdir(self.path)
+ print_error( "electrum directory", self.path)
# portable wallet: use the same directory for wallet and headers file
#if options.get('portable'):
print "Warning: not changing '%s' because it was set in the system configuration"%key
else:
- self.user_config[key] = value
- if save: self.save_user_config()
+
+ with self.lock:
+ self.user_config[key] = value
+ if save:
+ self.save_user_config()
import ast
try:
out = ast.literal_eval(out)
- except:
+ except Exception:
print "type error for '%s': using default value"%key
out = default
return
try:
d = ast.literal_eval( data ) #parse raw data from reading wallet file
- except:
- raise IOError("Cannot read config file.")
+ except Exception:
+ print_msg("Error: Cannot read config file.")
+ return
self.user_config = d