#!/usr/bin/env python3 """Append a new parameter (column) to the end of a type's sheet in the master template, and bump the template VERSION. After running, push the updated assets/template/template.xlsx + VERSION to the Skill_Assets repo. Usage: python append_parameter.py --type Diode --param "Reverse Recovery Time(ns)" \ --template assets/template/template.xlsx """ import argparse, os, openpyxl ap=argparse.ArgumentParser() ap.add_argument("--type", required=True); ap.add_argument("--param", required=True) ap.add_argument("--template", required=True) a=ap.parse_args() wb=openpyxl.load_workbook(a.template) if a.type not in wb.sheetnames: raise SystemExit(f"no sheet '{a.type}' in template; sheets: {wb.sheetnames}") ws=wb[a.type] headers=[ws.cell(1,c).value for c in range(1, ws.max_column+1)] if a.param in headers: raise SystemExit(f"'{a.param}' already exists in {a.type}") ws.cell(1, ws.max_column+1, a.param) # append at the end wb.save(a.template) vf=os.path.join(os.path.dirname(a.template), "VERSION") v=int(open(vf).read().strip()) if os.path.exists(vf) else 1 v+=1; open(vf,"w").write(str(v)) print(f"Appended '{a.param}' to {a.type}. Template is now v{v}. " f"Push {os.path.basename(a.template)} + VERSION to the Skill_Assets repo.")