from pathlib import Path import xml.etree.ElementTree as E, re, zipfile,io,json,subprocess root=E.parse('docs/verification/cleanup-2026-09-20/baseline-unused-resources.xml').getroot() # Scan source/config text and uncompressed local SDK contents for literal names. files=[Path(f) for f in subprocess.check_output(['git','ls-files','-z']).decode().split('\0') if f] texts={p:p.read_text(errors='ignore') for p in files if not str(p).startswith('docs/') and p.suffix in {'.kt','.java','.xml','.pro','.kts','.toml','.json','.html'}} blobs=[] def scan(data): try: with zipfile.ZipFile(io.BytesIO(data)) as z: for n in z.namelist(): b=z.read(n) if n.endswith(('.jar','.aar')):scan(b) else:blobs.append(b) except zipfile.BadZipFile:blobs.append(data) for p in Path('app/libs').rglob('*'): if p.is_file():scan(p.read_bytes()) sdk=b'\n'.join(blobs) remove=[];keep=[] for i in root.findall('issue'): if i.get('id')!='UnusedResources':continue m=re.search(r'R\.(\w+)\.(\w+)',i.get('message','')) if not m:continue typ,name=m.groups() # Limit this batch to standalone bitmap files, preserving all XML/value resources. if typ not in {'drawable','mipmap'}:continue variants=[p for p in files if str(p).startswith('app/src/main/res/'+typ) and p.stem==name] if not variants or any(p.suffix not in {'.png','.webp','.jpg','.jpeg'} for p in variants):continue refs=[str(p) for p,s in texts.items() if re.search(r'(?