ROMFS pruner: Kick out excluded files

This commit is contained in:
Lorenz Meier
2016-12-21 08:37:45 +01:00
parent becd9457ca
commit 417eda82ef
+15 -5
View File
@@ -56,6 +56,8 @@ def main():
parser = argparse.ArgumentParser(description="ROMFS pruner.") parser = argparse.ArgumentParser(description="ROMFS pruner.")
parser.add_argument('--folder', action="store", parser.add_argument('--folder', action="store",
help="ROMFS scratch folder.") help="ROMFS scratch folder.")
parser.add_argument('--board', action="store",
help="Board architecture for this run")
args = parser.parse_args() args = parser.parse_args()
# go through temp folder # go through temp folder
@@ -80,20 +82,28 @@ def main():
# read file line by line # read file line by line
pruned_content = "" pruned_content = ""
board_excluded = False
with open(file_path, "rU") as f: with open(file_path, "rU") as f:
for line in f: for line in f:
if re.search(r'\b{0} exclude\b'.format(args.board),line):
board_excluded = True;
# handle mixer files differently than startup files # handle mixer files differently than startup files
if file_path.endswith(".mix"): if file_path.endswith(".mix"):
if line.startswith(("Z:", "M:", "R: ", "O:", "S:", "H:", "T:", "P:")): if line.startswith(("Z:", "M:", "R: ", "O:", "S:", "H:", "T:", "P:")):
pruned_content += line pruned_content += line
else: else:
if not line.isspace() \ if not line.isspace() \
and not line.strip().startswith("#"): and not line.strip().startswith("#"):
pruned_content += line.strip() + "\n" pruned_content += line.strip() + "\n"
# overwrite old scratch file # delete the file if it doesn't contain the architecture
with open(file_path, "wb") as f: # write out the pruned content else
pruned_content = re.sub("\r\n", "\n", pruned_content) if not board_excluded:
f.write(pruned_content.encode("ascii", errors='strict')) # overwrite old scratch file
with open(file_path, "wb") as f:
pruned_content = re.sub("\r\n", "\n", pruned_content)
f.write(pruned_content.encode("ascii", errors='strict'))
else:
os.remove(file_path)
if __name__ == '__main__': if __name__ == '__main__':