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)
|
||||
|
||||
|
||||
@@ -7,3 +7,6 @@ class Parser():
|
||||
def __init__(self, input_file: Path):
|
||||
self.footprint = Footprint.from_file(input_file.absolute().__str__())
|
||||
|
||||
def parse(self) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ def test_parser_filenotexists():
|
||||
with pytest.raises(Exception, match=r".*Given path is not a file.*"):
|
||||
Parser(Path("nop"))
|
||||
|
||||
def test_parser():
|
||||
def test_parse():
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user