#!/usr/bin/python3 """ Scan source code for deprecated Adwaita symbolic icons and optionally replace them. """ import os import re import argparse # Meson sets this at build time; fall back safely for system installs XAPP_DATA_DIR = '/usr/share/xapp' if not os.path.exists(XAPP_DATA_DIR): XAPP_DATA_DIR = '/usr/share/xapp' EXCLUDED_DIRS = { ".git", "build", "__pycache__", "LC_MESSAGES", "debian", "obj-x86_64-linux-gnu", "tmp", } EXCLUDED_EXTENSIONS = {"svg", "pot", "po", "mo"} # ----------------------------------------------------------------------------- # CLI # ----------------------------------------------------------------------------- def parse_args(): parser = argparse.ArgumentParser( description="Scan source code for deprecated Adwaita symbolic icons and suggest or apply replacements." ) parser.add_argument( "path", nargs="?", default=".", help="Path to the directory to scan (default: current directory).", ) parser.add_argument( "--fix", action="store_true", help="Automatically replace deprecated icons (exact -symbolic matches only) with xsi--symbolic.", ) return parser.parse_args() # ----------------------------------------------------------------------------- # Icon loading and regex setup # ----------------------------------------------------------------------------- def load_icon_map(): icon_map = {} datafile = os.path.join(XAPP_DATA_DIR, "xsi-adwaita-symbolic.info") with open(datafile, "r", encoding="utf-8") as flist: for line in flist: line = line.strip() if not line or line.startswith("#"): continue old, cat, new = line.split(" # ") icon_map[old] = new return icon_map def build_patterns(icon_map): # Custom word boundaries that allow hyphens def boundary_join(names): return r'(?-symbolic replacements.") # ----------------------------------------------------------------------------- # Entry point # ----------------------------------------------------------------------------- def main(): args = parse_args() icon_map = load_icon_map() symbolic_pattern, bare_pattern, context_pattern = build_patterns(icon_map) scan_and_fix(args.path, icon_map, symbolic_pattern, bare_pattern, context_pattern, fix=args.fix) if __name__ == "__main__": main()