Browse Source

romfs_pruner: delete hidden files, remove tabs

If a text editor creates hidden save files, those will get copied into
the ROMFS. This is now fixed by deleting hidden files.

Also, the there was some available potential by removing the leading
whitespace.
sbg
Julian Oes 9 years ago committed by Lorenz Meier
parent
commit
49930d64ad
  1. 27
      Tools/px_romfs_pruner.py

27
Tools/px_romfs_pruner.py

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/usr/bin/env python
############################################################################
#
# Copyright (C) 2014-2015 PX4 Development Team. All rights reserved.
# Copyright (C) 2014-2016 PX4 Development Team. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@ -35,7 +35,12 @@ @@ -35,7 +35,12 @@
"""
px_romfs_pruner.py:
Delete all comments and newlines before ROMFS is converted to an image
Try to keep size of ROMFS minimal.
This script goes through the temporarily copied ROMFS data and deletes all
comments, empty lines and leading whitespace.
It also deletes hidden files such as auto-saved backups that a text editor
might have left in the tree.
@author: Julian Oes <julian@oes.ch>
"""
@ -53,19 +58,21 @@ def main(): @@ -53,19 +58,21 @@ def main():
help="ROMFS scratch folder.")
args = parser.parse_args()
#print("Pruning ROMFS files.")
# go through
# go through temp folder
for (root, dirs, files) in os.walk(args.folder):
for file in files:
file_path = os.path.join(root, file)
# delete hidden files
if file.startswith("."):
os.remove(file_path)
continue
# only prune text files
if ".zip" in file or ".bin" in file or ".swp" in file \
or ".data" in file or ".DS_Store" in file \
or file.startswith("."):
or ".data" in file or ".DS_Store" in file:
continue
file_path = os.path.join(root, file)
# read file line by line
pruned_content = ""
with open(file_path, "rU") as f:
@ -77,7 +84,7 @@ def main(): @@ -77,7 +84,7 @@ def main():
else:
if not line.isspace() \
and not line.strip().startswith("#"):
pruned_content += line
pruned_content += line.strip() + "\n"
# overwrite old scratch file
with open(file_path, "wb") as f:
pruned_content = re.sub("\r\n", "\n", pruned_content)

Loading…
Cancel
Save