#!/opt/anaconda1anaconda2anaconda3/bin/python
# encoding: utf-8
from landmarkerio.cache import (cache_assets, filename_as_asset_id,
                                filepath_as_asset_id_under_dir)

if __name__ == "__main__":
    from argparse import ArgumentParser
    parser = ArgumentParser(
        description=r"""
        Cache assets ready for serving to landmarker.io.
        """)
    parser.add_argument("mode", help="'image' or 'mesh'")
    parser.add_argument("path", help="path that will be searched for assets")
    parser.add_argument("cache",
                        help="The directory used to cache assets for serving")
    parser.add_argument("-r", "--recursive", action='store_true',
                        help="If provided the path is searched recursively for"
                             " assets")
    parser.add_argument("-e", "--ext",
                        help="If provided only files with this extension "
                             "will be cached.")
    parser.add_argument('-g', '--glob',
                        help="A custom (recursive) glob used for finding "
                             "assets under the path. If provided --ext and "
                             "--recursive flags are ignored")
    parser.add_argument("-f", "--filename", action='store_true',
                        help="Use filenames as IDs. If not, full paths are "
                             "used (underscores for dirs)")
    ns = parser.parse_args()
    if ns.filename:
        print('Using filename as asset_id')
        identifier_f = filename_as_asset_id
    else:
        print('Using full path as asset_id')
        identifier_f = filepath_as_asset_id_under_dir(ns.path)
    cache_assets(ns.mode, identifier_f, ns.path, ns.cache,
                 recursive=ns.recursive, ext=ns.ext, glob=ns.glob)
