Start adapting __main__ module to the converter framework.
This commit is contained in:
@@ -1,29 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
|
||||||
import sys
|
import sys
|
||||||
from enum import auto
|
from pathlib import Path
|
||||||
|
|
||||||
import AuDaGe
|
import AuDaGe
|
||||||
from AuDaGe.better_enum import BetterStrEnum
|
from AuDaGe.converter import Converter
|
||||||
from AuDaGe.frame import AuDaGeFrame
|
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():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
frame = load_input_file(args)
|
frame = load_input_file(args)
|
||||||
@@ -34,19 +19,44 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="AuDaGe", description="Convert automation database formats."
|
prog="AuDaGe", description="Convert automation database formats."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
subparsers = parser.add_subparsers(help="")
|
||||||
|
list_parser = subparsers.add_parser("list", help="")
|
||||||
|
list_parser.set_defaults(list=True)
|
||||||
|
convert_parser = subparsers.add_parser("convert", help="")
|
||||||
|
convert_parser.set_defaults(list=False)
|
||||||
|
convert_parser.add_argument(
|
||||||
"input_format",
|
"input_format",
|
||||||
type=str.lower,
|
type=str.lower,
|
||||||
choices=FormatChoices.values(),
|
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
parser.add_argument("input_file", type=pathlib.Path, help="")
|
convert_parser.add_argument(
|
||||||
parser.add_argument(
|
"input_file",
|
||||||
"output_format", choices=FormatChoices.values(), help=""
|
type=Path,
|
||||||
|
help="",
|
||||||
)
|
)
|
||||||
parser.add_argument("output_file", type=pathlib.Path, help="")
|
convert_parser.add_argument(
|
||||||
parser.add_argument("--unsafe", action="store_true")
|
"output_format",
|
||||||
|
type=str.lower,
|
||||||
|
help="",
|
||||||
|
)
|
||||||
|
convert_parser.add_argument("output_file", type=Path, help="")
|
||||||
|
convert_parser.add_argument("--unsafe", action="store_true", help="")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.list:
|
||||||
|
for dirpath, _, files in Path("extensions").walk(on_error=print):
|
||||||
|
for file in files:
|
||||||
|
file_path = Path(file)
|
||||||
|
if file_path.suffix == ".yaml":
|
||||||
|
print(
|
||||||
|
str(
|
||||||
|
Path(*Path(dirpath).parts[1:]).joinpath(
|
||||||
|
file_path.stem
|
||||||
|
)
|
||||||
|
).replace("\\", "/")
|
||||||
|
)
|
||||||
|
sys.exit()
|
||||||
|
args.input_format = Path(args.input_format).with_suffix(".yaml")
|
||||||
|
args.output_format = Path(args.output_format).with_suffix(".yaml")
|
||||||
if args.unsafe:
|
if args.unsafe:
|
||||||
AuDaGe.safe = False
|
AuDaGe.safe = False
|
||||||
print(
|
print(
|
||||||
@@ -60,34 +70,24 @@ def parse_args():
|
|||||||
|
|
||||||
|
|
||||||
def load_input_file(args):
|
def load_input_file(args):
|
||||||
match args.input_format:
|
pass
|
||||||
case (
|
# try:
|
||||||
FC.CONTROLEXPERT_XSY | FC.CONTROLEXPERT | FC.CE_XSY | FC.CE | FC.XSY
|
# converter = Converter(args.input_format)
|
||||||
):
|
|
||||||
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):
|
def dump_output_file(frame: AuDaGeFrame, args):
|
||||||
match args.output_format:
|
pass
|
||||||
case (
|
# match args.output_format:
|
||||||
FC.CONTROLEXPERT_XSY | FC.CONTROLEXPERT | FC.CE_XSY | FC.CE | FC.XSY
|
# 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:
|
# raise NotImplementedError("Writing to XSY is not implemented.")
|
||||||
from AuDaGe.formats.kepserver import csv
|
# case FC.KEPSERVER_CSV | FC.KEPSERVER | FC.KEP:
|
||||||
|
# from AuDaGe.formats.kepserver import csv
|
||||||
|
|
||||||
csv.Frame.from_AF(frame).to_file(args.output_file)
|
# csv.Frame.from_AF(frame).to_file(args.output_file)
|
||||||
case _:
|
# case _:
|
||||||
raise NotImplementedError("This format is not implemented.")
|
# raise NotImplementedError("This format is not implemented.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user