Fixed merged conflict and added folder creation on first load
authorMaran <maran.hidskes@gmail.com>
Fri, 21 Sep 2012 14:57:54 +0000 (16:57 +0200)
committerMaran <maran.hidskes@gmail.com>
Fri, 21 Sep 2012 14:57:54 +0000 (16:57 +0200)
1  2 
lib/interface.py
lib/simple_config.py

@@@ -26,8 -26,10 +26,9 @@@ from util import print_erro
  DEFAULT_TIMEOUT = 5
  DEFAULT_SERVERS = [ 'ecdsa.org:50001:t', 
                      'electrum.novit.ro:50001:t', 
 -                    'uncle-enzo.info:50001:t', 
                      'electrum.bytesized-hosting.com:50001:t']  # list of default servers
  
+ proxy_modes = ['none', 'socks4', 'socks5', 'http' ]
  
  def replace_keys(obj, old_key, new_key):
      if isinstance(obj, dict):
@@@ -3,40 -3,38 +3,56 @@@ import o
  from util import user_dir
  
  class SimpleConfig:
 -  default_options = {"gui": "lite", "proxy": { "mode": "none", "host":"localhost", "port":"8080" },
 -                    "winpos-qt": [100, 100, 840, 400], "winpos-lite": [4, 25, 351, 149], "history": False }
 -
 -  def set_key(self, key, value, save = True):
 -    self.config[key] = value
 -    if save == True:
 -      self.save_config()
 -
 -  def save_config(self):
 -    f = open(self.config_file_path(), "w+")
 -    f.write(json.dumps(self.config))
 -
 -  def load_config(self):
 -    f = open(self.config_file_path(), "r")
 -    file_contents = f.read()
 -    if file_contents:
 -      user_config = json.loads(file_contents)
 -      for i in user_config:
 -          self.config[i] = user_config[i]
 -    else:
 -      self.config = self.default_options
 -      self.save_config()
 +
-     default_options = {"gui": "lite"}
++
++    default_options = {"gui": "lite", "proxy": { "mode": "none", "host":"localhost", "port":"8080" },
++    "winpos-qt": [100, 100, 840, 400], "winpos-lite": [4, 25, 351, 149], "history": False }
 +    
 +    def __init__(self):
 +        # Find electrum data folder
 +        self.config_folder = user_dir()
 +        # Read the file
 +        if os.path.exists(self.config_file_path()):
 +            self.load_config()
 +        else:
 +            self.config = self.default_options
 +            # Make config directory if it does not yet exist.
 +            if not os.path.exists(self.config_folder):
 +                os.mkdir(self.config_folder)
 +            self.save_config()
-         
++
 +    def set_key(self, key, value, save = True):
 +        self.config[key] = value
 +        if save == True:
 +            self.save_config()
-     
++
 +    def save_config(self):
++        if not os.path.exists(self.config_folder):
++            os.mkdir(self.config_folder)
 +        f = open(self.config_file_path(), "w+")
 +        f.write(json.dumps(self.config))
-     
++
 +    def load_config(self):
 +        f = open(self.config_file_path(), "r")
 +        file_contents = f.read()
 +        if file_contents:
-             self.config = json.loads(file_contents)
++            user_config = json.loads(file_contents)
++            for i in user_config:
++                self.config[i] = user_config[i]
 +        else:
 +            self.config = self.default_options
 +            self.save_config()
-     
+   
 -  def config_file_path(self):
 -    return "%s" % (self.config_folder + "/config.json")
 -
 -  def __init__(self):
 -    # Find electrum data folder
 -    self.config_folder = user_dir()
 -    self.config = self.default_options
 -    # Read the file
 -    if os.path.exists(self.config_file_path()):
 -      self.load_config()
 -    self.save_config()
 -        
 +    def config_file_path(self):
 +        return "%s" % (self.config_folder + "/config.json")
 +
++    def __init__(self):
++        # Find electrum data folder
++        self.config_folder = user_dir()
++        self.config = self.default_options
++        # Read the file
++        if os.path.exists(self.config_file_path()):
++            self.load_config()
++        self.save_config()
++
++