Added proxy options to network dialog
[electrum-nvc.git] / lib / simple_config.py
1 import json
2 import os
3 from util import user_dir
4
5 class SimpleConfig:
6   default_options = {"gui": "lite", "proxy": { "mode": "none", "host":"localhost", "port":"8080" } }
7
8   def set_key(self, key, value, save = True):
9     self.config[key] = value
10     if save == True:
11       self.save_config()
12
13   def save_config(self):
14     f = open(self.config_file_path(), "w+")
15     f.write(json.dumps(self.config))
16
17   def load_config(self):
18     f = open(self.config_file_path(), "r")
19     file_contents = f.read()
20     if file_contents:
21       self.config = json.loads(file_contents)
22     else:
23       self.config = self.default_options
24       self.save_config()
25   
26   def config_file_path(self):
27     return "%s" % (self.config_folder + "/config.json")
28
29   def __init__(self):
30     # Find electrum data folder
31     self.config_folder = user_dir()
32     # Read the file
33     if os.path.exists(self.config_file_path()):
34       self.load_config()
35     else:
36       self.config = self.default_options
37       self.save_config()
38