def handle_cfg(transform, filepath): # if there is a .cfg file, disable it stem, ext = os.path.splitext(filepath) cfg_orig = stem + ".cfg" cfg_orig = io.iglob(cfg_orig) if cfg_orig: cfg_orig = cfg_orig[0] cfg_disable = cfg_orig + ".disable" io.rename(cfg_orig, cfg_disable) transform[cfg_orig] = cfg_disable # XXX write new .cfg with filtered flags s = open(cfg_disable).read() s = re.sub("(?i)-M", "", s) # writes dcus to disk s = re.sub("(?i)-GD", "", s) # writes .map file to disk s = re.sub("(?i)-cg", "", s) # writes .drc file to disk # kill whitespace only lines s = "\n".join(filter(lambda l: not re.match("^\s*$", l), s.splitlines())) open(cfg_orig, "w").write(s)
def classify_file(filepath, searchpath, stdlibpath): located = locate_file(filepath, searchpath + stdlibpath) filepath = located and located or filepath exists = located and True or False # XXX if the filetype is ambiguous and the file is not found there is no way to # decide its filetype, just pick the first filetype from the list filetypes = FileTypes.get_filetypes_from_extension(filepath) filetype = filetypes[0] if exists and FileTypes.is_source_file(filepath): filepaths = io.iglob(filepath) filepath = filepaths[0] filecontent = open(filepath).read() header = finders.find_programHeader(filecontent, stripcomments=True) if header: source_type_name, _ = header filetype = FileTypes.get_filetype_from_source_name(source_type_name) return filepath, exists, filetype