Add main module.
This commit is contained in:
82
src/AuDaGe/__main__.py
Normal file
82
src/AuDaGe/__main__.py
Normal file
@@ -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())
|
||||||
Reference in New Issue
Block a user