class ModuleHandler(): """ Handle loading, unloading and reloading of modules. """ # ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- def __init__(self, root, config): """ Initialize variables and modules. @type root: String @param root: Full path to the FuzzLabs root directory @type config: Dictionary @param config: The complete configuration as a dictionary """ self.root = root self.config = config self.loaded_modules = [] self.modules_dir = self.root + "/modules" self.database = DatabaseHandler(self.config, self.root) self.__init_modules() # ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- def __init_modules(self): """ Initial load of modules. All modules not already loaded will get initialized and started. """ for module_name in self.get_directories(): if self.is_module_loaded(module_name): continue mod = self.__load_module_by_name(module_name) if not mod: self.database.log("error", "failed to load module: %s" % module_name) continue try: mod["instance"].start() self.loaded_modules.append(mod) except Exception, ex: self.database.log("error", "failed to start module: %s" % mod["name"], str(ex))
def __init__(self, root, config): """ Initialize variables and modules. @type root: String @param root: Full path to the FuzzLabs root directory @type config: Dictionary @param config: The complete configuration as a dictionary """ self.root = root self.config = config self.loaded_modules = [] self.modules_dir = self.root + "/modules" self.database = DatabaseHandler(self.config, self.root) self.__init_modules()
def __init__(self, root, config): """ Initialize FuzzLabs daemon. @type root: String @param root: Full path to the FuzzLabs root directory @type config: Dictionary @param config: The complete configuration as a dictionary """ self.root = root self.config = config self.modules = None self.stdin_path = self.config['daemon']['stdin'] self.stdout_path = self.config['daemon']['stdout'] self.stderr_path = self.config['daemon']['stderr'] self.pidfile_path = self.config['daemon']['pidfile'] self.pidfile_timeout = self.config['daemon']['pidfile_timeout'] self.running = True self.database = DatabaseHandler(self.config, self.root)
import os import sys import json import time import inspect ROOT_DIR = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.append(ROOT_DIR + "/../../") from ConfigurationHandler import ConfigurationHandler from classes.DatabaseHandler import DatabaseHandler CONFIG_FILE = ROOT_DIR + "/../../etc/engine.config" CONFIG = ConfigurationHandler(CONFIG_FILE).get() DATABASE = DatabaseHandler(CONFIG, ROOT_DIR) JOB_DATA = SESSION_DATA = { "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "data": "this is just test data" } ISSUE_DATA = { "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "mutant_index": 101, "target": {}, "name": "TEST", "process_status": {}, "request": "REQUEST DATA" } ISSUE_DATA_ID = "10708a964e6a54434d9853a2b1cff7bc0b564d51"
class FuzzlabsDaemon(): """ Implement the FuzzLabs daemon which loads up modules and keeps track of any changes both to the loaded and new modules. Once the daemon is finished running the modules are unloaded. """ # ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- def __init__(self, root, config): """ Initialize FuzzLabs daemon. @type root: String @param root: Full path to the FuzzLabs root directory @type config: Dictionary @param config: The complete configuration as a dictionary """ self.root = root self.config = config self.modules = None self.stdin_path = self.config['daemon']['stdin'] self.stdout_path = self.config['daemon']['stdout'] self.stderr_path = self.config['daemon']['stderr'] self.pidfile_path = self.config['daemon']['pidfile'] self.pidfile_timeout = self.config['daemon']['pidfile_timeout'] self.running = True self.database = DatabaseHandler(self.config, self.root) # ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- def __sigterm_handler(self, signum, frame): """ Handle SIGTERM signal and abort execution. """ self.database.log("info", "DCNWS FuzzLabs is stopping") self.running = False # ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- def run(self): """ Main function of FuzzLabs. """ self.database.log("info", "DCNWS FuzzLabs is initializing") try: os.setsid() os.umask(077) signal.signal(signal.SIGTERM, self.__sigterm_handler) except Exception, ex: self.database.log("error", "failed to start daemon", str(ex)) sys.exit(1) try: self.modules = ModuleHandler(self.root, self.config) except Exception, ex: self.database.log("error", "failed to load modules", str(ex)) sys.exit(1)
if options_parser.relay_to_switch: BoardController.switch_relay(options_parser.relay_to_switch[0]) if options_parser.relay_and_value_to_set: BoardController.set_relay(options_parser.relay_and_value_to_set[0], options_parser.relay_and_value_to_set[1]) if options_parser.relay_to_print: print(BoardController.get_relay(options_parser.relay_to_print[0])) if options_parser.current_temperature: temp = BoardController.get_current_temperature() print_temperature(temp) if options_parser.time_interval_temperature: database_handler = DatabaseHandler() temp_tab = database_handler.get_time_interval_temperature(options_parser.time_interval_temperature[0], options_parser.time_interval_temperature[1]) for temp in temp_tab: print_temperature(temp) if options_parser.last_period_temperature: database_handler = DatabaseHandler() temp_tab = database_handler.get_last_period_temperature(options_parser.last_period_temperature[0], options_parser.without_filling) for temp in temp_tab: print_temperature(temp) if options_parser.save_temperature: temp = BoardController.get_current_temperature() database_handler = DatabaseHandler()