def _rewite_config(ModuleList, Config, filepath=CONFIG): """ Write in default config for all modules. ModuleList - The list of modules Config - The config object """ if VERBOSE: print("Rewriting config...") ModuleList.sort() for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module.split('.')[0]) moddir = os.path.dirname(module) mod = load_module(os.path.basename(module.split('.')[0]), [moddir]) if mod: try: conf = mod.DEFAULTCONF except: continue Config.add_section(modname) for key in conf: Config.set(modname, key, str(conf[key])) Config.add_section('main') for key in DEFAULTCONF: Config.set('main', key, str(DEFAULTCONF[key])) conffile = codecs.open(filepath, 'w', 'utf-8') Config.write(conffile) conffile.close()
def _rewrite_config(ModuleList, Config, filepath=CONFIG): """ Write in default config for all modules. ModuleList - The list of modules Config - The config object """ if VERBOSE: print("Rewriting config...") ModuleList.sort() for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module).split('.')[0] moddir = os.path.dirname(module) mod = load_module(os.path.basename(module).split('.')[0], [moddir]) if mod: try: conf = mod.DEFAULTCONF except: continue Config.add_section(modname) for key in conf: Config.set(modname, key, str(conf[key])) Config.add_section('main') for key in DEFAULTCONF: Config.set('main', key, str(DEFAULTCONF[key])) conffile = codecs.open(filepath, 'w', 'utf-8') Config.write(conffile) conffile.close()
def _start_module_threads(filelist, ModuleList, config, global_module_interface): """ Starts each module on the file list in a separate thread. Returns a list of threads filelist - A lists of strings. The strings are files to be scanned ModuleList - A list of all the modules to be run config - The config dictionary global_module_interface - The global module interface to be injected in each module """ if VERBOSE: print("Starting modules...") ThreadList = [] ThreadDict = {} global_module_interface.run_count += 1 # Starts a thread for each module. for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module[:-3]) moddir = os.path.dirname(module) mod = load_module(os.path.basename(module).split('.')[0], [moddir]) if not mod: print(module, " not a valid module...") continue conf = None if modname in config: if '_load_default' in config or '_load_default' in config[ modname]: try: conf = mod.DEFAULTCONF conf.update(config[modname]) except: conf = config[modname] # Remove _load_default from config if '_load_default' in conf: del conf['_load_default'] else: conf = config[modname] # Try and read in the default conf if one was not passed if not conf: try: conf = mod.DEFAULTCONF except: pass thread = _Thread(target=_run_module, args=(modname, mod, filelist, ThreadDict, global_module_interface, conf)) thread.name = modname thread.setDaemon(True) ThreadList.append(thread) ThreadDict[modname] = thread for thread in ThreadList: thread.start() return ThreadList
def _start_module_threads(filelist, ModuleList, config, global_module_interface): """ Starts each module on the file list in a separate thread. Returns a list of threads filelist - A lists of strings. The strings are files to be scanned ModuleList - A list of all the modules to be run config - The config dictionary global_module_interface - The global module interface to be injected in each module """ if VERBOSE: print("Starting modules...") ThreadList = [] ThreadDict = {} global_module_interface.run_count += 1 # Starts a thread for each module. for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module[:-3]) moddir = os.path.dirname(module) mod = load_module(os.path.basename(module.split('.')[0]), [moddir]) if not mod: print(module, " not a valid module...") continue conf = None if modname in config: if '_load_default' in config or '_load_default' in config[modname]: try: conf = mod.DEFAULTCONF conf.update(config[modname]) except: conf = config[modname] # Remove _load_default from config if '_load_default' in conf: del conf['_load_default'] else: conf = config[modname] # Try and read in the default conf if one was not passed if not conf: try: conf = mod.DEFAULTCONF except: pass thread = _Thread(target=_runModule, args=(modname, mod, filelist, ThreadDict, global_module_interface, conf)) thread.name = modname thread.setDaemon(True) ThreadList.append(thread) ThreadDict[modname] = thread for thread in ThreadList: thread.start() return ThreadList
def _get_storage_classes(dir_path=STORAGE_DIR): storage_classes = {} dir_list = common.parseDir(dir_path, recursive=True) dir_list.remove(os.path.join(dir_path, 'storage.py')) dir_list.remove(os.path.join(dir_path, '__init__.py')) for filename in dir_list: if filename.endswith('.py'): modname = os.path.basename(filename[:-3]) moddir = os.path.dirname(filename) mod = common.load_module(os.path.basename(modname), [moddir]) if not mod: print(filename, " not a valid module...") continue for member_name in dir(mod): member = getattr(mod, member_name) if inspect.isclass(member) and issubclass(member, Storage): storage_classes[member_name] = member() return storage_classes
def _write_missing_module_configs(ModuleList, Config, filepath=CONFIG): """ Write in default config for modules not in config file. Returns True if config was written, False if not. ModuleList - The list of modules Config - The config object """ ConfNeedsWrite = False ModuleList.sort() for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module).split('.')[0] moddir = os.path.dirname(module) if modname not in Config.sections(): mod = load_module( os.path.basename(module).split('.')[0], [moddir]) if mod: try: conf = mod.DEFAULTCONF except Exception as e: # TODO: log exception continue ConfNeedsWrite = True Config.add_section(modname) for key in conf: Config.set(modname, key, str(conf[key])) if 'main' not in Config.sections(): ConfNeedsWrite = True Config.add_section('main') for key in DEFAULTCONF: Config.set('main', key, str(DEFAULTCONF[key])) if ConfNeedsWrite: conffile = codecs.open(filepath, 'w', 'utf-8') Config.write(conffile) conffile.close() return True return False
def _write_missing_module_configs(ModuleList, Config, filepath=CONFIG): """ Write in default config for modules not in config file. Returns True if config was written, False if not. ModuleList - The list of modules Config - The config object """ ConfNeedsWrite = False ModuleList.sort() for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module.split('.')[0]) moddir = os.path.dirname(module) if modname not in Config.sections(): mod = load_module(os.path.basename(module.split('.')[0]), [moddir]) if mod: try: conf = mod.DEFAULTCONF except: continue ConfNeedsWrite = True Config.add_section(modname) for key in conf: Config.set(modname, key, str(conf[key])) if 'main' not in Config.sections(): ConfNeedsWrite = True Config.add_section('main') for key in DEFAULTCONF: Config.set('main', key, str(DEFAULTCONF[key])) if ConfNeedsWrite: conffile = codecs.open(filepath, 'w', 'utf-8') Config.write(conffile) conffile.close() return True return False