-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from scottstanie/update-datasets-cli
Update datasets hash and add first cli
- Loading branch information
Showing
7 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Command-line interface for opera-utils.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
import logging | ||
|
||
import click | ||
|
||
from .burst_frame_db import get_frame_bbox | ||
|
||
|
||
@click.group() | ||
@click.version_option() | ||
@click.option("--debug", is_flag=True, default=False) | ||
@click.pass_context | ||
def cli_app(ctx, debug): | ||
"""Orca command-line interface.""" | ||
level = logging.DEBUG if debug else logging.INFO | ||
handler = logging.StreamHandler() | ||
logging.basicConfig(level=level, handlers=[handler]) | ||
|
||
|
||
@cli_app.command() | ||
@click.argument("frame_id") | ||
@click.option( | ||
"--latlon", | ||
"-l", | ||
is_flag=True, | ||
help="Output the bounding box in latitude/longitude (EPSG:4326)", | ||
) | ||
@click.option( | ||
"--bounds-only", | ||
"-b", | ||
is_flag=True, | ||
help="Output only (left, bottom, right, top) and omit EPSG", | ||
) | ||
def frame_bbox(frame_id, latlon: bool, bounds_only: bool): | ||
"""Look up the EPSG/bounding box for FRAME_ID. | ||
Outputs as JSON string to stdout like | ||
{"epsg": 32618, "bbox": [157140.0, 4145220.0, 440520.0, 4375770.0]} | ||
Unless `--bounds-only` is given | ||
""" | ||
epsg, bounds = get_frame_bbox(frame_id=frame_id) | ||
if latlon: | ||
from opera_utils._helpers import reproject_bounds | ||
|
||
bounds = reproject_bounds(bounds, epsg, 4326) | ||
if bounds_only: | ||
click.echo(list(bounds)) | ||
else: | ||
obj = dict(epsg=epsg, bbox=bounds) | ||
click.echo(json.dumps(obj)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from click.testing import CliRunner | ||
|
||
from opera_utils.cli import cli_app | ||
|
||
|
||
def test_cli_help(): | ||
runner = CliRunner() | ||
result = runner.invoke(cli_app, ["--help"]) | ||
assert result.exit_code == 0 | ||
assert result.output.startswith("Usage:") | ||
|
||
|
||
def test_frame_bbox_help(): | ||
runner = CliRunner() | ||
result = runner.invoke(cli_app, ["frame-bbox", "--help"]) | ||
assert result.exit_code == 0 |