#!/usr/bin/env python
from pathlib import Path
from os import path as p
import menpo
from loguru import logger
from argparse import ArgumentParser, Namespace


def convert_all_under_path(path: Path) -> None:
    for ljson_p in path.glob("**/*.ljson"):
        logger.info("converting: {}", ljson_p)
        menpo.io.export_landmark_file(
            menpo.io.import_landmark_file(ljson_p), ljson_p, overwrite=True
        )


def build_argparser() -> ArgumentParser:
    parser = ArgumentParser(
        description=r"""
        Convert old LJSON files
        """
    )
    parser.add_argument(
        "path", type=Path, help="path that will be recursively searched for LJSON files"
    )
    return parser


def main(ns: Namespace) -> None:
    convert_all_under_path(Path(p.abspath(p.expanduser(ns.path))))


if __name__ == "__main__":
    main(build_argparser().parse_args())
