Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-01 09:34:21

0001 #!/usr/bin/env python3
0002 """Generate monitor_app/panda/error_labels.py from the pilot error catalog.
0003 
0004 Reads the pilot source's errorcodes.py (pilot/common/errorcodes.py in the
0005 PanDA pilot repository) and emits the pilot code -> message table used to
0006 label error categories. Rerun when the pilot catalog advances:
0007 
0008     python3 scripts/gen-pilot-error-labels.py /path/to/pilot/common/errorcodes.py
0009 """
0010 
0011 import re
0012 import sys
0013 from pathlib import Path
0014 
0015 HEADER = '''"""PanDA error-code labels by error component.
0016 
0017 PILOT_LABELS is generated from the pilot error catalog by
0018 scripts/gen-pilot-error-labels.py; edit that generator, not this table.
0019 category_label() is the shared renderer for component:code categories.
0020 """
0021 
0022 '''
0023 
0024 FOOTER = '''
0025 
0026 def category_label(component, code):
0027     """Human label for an error category, e.g. 'pilot 1099 - Failed to stage-in file'."""
0028     try:
0029         code = int(code)
0030     except (TypeError, ValueError):
0031         return f"{component} {code}"
0032     message = None
0033     if component == "pilot":
0034         message = PILOT_LABELS.get(code)
0035     base = f"{component} {code}"
0036     return f"{base} - {message}" if message else base
0037 '''
0038 
0039 
0040 def main():
0041     src = Path(sys.argv[1]).read_text()
0042     consts = dict(re.findall(r"^\s{4}([A-Z][A-Z0-9_]+)\s*=\s*(\d+)\s*$", src, re.M))
0043     body = re.search(r"_error_messages\s*=\s*\{(.*?)\n\s{4}\}", src, re.S).group(1)
0044     pairs = re.findall(r"([A-Z][A-Z0-9_]+)\s*:\s*\"(.*?)\"", body)
0045     table = {int(consts[name]): msg for name, msg in pairs if name in consts}
0046     out = Path(__file__).resolve().parent.parent / "src/monitor_app/panda/error_labels.py"
0047     lines = [HEADER, "PILOT_LABELS = {\n"]
0048     for code in sorted(table):
0049         msg = table[code].replace('"', '\\"')
0050         lines.append(f'    {code}: "{msg}",\n')
0051     lines.append("}\n")
0052     lines.append(FOOTER)
0053     out.write_text("".join(lines))
0054     print(f"wrote {out} with {len(table)} pilot labels")
0055 
0056 
0057 if __name__ == "__main__":
0058     main()