parse, convert, write
This commit is contained in:
@@ -3,9 +3,31 @@
|
||||
from argparse import ArgumentParser
|
||||
from pathlib import Path
|
||||
|
||||
from ergogen_footprint_converter.parser import Parser
|
||||
from ergogen_footprint_converter.converter import Converter
|
||||
|
||||
def main (args):
|
||||
print(args)
|
||||
|
||||
def main (args) -> None:
|
||||
check_args(args)
|
||||
|
||||
in_file: Path = args["in_file"]
|
||||
out_dir: Path = args["out"]
|
||||
|
||||
parser = Parser(in_file)
|
||||
parsed = parser.parse()
|
||||
|
||||
converter = Converter(parsed)
|
||||
converted = converter.convert()
|
||||
|
||||
write_output(converted, in_file, out_dir)
|
||||
|
||||
def write_output (output: str, in_file: Path, out_dir: Path) -> None:
|
||||
filename = in_file.name
|
||||
|
||||
with open(filename, 'w') as file:
|
||||
file.writelines(output)
|
||||
|
||||
def check_args(args) -> None:
|
||||
in_file: Path = args["in_file"]
|
||||
out_dir: Path = args["out"]
|
||||
if not in_file.exists():
|
||||
@@ -13,8 +35,6 @@ def main (args):
|
||||
|
||||
out_dir.mkdir(exist_ok=True)
|
||||
|
||||
None
|
||||
|
||||
def parse_args():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("in_file", type=Path)
|
||||
@@ -22,7 +42,7 @@ def parse_args():
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
def run ():
|
||||
def run () -> None:
|
||||
args = parse_args()
|
||||
main(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user