aboutsummaryrefslogtreecommitdiff
path: root/tools/interface_generator/interface_generator.py
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-08-18 15:08:13 +0300
committeraqua <aqua@iserlohn-fortress.net>2024-08-18 15:08:13 +0300
commitff0286195eeb4dc659863af4afbdf9ddd4d53a1b (patch)
tree94b06a2efdf8b349f7822dd79f5a6de5780bcbe3 /tools/interface_generator/interface_generator.py
parentMoved pytest to private (diff)
downloadkernel-ff0286195eeb4dc659863af4afbdf9ddd4d53a1b.tar.xz
Moved interface_generator script to bin
Diffstat (limited to 'tools/interface_generator/interface_generator.py')
-rwxr-xr-xtools/interface_generator/interface_generator.py83
1 files changed, 0 insertions, 83 deletions
diff --git a/tools/interface_generator/interface_generator.py b/tools/interface_generator/interface_generator.py
deleted file mode 100755
index 0693897..0000000
--- a/tools/interface_generator/interface_generator.py
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/usr/bin/env python3
-
-"""
-interface_generator.py
-"""
-
-from argparse import ArgumentParser
-from pathlib import Path
-import sys
-from mako.lookup import TemplateLookup
-from interface_definition import parse as parse_interface
-from templates import get_templates
-
-PROG = {
- "name": "interface_generator",
- "version": "0.1",
-}
-
-
-def generate_file(template: Path, templates: Path, output, kwargs):
- """generate file using a tempalte and write it to the output location"""
- lookup = TemplateLookup(directories=[".", "templates"])
- mako_template = lookup.get_template(str(template.relative_to(templates)))
- result = mako_template.render(**kwargs, PROG=PROG)
-
- output_name = template.stem.replace("interface", kwargs["name"])
- print(f'{kwargs["name"]} via {template.name} => {output_name}')
-
- if isinstance(output, Path):
- # print(f"writing to {(output / output_name).absolute()}")
- with open(output / output_name, "w", encoding="utf-8") as output_file:
- print(result, file=output_file)
- else:
- print(result, file=output)
-
-
-def main():
- """main function"""
- parser = ArgumentParser(
- prog="interface_generator",
- description="Generate C header and mock files from an interface definition",
- )
- parser.add_argument(
- "-i",
- "--interface",
- type=Path,
- # required=True,
- help="path to interface file",
- )
- parser.add_argument(
- "-t",
- "--templates",
- type=Path,
- default=Path("templates"),
- help="templates location",
- )
- parser.add_argument(
- "-l",
- "--license",
- type=Path,
- required=True,
- help="path to license file",
- )
- parser.add_argument(
- "-o",
- "--output",
- type=Path,
- default=sys.stdout,
- help="path to output, stdout by default",
- )
-
- args = parser.parse_args()
- # print(args)
-
- interface = parse_interface(args)
- # print(interface)
-
- for template in get_templates(args.templates):
- generate_file(template, args.templates, args.output, interface)
-
-
-if __name__ == "__main__":
- main()