Ejemplo n.º 1
0
def serve_rpc(ctx, host, port, conf):
    """Serve EODAG functionalities through a RPC interface"""
    setup_logging(verbose=ctx.obj["verbosity"])
    from eodag.rpc.server import EODAGRPCServer

    server = EODAGRPCServer(host, port, conf)
    server.serve()
Ejemplo n.º 2
0
def serve_rest(ctx, daemon, world, port, config, locs, debug):
    """Serve EODAG functionalities through a WEB interface"""
    setup_logging(verbose=ctx.obj["verbosity"])
    # Set the settings of the app
    # IMPORTANT: the order of imports counts here (first we override the settings,
    # then we import the app so that the updated settings is taken into account in
    # the app initialization)
    if config:
        os.environ["EODAG_CFG_FILE"] = config

    if config:
        os.environ["EODAG_CFG_FILE"] = config
    if locs:
        os.environ["EODAG_LOCS_CFG_FILE"] = locs

    from eodag.rest.server import app

    bind_host = "127.0.0.1"
    if world:
        bind_host = "0.0.0.0"
    if daemon:
        try:
            pid = os.fork()
        except OSError as e:
            raise Exception("%s [%d]" % (e.strerror, e.errno))

        if pid == 0:
            os.setsid()
            app.run(threaded=True, host=bind_host, port=port)
        else:
            sys.exit(0)
    else:
        app.run(debug=debug, host=bind_host, port=port)
Ejemplo n.º 3
0
def list_pt(ctx, **kwargs):
    """Print the list of supported product types"""
    setup_logging(verbose=ctx.obj["verbosity"])
    dag = EODataAccessGateway()
    provider = kwargs.pop("provider")
    text_wrapper = textwrap.TextWrapper()
    guessed_product_types = []
    try:
        guessed_product_types = dag.guess_product_type(
            platformSerialIdentifier=kwargs.get("platformserialidentifier"),
            processingLevel=kwargs.get("processinglevel"),
            sensorType=kwargs.get("sensortype"),
            **kwargs
        )
    except NoMatchingProductType:
        if any(
            kwargs[arg]
            for arg in [
                "instrument",
                "platform",
                "platformserialidentifier",
                "processinglevel",
                "sensortype",
            ]
        ):
            click.echo("No product type match the following criteria you provided:")
            click.echo(
                "\n".join(
                    "-{param}={value}".format(**locals())
                    for param, value in kwargs.items()
                    if value is not None
                )
            )
            sys.exit(1)
    try:
        if guessed_product_types:
            product_types = [
                pt
                for pt in dag.list_product_types(provider=provider)
                if pt["ID"] in guessed_product_types
            ]
        else:
            product_types = dag.list_product_types(provider=provider)
        click.echo("Listing available product types:")
        for product_type in product_types:
            click.echo("\n* {}: ".format(product_type["ID"]))
            for prop, value in product_type.items():
                if prop != "ID":
                    text_wrapper.initial_indent = "    - {}: ".format(prop)
                    text_wrapper.subsequent_indent = " " * len(
                        text_wrapper.initial_indent
                    )
                    if value is not None:
                        click.echo(text_wrapper.fill(value))
    except UnsupportedProvider:
        click.echo("Unsupported provider. You may have a typo")
        click.echo(
            "Available providers: {}".format(", ".join(dag.available_providers()))
        )
        sys.exit(1)
Ejemplo n.º 4
0
def serve_rpc(ctx, host, port, conf):
    """Serve EODAG functionalities through a RPC interface"""
    setup_logging(verbose=ctx.obj["verbosity"])
    try:
        from eodag_cube.rpc.server import EODAGRPCServer
    except ImportError:
        raise NotImplementedError(
            "eodag-cube needed for this functionnality, install using `pip install eodag-cube`"
        )

    server = EODAGRPCServer(host, port, conf)
    server.serve()
Ejemplo n.º 5
0
def download(ctx, **kwargs):
    """Download a bunch of products from a serialized search result"""
    search_result_path = kwargs.pop("search_results")
    if not search_result_path:
        with click.Context(download) as ctx:
            click.echo("Nothing to do (no search results file provided)")
            click.echo(download.get_help(ctx))
        sys.exit(1)
    kwargs["verbose"] = ctx.obj["verbosity"]
    setup_logging(**kwargs)
    conf_file = kwargs.pop("conf")
    if conf_file:
        conf_file = click.format_filename(conf_file)

    satim_api = EODataAccessGateway(user_conf_file_path=conf_file)
    search_results = satim_api.deserialize(search_result_path)
    # register downloader
    for idx, product in enumerate(search_results):
        if product.downloader is None:
            auth = product.downloader_auth
            if auth is None:
                auth = satim_api._plugins_manager.get_auth_plugin(
                    product.provider)
            search_results[idx].register_downloader(
                satim_api._plugins_manager.get_download_plugin(product), auth)

    downloaded_files = satim_api.download_all(search_results)
    if downloaded_files and len(downloaded_files) > 0:
        for downloaded_file in downloaded_files:
            if downloaded_file is None:
                click.echo(
                    "A file may have been downloaded but we cannot locate it")
            else:
                click.echo("Downloaded {}".format(downloaded_file))
    else:
        click.echo(
            "Error during download, a file may have been downloaded but we cannot locate it"
        )
Ejemplo n.º 6
0
def deploy_wsgi_app(
    ctx,
    root,
    config,
    webserver,
    threads,
    user,
    group,
    server_name,
    wsgi_process_group,
    wsgi_daemon_process,
    name,
):
    """Deploy the WEB interface of eodag behind a web server"""
    setup_logging(verbose=ctx.obj["verbosity"])
    import eodag as eodag_package

    server_config = {"EODAG_CFG_FILE": config}
    eodag_package_path = eodag_package.__path__[0]
    webapp_src_path = os.path.join(eodag_package_path, "rest")
    webapp_dst_path = os.path.join(root, name)
    if not os.path.exists(webapp_dst_path):
        os.mkdir(webapp_dst_path)
    wsgi_path = os.path.join(webapp_dst_path, "server.wsgi")
    click.echo("Moving eodag HTTP web app from {} to {}".format(
        webapp_src_path, webapp_dst_path))
    shutil.copy(os.path.join(webapp_src_path, "server.wsgi"), wsgi_path)
    shutil.copy(
        os.path.join(webapp_src_path, "description.md"),
        os.path.join(webapp_dst_path, "description.md"),
    )
    shutil.copytree(
        os.path.join(webapp_src_path, "templates"),
        os.path.join(webapp_dst_path, "templates"),
    )

    click.echo("Overriding eodag HTTP server config with values: {}".format(
        server_config))
    with open(os.path.join(webapp_dst_path, "eodag_server_settings.json"),
              "w") as fd:
        json.dump(server_config, fd)

    click.echo("Finished ! The WSGI file is in {}".format(wsgi_path))
    if webserver == "apache":
        application_group = "%{GLOBAL}"
        apache_config_sample = ("""
<VirtualHost *>
    ServerName %(server_name)s

    WSGIDaemonProcess %(wsgi_daemon_process)s user=%(user)s group=%(group)s \
    threads=%(threads)s
    WSGIScriptAlias / %(wsgi_path)s

    <Directory %(webapp_dst_path)s>
        WSGIProcessGroup %(wsgi_process_group)s
        WSGIApplicationGroup %(application_group)s
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>
</VirtualHost>
        """ % locals())
        click.echo("Sample Apache2 config to add in a your virtual host:")
        click.echo(apache_config_sample)
Ejemplo n.º 7
0
def search_crunch(ctx, **kwargs):
    """Search product types and optionnaly apply crunchers to search results"""
    # Process inputs for search
    product_type = kwargs.pop("producttype")
    instrument = kwargs.pop("instrument")
    platform = kwargs.pop("platform")
    platform_identifier = kwargs.pop("platformserialidentifier")
    processing_level = kwargs.pop("processinglevel")
    sensor_type = kwargs.pop("sensortype")
    id_ = kwargs.pop("id")
    custom = kwargs.pop("query")
    if not any([
            product_type,
            instrument,
            platform,
            platform_identifier,
            processing_level,
            sensor_type,
            id_,
    ]):
        with click.Context(search_crunch) as ctx:
            print("Give me some work to do. See below for how to do that:",
                  end="\n\n")
            click.echo(search_crunch.get_help(ctx))
        sys.exit(-1)

    kwargs["verbose"] = ctx.obj["verbosity"]
    setup_logging(**kwargs)

    if kwargs["box"] != (None, ) * 4:
        rect = kwargs.pop("box")
        footprint = {
            "lonmin": rect[0],
            "latmin": rect[1],
            "lonmax": rect[2],
            "latmax": rect[3],
        }
    else:
        footprint = kwargs.pop("geom")

    start_date = kwargs.pop("start")
    stop_date = kwargs.pop("end")
    criteria = {
        "geometry": footprint,
        "startTimeFromAscendingNode": None,
        "completionTimeFromAscendingNode": None,
        "cloudCover": kwargs.pop("cloudcover"),
        "productType": product_type,
        "instrument": instrument,
        "platform": platform,
        "platformSerialIdentifier": platform_identifier,
        "processingLevel": processing_level,
        "sensorType": sensor_type,
        "id": id_,
    }
    if custom:
        custom_dict = parse_qs(custom)
        for k, v in custom_dict.items():
            if isinstance(v, list) and len(v) == 1:
                criteria[k] = v[0]
            else:
                criteria[k] = v
    if start_date:
        criteria["startTimeFromAscendingNode"] = start_date.isoformat()
    if stop_date:
        criteria["completionTimeFromAscendingNode"] = stop_date.isoformat()
    conf_file = kwargs.pop("conf")
    if conf_file:
        conf_file = click.format_filename(conf_file)
    locs_file = kwargs.pop("locs")
    if locs_file:
        locs_file = click.format_filename(locs_file)

    # Process inputs for crunch
    cruncher_names = set(kwargs.pop("cruncher") or [])
    cruncher_args = kwargs.pop("cruncher_args")
    cruncher_args_dict = {}
    if cruncher_args:
        for cruncher, argname, argval in cruncher_args:
            cruncher_args_dict.setdefault(cruncher,
                                          {}).setdefault(argname, argval)

    items_per_page = kwargs.pop("items")
    page = kwargs.pop("page") or 1

    gateway = EODataAccessGateway(user_conf_file_path=conf_file,
                                  locations_conf_path=locs_file)

    # Search
    results, total = gateway.search(page=page,
                                    items_per_page=items_per_page,
                                    **criteria)
    click.echo("Found a total number of {} products".format(total))
    click.echo("Returned {} products".format(len(results)))

    # Crunch !
    crunch_args = {
        cruncher_name: cruncher_args_dict.get(cruncher_name, {})
        for cruncher_name in cruncher_names
    }
    if crunch_args:
        results = gateway.crunch(results,
                                 search_criteria=criteria,
                                 **crunch_args)

    storage_filepath = kwargs.pop("storage")
    if not storage_filepath.endswith(".geojson"):
        storage_filepath += ".geojson"
    result_storage = gateway.serialize(results, filename=storage_filepath)
    click.echo("Results stored at '{}'".format(result_storage))
Ejemplo n.º 8
0
from eodag.api.core import EODataAccessGateway
from eodag.utils.logging import setup_logging
from eodag.utils import ProgressCallback
import os
import json
import pprint
import tqdm
setup_logging(verbose=1)
WORKSPACE="eodag_workspace"
DESCRIPTORS_PATH = r"products/stuttgart21.json"
PROVIDER = "sobloo"

dag = EODataAccessGateway('eodag.yml')
dag.set_preferred_provider(PROVIDER)


def loadDescriptorJson(path):
    with open(path, "r") as json_file:
        data = json.load(json_file)
    return data


def createDescriptors(data):
    descriptorDict = {}
    for type in data["PRODUCT_TYPES"]:
        descriptorDict[type] = {"productType": data["PRODUCT_TYPES"][type]}
        for prop in data:
            if prop != "PRODUCT_TYPES":
                descriptorDict[type][prop] = data[prop]
    return descriptorDict