From 073ab100c8e9196de5f346abcfe19eb5b99dbc28 Mon Sep 17 00:00:00 2001 From: Joshua Lucas Date: Wed, 14 Oct 2026 21:27:16 -0500 Subject: [PATCH] Add main module. --- src/AuDaGe/__main__.py | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/AuDaGe/__main__.py diff --git a/src/AuDaGe/__main__.py b/src/AuDaGe/__main__.py new file mode 100644 index 0000000..63019f7 --- /dev/null +++ b/src/AuDaGe/__main__.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +import argparse +import pathlib +import sys +from enum import auto + +from AuDaGe.better_enum import BetterStrEnum +from AuDaGe.frame import AuDaGeFrame + + +class FormatChoices(BetterStrEnum): + CONTROLEXPERT_XSY = auto() + CONTROLEXPERT = auto() + CE_XSY = auto() + CE = auto() + XSY = auto() + KEPSERVER_CSV = auto() + KEPSERVER = auto() + KEP = auto() + + +FC = FormatChoices + + +def main(): + args = parse_args() + frame = load_input_file(args) + dump_output_file(frame, args) + + +def parse_args(): + parser = argparse.ArgumentParser( + prog="AuDaGe", description="Convert automation database formats." + ) + parser.add_argument( + "input_format", + type=str.lower, + choices=FormatChoices.values(), + help="", + ) + parser.add_argument("input_file", type=pathlib.Path, help="") + parser.add_argument( + "output_format", choices=FormatChoices.values(), help="" + ) + parser.add_argument("output_file", type=pathlib.Path, help="") + return parser.parse_args() + + +def load_input_file(args): + match args.input_format: + case ( + FC.CONTROLEXPERT_XSY | FC.CONTROLEXPERT | FC.CE_XSY | FC.CE | FC.XSY + ): + from AuDaGe.formats.controlexpert import xsy + + xsy_reader = xsy.XSYReader() + return xsy_reader.read(args.input_file).datablock + case FC.KEPSERVER_CSV | FC.KEPSERVER | FC.KEP: + from AuDaGe.formats.kepserver import csv + + return csv.Frame.from_file(args.input_file).to_af() + case _: + raise NotImplementedError("This format is not implemented.") + + +def dump_output_file(frame: AuDaGeFrame, args): + match args.output_format: + case ( + FC.CONTROLEXPERT_XSY | FC.CONTROLEXPERT | FC.CE_XSY | FC.CE | FC.XSY + ): + raise NotImplementedError("Writing to XSY is not implemented.") + case FC.KEPSERVER_CSV | FC.KEPSERVER | FC.KEP: + from AuDaGe.formats.kepserver import csv + + csv.Frame.from_AF(frame).to_file(args.output_file) + case _: + raise NotImplementedError("This format is not implemented.") + + +if __name__ == "__main__": + sys.exit(main())