-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
65 lines (54 loc) · 2.31 KB
/
config.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from configparser import ConfigParser
from distutils.command.config import config
import constants as const
import os
configPath = const.WORKING_DIR + const.CONFIG_NAME
class Config:
def __init__(self):
self.config = ConfigParser(allow_no_value=True)
self.config.read(configPath)
def configRewrite(self):
with open(configPath, "w") as configfile:
self.config.write(configfile)
def configSetDefaults(self): #Can be depricated once Server is updated to new functionality
if not os.path.exists(configPath):
self.config["Settings"] = {
"app_version" : str(const.APP_VER),
"refresh_rate" : str(const.REFRESH_RATE_DEF),
"screenShotsToStore": str(const.TRANSFER_FRAMES_MAX_DEFAULT),
"jpgQuality": str(const.JPG_QUALITY),
"sharpening" : str(const.SHARPENING),
"scaling" : str(const.SCALING),
"monitor" : "1",
"ip" : const.DEFAULT_IP,
"port" : str(const.DEFAULT_PORT),
"key" : "default",
"failedAttempMax" : str(const.FAILED_ATTEMPT_MAX),
"connectionTimeoutSeconds" : str(const.CONNECTION_TIMEOUT_SECONDS),
"invert": const.INVERT,
"resample": const.RESAMPLE,
"xoff": const.XOFF,
"yoff": const.YOFF,
"zoom_scale": const.ZOOM_SCALE
}
self.configRewrite()
#def configRead():
#config.read(configPath)
#return config["Settings"]
def configDataGet(self, _key, _default):
if (not self.config.has_section("Settings")):
self.config["Settings"] = {}
_default = str(_default)
if (self.config.has_option("Settings", _key)):
return self.config["Settings"][_key]
else:
print(f"Config option missing! [{_key}] Fetching default and adding option for next time.")
self.config["Settings"][_key] = _default
self.configRewrite()
return _default
def configDataWrite(self, _key, _data):
if (not self.config.has_section("Settings")):
self.config["Settings"] = {}
self.config["Settings"][_key] = str(_data)
self.configRewrite()
c = Config()