def handle_filehash_files(rule, dep_files, fhash): if not rule.enabled: return filehash_fname = rule.get(fhash) filename = [ fname for fname, content in dep_files.items() if os.path.join(*(fname.split(os.path.sep)[1:])) == filehash_fname ] if filename: logger.debug("Copying %s file %s to output directory" % (fhash, filehash_fname)) filepath = os.path.join(config.get_state_dir(), os.path.dirname(filename[0])) logger.debug("filepath: %s" % filepath) try: os.makedirs(filepath) except OSError as oserr: if oserr.errno != errno.EEXIST: logger.error(oserr) sys.exit(1) logger.debug("output fname: %s" % os.path.join(filepath, os.path.basename(filehash_fname))) with open(os.path.join(filepath, os.path.basename(filehash_fname)), "w+") as fp: fp.write(dep_files[os.path.join("rules", filehash_fname)].decode("utf-8")) else: logger.error("%s file %s was not found" % (fhash, filehash_fname))
def get_source_directory(): """Return the directory where source configuration files are kept.""" return os.path.join(config.get_state_dir(), config.SOURCE_DIRECTORY)