From 49930d64ad677af8f762d915ba4de9c22e06aeba Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 2 Jun 2016 15:11:43 +0100 Subject: [PATCH] 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. --- Tools/px_romfs_pruner.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Tools/px_romfs_pruner.py b/Tools/px_romfs_pruner.py index 5ac8fc2801..fa48019bd0 100644 --- a/Tools/px_romfs_pruner.py +++ b/Tools/px_romfs_pruner.py @@ -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 @@ """ 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 """ @@ -53,18 +58,20 @@ 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: - # 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("."): + file_path = os.path.join(root, file) + + # delete hidden files + if file.startswith("."): + os.remove(file_path) continue - file_path = os.path.join(root, file) + # 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: + continue # read file line by line pruned_content = "" @@ -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)