def _start_module_threads(filelist, ModuleList, Config): """ 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 object """ if VERBOSE: print("Starting modules...") ThreadList = [] ThreadDict = {} # Starts a thread for each module. for module in ModuleList: if module.endswith(".py"): modname = os.path.basename(module[:-3]) mod = _loadModule(os.path.basename(module.split('.')[0]), [MODULEDIR]) if not mod: print(module, " not a valid module...") continue conf = None if modname in Config.sections(): conf = conf2dic(Config.items(modname)) thread = _Thread(target=_runModule, args=(modname, mod, filelist, ThreadDict, conf)) thread.name = modname thread.setDaemon(True) ThreadList.append(thread) ThreadDict[modname] = thread for thread in ThreadList: thread.start() return ThreadList
def _get_main_config(Config, filepath=CONFIG): """ Reads in config for main script. It will write defaults if not present. Returns dictionary. Config - The config object filepath - The path to the config file """ # Write main defaults if needed ConfNeedsWrite = False if 'main' not in Config.sections(): ConfNeedsWrite = True maindefaults = DEFAULTCONF Config.add_section('main') for key in maindefaults: Config.set('main', key, str(maindefaults[key])) if ConfNeedsWrite: conffile = codecs.open(filepath, 'w', 'utf-8') Config.write(conffile) conffile.close() # Read in main config return conf2dic(Config.items('main'))