class Core: """ Initializes all the submodules and serves as a connection point between different modules. """ def __init__(self, justPlots = False): self.__name__ = "Core" self.configManager = ConfigurationManager() # These return True of False depending on whether loading the conf was a success. # It should be checked if the conf was loaded successfully and failures should be logged. self.configManager.loadConf(CONFIG_CORE, True) self.configManager.loadConf(CONFIG_SETTINGS, True) self.configManager.loadConf(CONFIG_FORMS, True) self.configManager.loadConf(CONFIG_URLMAP, True) self.configManager.loadConf(CONFIG_MESSAGES, True) self.moduleManager = ModuleManager(self) self.settingsManager = SettingsManager(self) self.clientManager = ClientManager(self) self.sensorManager = SensorManager(self) self.deviceManager = DeviceManager(self) self.taskManager = TaskManager(self) self.messageManager = MessageManager(self) self.logging = Logging(self) if self.settingsManager.equals("plottype", "matplotlib"): from Plot import Plot self.plot = Plot(self) self.protocol = Protocol(self) if not justPlots: self.connection = Connection(self) if not justPlots: self.scheduler = Scheduler() if not justPlots: self.webServer = WebServer(self.connection.getLocalIP(), self.settingsManager.getValueByName("listenport")) # Currently binds to localhost. But this needs to be fixed so other connections can be listened to too. def initialize(self): self.logging.logDebug(self.__name__ + "." + "initialize") self.scheduler.initialize() startup = Startup(self) startup.addSensors() startup.addDevices() #startup.addTasks() #startup.addSensorLogging() #startup.addDailyPlots() #startup.addWeeklyPlots() #startup.addSensorControl() #modules = [] #for moduleList in self.configManager.getConf(CONFIG_FORMS).getItem("modules", ""): # modules.append(moduleList["module"]) self.moduleManager.loadModules(self.configManager.getConf(CONFIG_FORMS).getItem("modules", "")) self.webServer.setUp() def quit(self): """ Gives threads a signal to shut down, gives them some time to do so and then exits the program gracefully. """ self.logging.logEvent("Core: Shutting down", "orange") self.connection.running = False sleep(1) from os import _exit _exit(0)