#!/bin/python from argparse import ArgumentParser from pathlib import Path from .converter import Converter from kiutils.footprint import Footprint def main (args) -> None: check_args(args) converted = convert(args["in_file"]) write_output(converted, args["in_file"], args["out"]) def convert(in_file: Path) -> str: parsed = Footprint.from_file(in_file.absolute().__str__()) converter = Converter(parsed) return converter.convert() def write_output (output: str, in_file: Path, out_dir: Path) -> None: filename = in_file.name.split('.')[0] + ".js" 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(): raise FileNotFoundError("Input file not found!") out_dir.mkdir(exist_ok=True) def parse_args(): parser = ArgumentParser() parser.add_argument("in_file", type=Path) parser.add_argument("--out", type=Path, required=False, default=Path('.')) return parser.parse_args() def run () -> None: args = parse_args() main(args) if __name__ == "__main__": run()