-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_details_manager.py
91 lines (69 loc) · 2.43 KB
/
system_details_manager.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
#!/usr/bin/env python
#Manages Sensor Inputs
#Author: Kevin Murphy
#Date : 5 - Dec - 15
import json
from configurable import Configurable
import constants as CONSTS
class SystemDetailsManager(Configurable):
DEBUG = True
LOGTAG = "SystemDetailsManager"
__databaseManager = None
__name = None
__location = None
__gps_lat = None
__gps_lng = None
def __init__(self, databaseManager):
super(SystemDetailsManager, self).__init__(CONSTS.JSON_KEY_SYSTEM_DETAILS_MANAGER_CONFIG)
if self.DEBUG:
print self.LOGTAG, " :: Created"
self.__databaseManager = databaseManager
self.setSystemDetails(self.__databaseManager.select_system_details())
def configure(self, config):
if self.DEBUG:
print self.LOGTAG, ":: Configuring"
if config is not None:
try:
sysDetailsConfig = config[self.getJsonConfigKey()]
self.setName(sysDetailsConfig[CONSTS.JSON_KEY_SYSTEM_DETAILS_NAME])
self.setLocation(sysDetailsConfig[CONSTS.JSON_KEY_SYSTEM_DETAILS_LOCATION])
self.setGPSLat(sysDetailsConfig[CONSTS.JSON_KEY_SYSTEM_DETAILS_GPS_LAT])
self.setGPSLng(sysDetailsConfig[CONSTS.JSON_KEY_SYSTEM_DETAILS_GPS_LNG])
self.__databaseManager.insert_system_details(**self.getDetails())
except KeyError:
if self.DEBUG:
print self.LOGTAG, " :: Config not present"
def getDetails(self):
return { CONSTS.JSON_KEY_SYSTEM_DETAILS_NAME : self.getName(),
CONSTS.JSON_KEY_SYSTEM_DETAILS_LOCATION : self.getLocation(),
CONSTS.JSON_KEY_SYSTEM_DETAILS_GPS_LAT : self.getGPSLat(),
CONSTS.JSON_KEY_SYSTEM_DETAILS_GPS_LNG : self.getGPSLng()}
def setSystemDetails(self, systemDetails):
self.setName(systemDetails.name)
self.setLocation(systemDetails.location)
self.setGPSLat(systemDetails.gps_lat)
self.setGPSLng(systemDetails.gps_lng)
def setName(self, name):
self.__name = name
def getName(self):
return self.__name
def setLocation(self, location):
self.__location = location
def getLocation(self):
return self.__location
def setIpAddress(self, ip_address):
self.__ip_address = ip_address
def getIpAddress(self):
return self.__ip_address
def setGPSLat(self, gps_lat):
self.__gps_lat = gps_lat
def getGPSLat(self):
return self.__gps_lat
def setGPSLng(self, gps_lng):
self.__gps_lng = gps_lng
def getGPSLng(self):
return self.__gps_lng
def toString(self):
if self.DEBUG:
print self.LOGTAG , json.dumps(self.getDetails())
return self.getDetails()