Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions bin/check_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com
"""

import argparse
import logging
import re
from pathlib import Path

logger = logging.getLogger(__name__)

SOURCE_PATH = Path("source/")
RST_SOURCE = set(SOURCE_PATH.glob("**/*.rst"))
RST_SOURCE = sorted(SOURCE_PATH.glob("**/*.rst"))
IGNORED = re.compile(r"([^_].*\.rst)|(version\.txt)")


def get_names(base):
"""Get a set of file names to check for, ignoring anything in that matches the IGNORED regex.
def get_paths(base):
"""Get a list of paths to check for, ignoring anything with a name that matches the IGNORED
regex.

:param base: Pathlib path to directory to search
:return: Set of string path names
:return: List of pathlib paths
"""
files_to_check = set()
files_to_check = []
for file in base.glob("**/*"):
if file.is_dir():
continue
Expand All @@ -33,7 +35,7 @@ def get_names(base):
logger.debug("Ignored: %s", name)
continue

files_to_check.add(name)
files_to_check.append(file)
return files_to_check


Expand Down Expand Up @@ -67,15 +69,46 @@ def check_all(string):
return False


def main():
"""Main CLI entrypoint"""
logging.basicConfig(level=logging.INFO)
def get_unused_files(files):
"""Get a list of unused files from a subset of files given

files_to_check = get_names(SOURCE_PATH)
for filename in files_to_check:
:param files: List of pathlib paths
:return: List of unused pathlib paths
"""
names_to_check = {x.name for x in files}
unused_names = []
for filename in names_to_check:
if check_all(filename):
continue
logging.info("File not used: %s", filename)

logging.debug("Name not found: %s", filename)
unused_names.append(filename)

return [x for x in files if x.name in unused_names]


def main():
"""Main CLI entrypoint"""
parser = argparse.ArgumentParser(
prog="check_files.py",
description="Tool to verify all files in the tree are in use",
)

parser.add_argument("-d", "--delete", action="store_true")
parser.add_argument("-v", "--verbose", action="store_true")

args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

files_to_check = get_paths(SOURCE_PATH)
files_unused = get_unused_files(files_to_check)

for path in files_unused:
if args.delete:
logging.info("Deleting: %s", path)
path.unlink()
else:
logging.warning("File not used: %s", path)


if __name__ == "__main__":
Expand Down
118 changes: 0 additions & 118 deletions source/common/EVM_Hardware_Setup/_OMAPL137_EVM_Hardware_Setup.rst

This file was deleted.

This file was deleted.

Loading