#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    import os, sys, argparse, layer_importer, psycopg2 as dbapi2
    try:
        from StringIO import StringIO
    except ImportError:
        from io import StringIO, BytesIO

    ArgP = argparse.ArgumentParser(description="")
    ArgP.add_argument("--api_url", default="http://localhost:8080/geoserver")
    ArgP.add_argument("--api_user", default="admin")
    ArgP.add_argument("--api_password", default="geoserver")
    ArgP.add_argument("workspace")
    ArgP.add_argument("layer_name")
    ArgP.add_argument("geotiff_path")
    ArgP.add_argument("worldfile_path")
    ArgP.add_argument("prj_path")
    ArgP.add_argument("projection")
    Args = ArgP.parse_args()

    api = layer_importer.GeoserverApi(Args.api_url, Args.api_user, Args.api_password)
    api.delete_coveragestore(Args.workspace, Args.layer_name, recurse=True)
    api.create_worldfile_geotiff_store_layer(Args.workspace, Args.layer_name, Args.geotiff_path, Args.worldfile_path, Args.prj_path, Args.projection)
