def __init__(self, config): self.__logger = logging.getLogger('PHAD') self.__devices = DeviceRegistry() self.__plugins = PluginRegistry(self.__devices) self.__scheduler = BackgroundScheduler() self.__config = SafeConfigParser() self.__config.read(config)
class PHAD(object): def __init__(self, config): self.__logger = logging.getLogger('PHAD') self.__devices = DeviceRegistry() self.__plugins = PluginRegistry(self.__devices) self.__scheduler = BackgroundScheduler() self.__config = SafeConfigParser() self.__config.read(config) def getPlugins(self): return self.__plugins.getPlugins() def initialize(self): # initialize plugin registry self.__plugins.initialize(self.__config.get('PHAD', 'plugin_dir')) # schedule plugin execution for plugin in self.getPlugins(): # if self.__config.has_section(inst.getName()): # inst.setConfig(self.__config.) plugin.initialize() self.__scheduler.add_job(plugin.execute, 'interval', seconds=plugin.getCycleTime()) def execute(self): self.__scheduler.start() print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: # This is here to simulate application activity (which keeps the main thread alive). while True: time.sleep(2) except (KeyboardInterrupt, SystemExit): # Not strictly necessary if daemonic mode is enabled but should be done if possible self.__scheduler.shutdown()