fix proxy issues: override config with command line option, and use interface.proxy...
[electrum-nvc.git] / lib / simple_config.py
1 import json
2 import os
3 from util import user_dir
4
5 class SimpleConfig:
6
7
8     default_options = {
9         "gui": "lite",
10         "proxy": None,
11         "winpos-qt": [100, 100, 840, 400],
12         "winpos-lite": [4, 25, 351, 149],
13         "history": False
14         }
15     
16     def __init__(self):
17         # Find electrum data folder
18         self.config_folder = user_dir()
19         # Read the file
20         if os.path.exists(self.config_file_path()):
21             self.load_config()
22         else:
23             self.config = self.default_options
24             # Make config directory if it does not yet exist.
25             if not os.path.exists(self.config_folder):
26                 os.mkdir(self.config_folder)
27             self.save_config()
28
29     def set_key(self, key, value, save = True):
30         self.config[key] = value
31         if save == True:
32             self.save_config()
33
34     def save_config(self):
35         if not os.path.exists(self.config_folder):
36             os.mkdir(self.config_folder)
37         f = open(self.config_file_path(), "w+")
38         f.write(json.dumps(self.config))
39
40     def load_config(self):
41         f = open(self.config_file_path(), "r")
42         file_contents = f.read()
43         if file_contents:
44             user_config = json.loads(file_contents)
45             for i in user_config:
46                 self.config[i] = user_config[i]
47         else:
48             self.config = self.default_options
49             self.save_config()
50   
51     def config_file_path(self):
52         return "%s" % (self.config_folder + "/config.json")
53
54     def __init__(self):
55         # Find electrum data folder
56         self.config_folder = user_dir()
57         self.config = self.default_options
58         # Read the file
59         if os.path.exists(self.config_file_path()):
60             self.load_config()
61         self.save_config()
62
63