Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cwmscli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ def cli():
cli.add_command(commands_cwms.shefcritimport)
cli.add_command(commands_cwms.csv2cwms_cmd)
cli.add_command(commands_cwms.blob_group)
cli.add_command(commands_cwms.timeseries)
237 changes: 236 additions & 1 deletion cwmscli/commands/commands_cwms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cwmscli import requirements as reqs
from cwmscli.callbacks import csv_to_list
from cwmscli.commands import csv2cwms
from cwmscli.utils import api_key_loc_option, common_api_options
from cwmscli.utils import api_key_loc_option, common_api_options, to_uppercase
from cwmscli.utils.deps import requires


Expand Down Expand Up @@ -250,3 +250,238 @@ def list_cmd(**kwargs):


# endregion


# region Time Series
# ================================================================================
# Time Series
# ================================================================================
@click.group(
"timeseries",
help="Manage CWMS Time Series",
epilog=textwrap.dedent(
"""
Example Usage:\n
- cwms-cli timeseries group --help : Manage Time Series Groups\n
- More Coming Soon!
"""
),
)
@requires(reqs.cwms)
def timeseries():
pass


# region Time Series Group
# ================================================================================
# Time Series Group
# ================================================================================
@timeseries.group(
"group",
help="Manage CWMS Time Series Groups (upload, download, delete, update, list)",
epilog=textwrap.dedent(
"""
Example Usage:\n
- Store Time Series Groups from CLI\n
- Download a Time Series Group to your local filesystem\n
- Update a Time Series Group description, category, and identifiers\n
- Bulk list Time Series Groups for a given office
"""
),
)
def timeseries_group():
pass


# ================================================================================
# Store
# ================================================================================
@timeseries_group.command("store", help="Store a timeseries group")
@click.option(
"--overwrite/--no-overwrite",
default=False,
show_default=True,
help="If true, replace existing timeseries group.",
)
@click.option(
"--input-file",
required=False,
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=str),
help="Specify a relative/absolute path to a JSON file containing the request body. If not specified, it will be read from stdin.",
)
@click.option("--dry-run", is_flag=True, help="Show request; do not send.")
@common_api_options
def timeseries_group_upload(**kwargs):
from cwmscli.commands.timeseries.group import store_cmd

store_cmd(**kwargs)


# ================================================================================
# Download
# ================================================================================
@timeseries_group.command("retrieve", help="Download timeseries group")
@click.option(
"--group-id",
type=str,
help="Specifies the timeseries group whose data is to be included in the response",
)
@click.option(
"--office",
type=str,
callback=to_uppercase,
help="Specifies the owning office of the timeseries assigned to the group whose data is to be included in the response. This will limit the assigned timeseries returned to only those assigned to the specified office.",
)
@click.option(
"--category-office-id",
type=str,
help="Specifies the owning office of the timeseries group category",
)
@click.option(
"--group-office-id",
type=str,
help="Specifies the owning office of the timeseries group",
)
@click.option(
"--category-id",
type=str,
help="Specifies the category containing the timeseries group whose data is to be included in the response.",
)
@click.option("--dry-run", is_flag=True, help="Show request; do not send.")
@click.option(
"--dest-dir",
required=False,
type=click.Path(exists=True, dir_okay=True, readable=True, path_type=str),
help="""Specify a relative/absolute path to a directory where the output file will be saved.
The file will be named <office>_<group-id>.json.
If not specified, it will be written to stdout.""",
)
@common_api_options
def timeseries_group_download(**kwargs):
from cwmscli.commands.timeseries.group import retrieve_cmd

retrieve_cmd(**kwargs)


# ================================================================================
# Delete
# ================================================================================
@timeseries_group.command("delete", help="Deletes requested time series group")
@click.option(
"--group-id", required=True, type=str, help="The time series group to be deleted"
)
@click.option(
"--category-id",
required=True,
type=str,
help="Specifies the time series category of the time series group to be deleted",
)
@click.option(
"--office",
type=str,
callback=to_uppercase,
help="Specifies the owning office of the time series group to be deleted",
)
@click.option("--dry-run", is_flag=True, help="Show request; do not send.")
@common_api_options
def delete_cmd(**kwargs):
from cwmscli.commands.timeseries.group import delete_cmd

delete_cmd(**kwargs)


# ================================================================================
# Update
# ================================================================================
@timeseries_group.command("update", help="Update/patch a timeseries group")
@click.option("--blob-id", required=True, type=str, help="Blob ID to update.")
@click.option("--dry-run", is_flag=True, help="Show request; do not send.")
@click.option(
"--description",
default=None,
help="New description JSON or text.",
)
@click.option(
"--media-type",
default=None,
help="New media type (guessed from file if omitted).",
)
@click.option(
"--input-file",
required=False,
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=str),
help="Optional file content to upload with update.",
)
@click.option(
"--overwrite/--no-overwrite",
default=False,
show_default=True,
help="If true, replace existing blob.",
)
@common_api_options
def update_cmd(**kwargs):
from cwmscli.commands.timeseries.group import update_cmd

update_cmd(**kwargs)


# timeseries_category_like=timeseries_category_like,
# category_office_id=category_office_id,
# timeseries_group_like=timeseries_group_like,


# ================================================================================
# List
# ================================================================================
@timeseries_group.command("list", help="List blobs with optional filters and sorting")
@click.option(
"--include-assigned",
default=False,
show_default=True,
help="Include the assigned timeseries in the returned timeseries groups. (default: true)",
)
@click.option(
"--timeseries-category-like",
help="Posix regular expression matching against the timeseries category id",
)
@click.option(
"--category-office-id",
help="Specifies the owning office of the timeseries group category",
)
@click.option(
"--timeseries-group-like",
help="Posix regular expression matching against the timeseries group id",
)
@click.option(
"--columns",
multiple=True,
callback=csv_to_list,
help="Columns to show (repeat or comma-separate).",
)
@click.option(
"--sort-by",
multiple=True,
callback=csv_to_list,
help="Columns to sort by (repeat or comma-separate).",
)
@click.option(
"--desc/--asc",
default=False,
show_default=True,
help="Sort descending instead of ascending.",
)
@click.option("--limit", type=int, default=None, help="Max rows to show.")
@click.option(
"--to-csv",
type=click.Path(dir_okay=False, writable=True, path_type=str),
help="If set, write results to this CSV file.",
)
@common_api_options
def list_cmd(**kwargs):
from cwmscli.commands.timeseries.group import list_cmd

list_cmd(**kwargs)


# endregion
# endregion
Loading