-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfigService.py
50 lines (37 loc) · 1.01 KB
/
ConfigService.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Helper class for loading and storing preferences
import os
import sys
import json
import requests
class ConfigService:
def __init__(self, configFile = None):
self.configFile = configFile
self.config = {
"naming":{
"path": "DOWNLOADS/%artist%/%albumName%",
"discPath": "%path%/Disc %disc%",
"albumName": "%album% (%type%)",
"fileName": "%number% %title%"
},
"arl":""
};
self.loadConfig()
self.saveConfig()
def loadConfig(self):
configFileContent = self.configFile
try:
configFileContent = open(configFileContent, 'r+').read()
configFileContent = json.loads(configFileContent)
except Exception as e:
return self.config
for key, value in configFileContent.items():
self.config[key] = value
return self.config
def saveConfig(self):
open(self.configFile, 'w').write(json.dumps(self.config, sort_keys=True, indent=4))
def set(self, key, value):
self.config[key] = value
def get(self, key):
if key == None:
return self.config
return self.config[key]