mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
px_romfs_pruner.py: PEP8ify and whitespace
- Changed from 8 spaces indent back to 4 which I find appropriate for Python. - Fixed linelength to 80 chars.
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
############################################################################
|
############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
# Copyright (C) 2014-2015 PX4 Development Team. All rights reserved.
|
||||||
# Author: Julian Oes <joes@student.ethz.ch>
|
|
||||||
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions
|
# modification, are permitted provided that the following conditions
|
||||||
@@ -37,18 +36,21 @@
|
|||||||
"""
|
"""
|
||||||
px_romfs_pruner.py:
|
px_romfs_pruner.py:
|
||||||
Delete all comments and newlines before ROMFS is converted to an image
|
Delete all comments and newlines before ROMFS is converted to an image
|
||||||
|
|
||||||
|
@author: Julian Oes <julian@oes.ch>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import argparse, re
|
import argparse
|
||||||
|
import re
|
||||||
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.")
|
||||||
@@ -57,8 +59,9 @@ def main():
|
|||||||
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 or ".swp" in file or ".data" in file or \
|
if ".zip" in file or ".bin" in file or ".swp" in file \
|
||||||
".DS_Store" in file or file.startswith("."):
|
or ".data" in file or ".DS_Store" in file \
|
||||||
|
or file.startswith("."):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
file_path = os.path.join(root, file)
|
file_path = os.path.join(root, file)
|
||||||
@@ -67,13 +70,13 @@ def main():
|
|||||||
pruned_content = ""
|
pruned_content = ""
|
||||||
with open(file_path, "rU") as f:
|
with open(file_path, "rU") 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:")):
|
||||||
pruned_content += line
|
pruned_content += line
|
||||||
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, "wb") as f:
|
with open(file_path, "wb") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user