Fixed merged conflict and added folder creation on first load
[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 = {"gui": "lite", "proxy": { "mode": "none", "host":"localhost", "port":"8080" },
9     "winpos-qt": [100, 100, 840, 400], "winpos-lite": [4, 25, 351, 149], "history": False }
10     
11     def __init__(self):
12         # Find electrum data folder
13         self.config_folder = user_dir()
14         # Read the file
15         if os.path.exists(self.config_file_path()):
16             self.load_config()
17         else:
18             self.config = self.default_options
19             # Make config directory if it does not yet exist.
20             if not os.path.exists(self.config_folder):
21                 os.mkdir(self.config_folder)
22             self.save_config()
23
24     def set_key(self, key, value, save = True):
25         self.config[key] = value
26         if save == True:
27             self.save_config()
28
29     def save_config(self):
30         if not os.path.exists(self.config_folder):
31             os.mkdir(self.config_folder)
32         f = open(self.config_file_path(), "w+")
33         f.write(json.dumps(self.config))
34
35     def load_config(self):
36         f = open(self.config_file_path(), "r")
37         file_contents = f.read()
38         if file_contents:
39             user_config = json.loads(file_contents)
40             for i in user_config:
41                 self.config[i] = user_config[i]
42         else:
43             self.config = self.default_options
44             self.save_config()
45   
46     def config_file_path(self):
47         return "%s" % (self.config_folder + "/config.json")
48
49     def __init__(self):
50         # Find electrum data folder
51         self.config_folder = user_dir()
52         self.config = self.default_options
53         # Read the file
54         if os.path.exists(self.config_file_path()):
55             self.load_config()
56         self.save_config()
57
58