Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion design-docs/CLI-Data.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ with a utc offset using a file to specify the filter.

```
$ planet data stats --utc-offset +1:00 \
PSScene,PSOrthoTile day filter-desc.json
PSScene,REOrthoTile day filter-desc.json

<unedited API response json>
```
40 changes: 26 additions & 14 deletions planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
SEARCH_SORT_DEFAULT,
STATS_INTERVAL)

from planet.specs import (get_data_item_types,
validate_data_item_type,
SpecificationException)
from planet.specs import (FetchBundlesSpecError,
get_item_types,
SpecificationException,
validate_data_item_type)

from . import types
from .cmds import coro, translate_exceptions
Expand All @@ -38,9 +39,6 @@
from .session import CliSession
from .validators import check_geom

valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join(
get_data_item_types())


@asynccontextmanager
async def data_client(ctx):
Expand Down Expand Up @@ -79,6 +77,8 @@ def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
return item_types
except SpecificationException as e:
raise click.BadParameter(str(e))
except FetchBundlesSpecError as e:
raise click.ClickException(str(e))


def check_item_type(ctx, param, item_type) -> Optional[List[dict]]:
Expand All @@ -88,12 +88,14 @@ def check_item_type(ctx, param, item_type) -> Optional[List[dict]]:
validate_data_item_type(item_type)
except SpecificationException as e:
raise click.BadParameter(str(e))
except FetchBundlesSpecError as e:
raise click.ClickException(str(e))

return item_type


def check_search_id(ctx, param, search_id) -> str:
"""Ensure search id is a valix hex string"""
"""Ensure search id is a valid hex string"""
try:
_ = DataClient._check_search_id(search_id)
except exceptions.ClientError as e:
Expand Down Expand Up @@ -274,7 +276,7 @@ def filter(ctx,
echo_json(filt, pretty)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -320,7 +322,7 @@ async def search(ctx, item_types, geom, filter, limit, name, sort, pretty):
echo_json(item, pretty)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -417,7 +419,7 @@ async def search_run(ctx, search_id, sort, limit, pretty):
echo_json(item, pretty)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -477,7 +479,7 @@ async def search_delete(ctx, search_id):
await cl.delete_search(search_id)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -526,7 +528,7 @@ async def search_update(ctx,
echo_json(items, pretty)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -588,7 +590,7 @@ async def asset_download(ctx,
cl.validate_checksum(asset, path)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand All @@ -602,7 +604,7 @@ async def asset_activate(ctx, item_type, item_id, asset_type):
await cl.activate_asset(asset)


@data.command(epilog=valid_item_string) # type: ignore
@data.command() # type: ignore
@click.pass_context
@translate_exceptions
@coro
Expand Down Expand Up @@ -652,3 +654,13 @@ async def asset_wait(ctx, item_type, item_id, asset_type, delay, max_attempts):

# TODO: search_run()".
# TODO: item_get()".


@data.command() # type: ignore
@click.pass_context
@translate_exceptions
def show_item_types(ctx):
"""Show valid item types."""
click.echo("Valid item types:")
for it in get_item_types():
click.echo(f"- {it}")
68 changes: 63 additions & 5 deletions planet/cli/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from contextlib import asynccontextmanager
import logging
from pathlib import Path
from typing import List, Optional

import click

Expand All @@ -26,10 +27,47 @@
from .io import echo_json
from .options import limit, pretty
from .session import CliSession
from ..specs import (FetchBundlesSpecError,
get_bundle_names,
get_item_types,
SpecificationException,
validate_bundle,
validate_data_item_type)

LOGGER = logging.getLogger(__name__)


def check_item_type(ctx, param, item_type):
"""Validates the item type provided by comparing it to all supported
item types."""
try:
validate_data_item_type(item_type)
return item_type
except SpecificationException as e:
raise click.BadParameter(str(e))
except FetchBundlesSpecError as e:
raise click.ClickException(str(e))


def check_bundle(ctx, param, bundle) -> Optional[List[dict]]:
"""Validates the bundle provided by comparing it to all supported
bundles."""

# Get the value of item_type from the context
item_type = ctx.params.get('item_type')
if not item_type:
raise click.BadParameter("Item type is required to validate a bundle.")

try:
validate_bundle(item_type, bundle)
except SpecificationException as e:
raise click.BadParameter(str(e))
except FetchBundlesSpecError as e:
raise click.ClickException(str(e))

return bundle


@asynccontextmanager
async def orders_client(ctx):
base_url = ctx.obj['BASE_URL']
Expand Down Expand Up @@ -304,13 +342,13 @@ async def create(ctx, request, pretty, **kwargs):
@click.option('--item-type',
required=True,
help='Item type for requested item ids.',
type=click.Choice(planet.specs.get_item_types(),
case_sensitive=False))
type=str,
callback=check_item_type)
@click.option('--bundle',
required=True,
help='Asset type for the item.',
type=click.Choice(planet.specs.get_product_bundles(),
case_sensitive=False))
help='Bundle type for the item.',
type=str,
callback=check_bundle)
@click.option('--name',
required=True,
help='Order name. Does not need to be unique.',
Expand Down Expand Up @@ -426,3 +464,23 @@ async def request(ctx,
collection_id=collection_id)

echo_json(request, pretty)


@orders.command() # type: ignore
@click.pass_context
@translate_exceptions
def show_item_types(ctx):
"""Show valid item types for ordering."""
click.echo("Valid item types:")
for it in get_item_types():
click.echo(f"- {it}")


@orders.command() # type: ignore
@click.pass_context
@translate_exceptions
def show_bundles(ctx):
"""Show valid bundle names for ordering."""
click.echo("Valid bundles:")
for it in get_bundle_names():
click.echo(f"- {it}")
32 changes: 15 additions & 17 deletions planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
from planet.clients.subscriptions import SubscriptionsClient
from .. import subscription_request
from ..subscription_request import sentinel_hub
from ..specs import get_item_types, validate_item_type, SpecificationException
from ..specs import FetchBundlesSpecError, get_item_types, SpecificationException, validate_item_type
from .validators import check_geom

ALL_ITEM_TYPES = get_item_types()
valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join(ALL_ITEM_TYPES)


def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
"""Validates each item types provided by comparing them to all supported
Expand All @@ -28,17 +25,8 @@ def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
return item_types
except SpecificationException as e:
raise click.BadParameter(str(e))


def check_item_type(ctx, param, item_type) -> Optional[List[dict]]:
"""Validates the item type provided by comparing it to all supported
item types."""
try:
validate_item_type(item_type)
except SpecificationException as e:
raise click.BadParameter(str(e))

return item_type
except FetchBundlesSpecError as e:
raise click.ClickException(str(e))


@asynccontextmanager
Expand Down Expand Up @@ -395,7 +383,7 @@ def request(name,
echo_json(res, pretty)


@subscriptions.command(epilog=valid_item_string) # type: ignore
@subscriptions.command() # type: ignore
@translate_exceptions
@click.option('--item-types',
required=True,
Expand Down Expand Up @@ -473,7 +461,7 @@ def request_catalog(item_types,
@click.option(
'--var-id',
required=True,
help='A Planetary Variable ID. See documenation for all available IDs.')
help='A Planetary Variable ID. See documentation for all available IDs.')
@click.option(
'--geometry',
required=True,
Expand Down Expand Up @@ -505,3 +493,13 @@ def request_pv(var_type, var_id, geometry, start_time, end_time, pretty):
end_time=end_time,
)
echo_json(res, pretty)


@subscriptions.command() # type: ignore
@click.pass_context
@translate_exceptions
def show_item_types(ctx):
"""Show valid item types for catalog subscriptions."""
click.echo("Valid item types:")
for it in get_item_types():
click.echo(f"- {it}")
2 changes: 1 addition & 1 deletion planet/clients/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
ORDERS_PATH = '/orders/v2'
BULK_PATH = '/bulk/orders/v2'

# Order states https://developers.planet.com/docs/orders/ordering/#order-states
# Order states https://developers.planet.com/apis/orders/states/
# this is in order of state progression except for final states
ORDER_STATE_SEQUENCE = \
('queued', 'running', 'failed', 'success', 'partial', 'cancelled')
Expand Down
12 changes: 0 additions & 12 deletions planet/data/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# data
This directory contains static external resources used by the codebase.

## Orders Spec

### Files

* `orders_product_bundle_2024-08-12.json`

### Description

This file was downloaded from the Planet
[Product Bundles Reference](https://developers.planet.com/docs/orders/product-bundles-reference/)
page and is stored without any adjustments.

## GeoJSON Schemas

### Files
Expand Down
Loading
Loading