Skip to content

Commit

Permalink
Improve unused icons script
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Nov 5, 2024
1 parent f3ec6f3 commit ed04688
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions scripts/check_unused_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@
icons = root / "assets/icons"


def source_dir_uses_icon(dir: str, name: str):
def count_icon_usages(name: str):
count = 0
name = name.encode()
for file in (root / dir).glob("**/*.c"):
try:
if name in file.read_bytes():
count += 1
except Exception:
print(f"Faield to read {file}")
# EXTREMELY wasteful, but who cares
for dir in ("applications", "furi", "lib", "targets"):
for filetype in (".c", ".cpp", ".h", ".fam"):
for file in (root / dir).glob(f"**/*{filetype}"):
try:
if name in file.read_bytes():
count += 1
except Exception:
print(f"Failed to read {file}")
return count


for category in icons.iterdir():
if not category.is_dir():
continue
for icon in category.iterdir():
if icon.is_dir() and (icon / "frame_rate").is_file():
name = "&A_" + icon.name.replace("-", "_")
else:
name = "&I_" + "_".join(icon.name.split(".")[:-1]).replace("-", "_")
count = 0
for dir in ("applications", "furi", "lib", "targets"):
count += source_dir_uses_icon(dir, name)
if __name__ == "__main__":
counts = {}

for category in icons.iterdir():
if not category.is_dir():
continue
for icon in category.iterdir():
if icon.is_dir() and (icon / "frame_rate").is_file():
name = "A_" + icon.name.replace("-", "_")
elif icon.is_file() and icon.suffix == ".png":
name = "I_" + "_".join(icon.name.split(".")[:-1]).replace("-", "_")
else:
continue
counts[name[2:]] = count_icon_usages(name)

for name, count in sorted(counts.items(), key=lambda x: x[1], reverse=True):
print(f"{name} used {count} times")
if count == 0:
print(f"====== {name} is not used! ======")

0 comments on commit ed04688

Please sign in to comment.