forked from iBaa/PlexConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.py
executable file
·111 lines (85 loc) · 3.05 KB
/
Settings.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
import sys
from os import sep
import ConfigParser
from Debug import * # dprint()
"""
Global Settings...
PMS: plexgdm, ip_pms, port_pms
DNS: ip_dnsmaster - IP of Router, ISP's DNS, ... [dflt: google public DNS]
IP_self: enable_plexconnect_autodetect, ip_plexconnect - manual override for VPN usage
HTTP: ip_webserver, port_webserver - override when using webserver + forwarding to PlexConnect
HTTPS: port_ssl, certfile -
"""
g_settings = { \
'enable_plexgdm' :('True', 'False'), \
'ip_pms' :('192.168.178.10',), \
'port_pms' :('32400',), \
\
'enable_dnsserver':('True', 'False'), \
'port_dnsserver' :('53',), \
'ip_dnsmaster' :('8.8.8.8',), \
'prevent_atv_update' :('True', 'False'), \
\
'enable_plexconnect_autodetect':('True', 'False'), \
'ip_plexconnect' :('0.0.0.0',), \
\
'ip_webserver' :('0.0.0.0',), \
'port_webserver' :('80',), \
'port_ssl' :('443',), \
'certfile' :('./assets/certificates/trailers.pem',), \
\
'loglevel' :('Normal', 'High'), \
'logpath' :('.',), \
}
class CSettings():
def __init__(self):
dprint(__name__, 1, "init class CSettings")
self.cfg = None
self.section = 'PlexConnect'
self.loadSettings()
self.checkSection()
# load/save config
def loadSettings(self):
dprint(__name__, 1, "load settings")
# options -> default
dflt = {}
for opt in g_settings:
dflt[opt] = g_settings[opt][0]
# load settings
self.cfg = ConfigParser.SafeConfigParser()
self.cfg.read(self.getSettingsFile())
def saveSettings(self):
dprint(__name__, 1, "save settings")
f = open(self.getSettingsFile(), 'wb')
self.cfg.write(f)
f.close()
def getSettingsFile(self):
return sys.path[0] + sep + "Settings.cfg"
def checkSection(self):
modify = False
# check for existing section
if not self.cfg.has_section(self.section):
modify = True
self.cfg.add_section(self.section)
dprint(__name__, 0, "add section {0}", self.section)
for opt in g_settings:
if not self.cfg.has_option(self.section, opt):
modify = True
self.cfg.set(self.section, opt, g_settings[opt][0])
dprint(__name__, 0, "add option {0}={1}", opt, g_settings[opt][0])
# save if changed
if modify:
self.saveSettings()
# access/modify PlexConnect settings
def getSetting(self, option):
dprint(__name__, 1, "getsetting {0}={1}", option, self.cfg.get(self.section, option))
return self.cfg.get(self.section, option)
if __name__=="__main__":
Settings = CSettings()
option = 'enable_plexgdm'
print Settings.getSetting(option)
option = 'enable_dnsserver'
print Settings.getSetting(option)
Settings.saveSettings()
del Settings