Skip to content

Commit abb65a4

Browse files
authored
Merge pull request #990 from planetlabs/issue970
Add archive options to planet-orders-request
2 parents 0aaf6c5 + d84c3ad commit abb65a4

File tree

5 files changed

+61
-22
lines changed

5 files changed

+61
-22
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
2.1.0 (TBD)
22

3+
- The --cloudconfig option of the request command of the orders CLI has been
4+
superseded by a new --delivery option, with --cloudconfig left as an alias.
5+
New --archive-type, --archive-filename, and --single-archive options to
6+
control the zip archiving of order outputs without any cloud storage delivery
7+
have also been added (#990).
8+
39
2.1b1 (2023-07-11)
410

511
Added:

planet/cli/orders.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,27 @@ async def create(ctx, request: str, pretty):
253253
default=False,
254254
is_flag=True,
255255
help='Send email notification when order is complete.')
256+
@click.option('--archive-type',
257+
type=click.Choice(['zip']),
258+
help="Optionally zip archive each item bundle.")
259+
@click.option('--archive-filename',
260+
default='{{name}}-{{order_id}}.zip',
261+
show_default=True,
262+
help="Templated filename for archived bundles or orders.")
263+
@click.option('--single-archive',
264+
is_flag=True,
265+
default=False,
266+
show_default=True,
267+
help="Optionally zip archive all item bundles together.")
256268
@click.option(
269+
'--delivery',
257270
'--cloudconfig',
258271
type=types.JSON(),
259-
help="""Credentials for cloud storage provider to enable cloud delivery of
260-
data. Can be a json string, filename, or '-' for stdin.""")
272+
help=("Delivery configuration, which may include credentials for a cloud "
273+
"storage provider, to enable cloud delivery of data, and/or "
274+
"parameters for bundling deliveries as zip archives. Can be a JSON "
275+
"string, a filename, or '-' for stdin. The --cloudconfig option is "
276+
"an alias for this use case."))
261277
@click.option(
262278
'--stac/--no-stac',
263279
default=True,
@@ -274,7 +290,10 @@ async def request(ctx,
274290
clip,
275291
tools,
276292
email,
277-
cloudconfig,
293+
archive_type,
294+
archive_filename,
295+
single_archive,
296+
delivery,
278297
stac,
279298
pretty):
280299
"""Generate an order request.
@@ -303,14 +322,12 @@ async def request(ctx,
303322
except planet.exceptions.ClientError as e:
304323
raise click.BadParameter(e)
305324

306-
if cloudconfig:
307-
delivery = planet.order_request.delivery(cloud_config=cloudconfig)
308-
if "google_earth_engine" in cloudconfig:
309-
stac = False
310-
else:
311-
delivery = None
325+
delivery = planet.order_request.delivery(archive_type=archive_type,
326+
archive_filename=archive_filename,
327+
single_archive=single_archive,
328+
cloud_config=delivery)
312329

313-
if stac:
330+
if stac and "google_earth_engine" not in delivery:
314331
stac_json = {'stac': {}}
315332
else:
316333
stac_json = {}

planet/cli/subscriptions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ async def list_subscription_results_cmd(ctx,
226226
required=True,
227227
type=types.JSON(),
228228
help='Source JSON. Can be a string, filename, or - for stdin.')
229-
@click.option('--delivery',
230-
required=True,
231-
type=types.JSON(),
232-
help='Delivery JSON. Can be a string, filename, or - for stdin.')
229+
@click.option(
230+
'--delivery',
231+
required=True,
232+
type=types.JSON(),
233+
help=("Delivery configuration, including credentials for a cloud "
234+
"storage provider, to enable cloud delivery of data. Can be a "
235+
"JSON string, a filename, or '-' for stdin. "))
233236
@click.option(
234237
'--notifications',
235238
type=types.JSON(),

planet/order_request.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Functionality for preparing order details for use in creating an order"""
1616
from __future__ import annotations # https://stackoverflow.com/a/33533514
1717
import logging
18-
from typing import Optional, Any, Dict, List, Union
18+
from typing import Any, Dict, List, Mapping, Optional, Union
1919

2020
from . import geojson, specs
2121
from .exceptions import ClientError
@@ -163,9 +163,9 @@ def notifications(email: Optional[bool] = None,
163163

164164

165165
def delivery(archive_type: Optional[str] = None,
166-
single_archive: bool = False,
166+
single_archive: Optional[bool] = False,
167167
archive_filename: Optional[str] = None,
168-
cloud_config: Optional[dict] = None) -> dict:
168+
cloud_config: Optional[Mapping] = None) -> dict:
169169
"""Order delivery configuration.
170170
171171
Example:
@@ -196,20 +196,21 @@ def delivery(archive_type: Optional[str] = None,
196196
Raises:
197197
planet.specs.SpecificationException: If archive_type is not valid.
198198
"""
199+
config: Dict[str, Any] = {}
200+
199201
if archive_type:
200202
archive_type = specs.validate_archive_type(archive_type)
201203

202-
# for missing archive file name
203204
if archive_filename is None:
204205
archive_filename = "{{name}}_{{order_id}}.zip"
205206

206-
fields = ['archive_type', 'single_archive', 'archive_filename']
207-
values = [archive_type, single_archive, archive_filename]
208-
209-
config = dict((k, v) for k, v in zip(fields, values) if v)
207+
config.update(archive_type=archive_type,
208+
archive_filename=archive_filename,
209+
single_archive=single_archive)
210210

211211
if cloud_config:
212212
config.update(cloud_config)
213+
213214
return config
214215

215216

tests/unit/test_order_request.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def test_delivery_missing_archive_details():
175175
expected = {
176176
'archive_type': 'zip',
177177
'archive_filename': "{{name}}_{{order_id}}.zip",
178+
'single_archive': False,
178179
'amazon_s3': {
179180
'aws_access_key_id': 'aws_access_key_id',
180181
'aws_secret_access_key': 'aws_secret_access_key',
@@ -317,3 +318,14 @@ def test_band_math_tool_invalid_pixel_type():
317318
order_request.band_math_tool(b1='b1',
318319
b2='arctan(b1)',
319320
pixel_type="invalid")
321+
322+
323+
def test_no_archive_items_without_type():
324+
"""Without an archive type no filename or single option are passed."""
325+
delivery_config = order_request.delivery(
326+
None, True, TEST_ARCHIVE_FILENAME, cloud_config={"bogus_storage": {}})
327+
328+
assert "bogus_storage" in delivery_config
329+
assert "archive_type" not in delivery_config
330+
assert "archive_filename" not in delivery_config
331+
assert "single_archive" not in delivery_config

0 commit comments

Comments
 (0)