mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 19:53:35 +08:00
Merge pull request #889 from PX4/romfs_clean
Do not copy hidden or backup files to ROMFS
This commit is contained in:
+15
-14
@@ -43,29 +43,30 @@ from __future__ import print_function
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
# Parse commandline arguments
|
# Parse commandline arguments
|
||||||
parser = argparse.ArgumentParser(description="ROMFS pruner.")
|
parser = argparse.ArgumentParser(description="ROMFS pruner.")
|
||||||
parser.add_argument('--folder', action="store", help="ROMFS scratch folder.")
|
parser.add_argument('--folder', action="store", help="ROMFS scratch folder.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Pruning ROMFS files.")
|
print("Pruning ROMFS files.")
|
||||||
|
|
||||||
# go through
|
# go through
|
||||||
for (root, dirs, files) in os.walk(args.folder):
|
for (root, dirs, files) in os.walk(args.folder):
|
||||||
for file in files:
|
for file in files:
|
||||||
# only prune text files
|
# only prune text files
|
||||||
if ".zip" in file or ".bin" in file:
|
if ".zip" in file or ".bin" or ".swp" in file:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
file_path = os.path.join(root, file)
|
file_path = os.path.join(root, file)
|
||||||
|
|
||||||
# read file line by line
|
# read file line by line
|
||||||
pruned_content = ""
|
pruned_content = ""
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|
||||||
# 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:")):
|
if line.startswith(("Z:", "M:", "R: ", "O:", "S:")):
|
||||||
@@ -73,11 +74,11 @@ def main():
|
|||||||
else:
|
else:
|
||||||
if not line.isspace() and not line.strip().startswith("#"):
|
if not line.isspace() and not line.strip().startswith("#"):
|
||||||
pruned_content += line
|
pruned_content += line
|
||||||
|
|
||||||
# overwrite old scratch file
|
# overwrite old scratch file
|
||||||
with open(file_path, "w") as f:
|
with open(file_path, "w") as f:
|
||||||
f.write(pruned_content)
|
f.write(pruned_content)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ endif
|
|||||||
$(info % GIT_DESC = $(GIT_DESC))
|
$(info % GIT_DESC = $(GIT_DESC))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set a default target so that included makefiles or errors here don't
|
# Set a default target so that included makefiles or errors here don't
|
||||||
# cause confusion.
|
# cause confusion.
|
||||||
#
|
#
|
||||||
# XXX We could do something cute here with $(DEFAULT_GOAL) if it's not one
|
# XXX We could do something cute here with $(DEFAULT_GOAL) if it's not one
|
||||||
@@ -177,7 +177,7 @@ GLOBAL_DEPS += $(MAKEFILE_LIST)
|
|||||||
#
|
#
|
||||||
# Extra things we should clean
|
# Extra things we should clean
|
||||||
#
|
#
|
||||||
EXTRA_CLEANS =
|
EXTRA_CLEANS =
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -371,6 +371,8 @@ $(ROMFS_IMG): $(ROMFS_SCRATCH) $(ROMFS_DEPS) $(GLOBAL_DEPS)
|
|||||||
$(ROMFS_SCRATCH): $(ROMFS_DEPS) $(GLOBAL_DEPS)
|
$(ROMFS_SCRATCH): $(ROMFS_DEPS) $(GLOBAL_DEPS)
|
||||||
$(Q) $(MKDIR) -p $(ROMFS_SCRATCH)
|
$(Q) $(MKDIR) -p $(ROMFS_SCRATCH)
|
||||||
$(Q) $(COPYDIR) $(ROMFS_ROOT)/* $(ROMFS_SCRATCH)
|
$(Q) $(COPYDIR) $(ROMFS_ROOT)/* $(ROMFS_SCRATCH)
|
||||||
|
# delete all files in ROMFS_SCRATCH which start with a . or end with a ~
|
||||||
|
$(Q) $(RM) $(ROMFS_SCRATCH)/*/.[!.]* $(ROMFS_SCRATCH)/*/*~
|
||||||
ifneq ($(ROMFS_EXTRA_FILES),)
|
ifneq ($(ROMFS_EXTRA_FILES),)
|
||||||
$(Q) $(MKDIR) -p $(ROMFS_SCRATCH)/extras
|
$(Q) $(MKDIR) -p $(ROMFS_SCRATCH)/extras
|
||||||
$(Q) $(COPY) $(ROMFS_EXTRA_FILES) $(ROMFS_SCRATCH)/extras
|
$(Q) $(COPY) $(ROMFS_EXTRA_FILES) $(ROMFS_SCRATCH)/extras
|
||||||
|
|||||||
Reference in New Issue
Block a user