Skip to content

Commit d104f5a

Browse files
committed
ci(check_files): add delete flag
Add a convenient delete function to strip confirmed unused files from the current source directory. It is not set by default and, while it is very specific about the directory it's searching and the files it finds, I advise you use it with caution. Signed-off-by: Randolph Sapp <rs@ti.com>
1 parent 445c21c commit d104f5a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

bin/check_files.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com
77
"""
88

9+
import argparse
910
import logging
1011
import re
1112
from pathlib import Path
@@ -88,13 +89,26 @@ def get_unused_files(files):
8889

8990
def main():
9091
"""Main CLI entrypoint"""
91-
logging.basicConfig(level=logging.INFO)
92+
parser = argparse.ArgumentParser(
93+
prog="check_files.py",
94+
description="Tool to verify all files in the tree are in use",
95+
)
96+
97+
parser.add_argument("-d", "--delete", action="store_true")
98+
parser.add_argument("-v", "--verbose", action="store_true")
99+
100+
args = parser.parse_args()
101+
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
92102

93103
files_to_check = get_paths(SOURCE_PATH)
94104
files_unused = get_unused_files(files_to_check)
95105

96106
for path in files_unused:
97-
logging.warning("File not used: %s", path)
107+
if args.delete:
108+
logging.info("Deleting: %s", path)
109+
path.unlink()
110+
else:
111+
logging.warning("File not used: %s", path)
98112

99113

100114
if __name__ == "__main__":

0 commit comments

Comments
 (0)