#!/usr/bin/env python

from argparse import ArgumentParser

from m4db_database.export_json_utilities import export_geometry_by_unique_id
from m4db_database.export_data_files_utilities import export_geometry_data_files_by_unique_id


def get_command_line_parser():
    r"""
    Retrieve a command line parser object for this script.

    Returns:
        A command line parser object for this script.

    """
    parser = ArgumentParser()

    parser.add_argument("dir_path",
                        help="output directory, will produce a file called 'geometry.json' and a directory 'geometry'")
    parser.add_argument("-l", "--list", action="append",
                        help="a list of geometry unique ids")
    parser.add_argument("-f", "--formatted", action="store_true",
                        help="flag to indicate whether the output should be formatted")
    parser.add_argument("-z", "--zipped", action="store_true",
                        help="flag to indicate whether a zipper version of the geometry data directory should be made")
    parser.add_argument("-d", "--delete_dir_path", action="store_true",
                        help="flag to indicate whether the original '<dir_path>/geometry' directory should be removed")
    return parser


def main():
    parser = get_command_line_parser()
    args = parser.parse_args()

    print("Exporting geometries to '{}'...".format(args.dir_path))
    export_geometry_by_unique_id(args.dir_path, args.list, args.formatted)
    export_geometry_data_files_by_unique_id(args.dir_path, args.list, args.zipped, args.delete_dir_path)
    print("done!")


if __name__ == "__main__":
    main()
