-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsettings.py
More file actions
93 lines (75 loc) · 3.27 KB
/
settings.py
File metadata and controls
93 lines (75 loc) · 3.27 KB
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
import configparser
import os
import sys
configfilename=sys.path[0]+"/utils.cfg"
class Settings():
def getSettingValue(self, section, settingName):
settingValue=""
settingValue=self.config.get(section, settingName)
return settingValue
def saveConfigFile(self,
serverip,serverport,
autotimeperiod,
autoonatstart,
autoselected,
precision,
gpscomport,
gpsportspeed,
gpsoption,
showdebug):
config = configparser.ConfigParser()
config['NETWORK'] = {'serverip': serverip,
'serverport': int(serverport)}
config['APP'] = {'autotimeperiod': int(autotimeperiod),
'autoonatstart':int(autoonatstart),
'autoselectedoption':int(autoselected),
'precision': int(precision)
}
config['GPSHARDWARE'] = {'gpscomport': gpscomport,
'gpsportspeed': gpsportspeed,
'option': gpsoption,
}
config['DEBUG'] = {'showoutput': int(showdebug) }
with open(configfilename, 'w') as configfile:
config.write(configfile)
configfile.close()
return config
def createConfigFile(self,configFileName):
#creates the config file if it does not exist
if not os.path.isfile(configFileName):
config = configparser.ConfigParser()
config['NETWORK'] = {'serverip': '127.0.0.1',
'serverport': 2242}
config['APP'] = {'autotimeperiod': 10,
'autoonatstart':0,
'autoselectedoption':0,
'precision': 4
}
config['GPSHARDWARE'] = {'gpscomport': 'COM15',
'gpsportspeed': '9600',
'option': 'None',
}
config['DEBUG'] = {'showoutput': 0 }
with open(configFileName, 'w') as configfile:
config.write(configfile)
configfile.close()
return config
def __init__(self, *args, **kwargs):
self.config=None
self.config = self.loadconfig()
def getNetworkSettingValue(self, settingName):
return self.getSettingValue('NETWORK', settingName)
def getAppSettingValue(self, settingName):
return self.getSettingValue('APP', settingName)
def getGPSHardwareSettingValue(self, settingName):
return self.getSettingValue('GPSHARDWARE', settingName)
def getDebugSettingValue(self, settingName):
return self.getSettingValue('DEBUG', settingName)
def loadconfig(self):
config = None
if os.path.isfile(configfilename):
config = configparser.ConfigParser()
config.read(configfilename)
else:
config = self.createConfigFile(configfilename)
return config