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)