Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle optional flags from Argo TDE-1346 #1287

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions scripts/cli/cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,20 @@ def str_to_gsd(value: str) -> Decimal:
)

return Decimal(number_value)


def str_to_bool(value: str) -> bool:
if value == "true":
return True
if value == "false":
return False
raise argparse.ArgumentTypeError(f"Invalid boolean (must be exactly 'true' or 'false'): {value}")


def str_to_list_or_none(values: str) -> list[Decimal] | None:
if not values:
return None
result = [Decimal(value) for value in values.split(",")]
if len(result) != 2:
raise argparse.ArgumentTypeError(f"Invalid list - must be blank or exactly 2 values x,y. Received: {values}")
return result
6 changes: 3 additions & 3 deletions scripts/collection_from_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from boto3 import client
from linz_logger import get_log

from scripts.cli.cli_helper import coalesce_multi_single, str_to_gsd
from scripts.cli.cli_helper import coalesce_multi_single, str_to_bool, str_to_gsd
from scripts.datetimes import RFC_3339_DATETIME_FORMAT, parse_rfc_3339_datetime
from scripts.files.files_helper import SUFFIX_FOOTPRINT, SUFFIX_JSON
from scripts.files.fs_s3 import bucket_name_from_path, get_object_parallel_multithreading, list_files_in_uri
Expand Down Expand Up @@ -100,15 +100,15 @@ def parse_args(args: List[str] | None) -> Namespace:
parser.add_argument(
"--capture-dates",
dest="capture_dates",
action="store_true",
help="Add a capture-dates.geojson.gz file to the collection assets",
type=str_to_bool,
required=False,
)
parser.add_argument(
"--add-title-suffix",
dest="add_title_suffix",
action="store_true",
help="Add a title suffix to the collection title based on the lifecycle. For example, '[TITLE] - Preview'",
type=str_to_bool,
required=False,
)
parser.add_argument(
Expand Down
28 changes: 9 additions & 19 deletions scripts/standardise_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import os
import sys
from datetime import datetime, timezone
from decimal import Decimal

from linz_logger import get_log

from scripts.cli.cli_helper import InputParameterError, is_argo, load_input_files, str_to_gsd, valid_date
from scripts.cli.cli_helper import (
InputParameterError,
is_argo,
load_input_files,
str_to_bool,
str_to_gsd,
str_to_list_or_none,
valid_date,
)
from scripts.datetimes import RFC_3339_DATETIME_FORMAT, format_rfc_3339_nz_midnight_datetime_string
from scripts.files.file_tiff import FileTiff
from scripts.files.files_helper import SUFFIX_JSON, ContentType
Expand All @@ -17,23 +24,6 @@
from scripts.standardising import StandardisingConfig, run_standardising


def str_to_bool(value: str) -> bool:
if value == "true":
return True
if value == "false":
return False
raise argparse.ArgumentTypeError(f"Invalid boolean (must be exactly 'true' or 'false'): {value}")


def str_to_list_or_none(values: str) -> list[Decimal] | None:
if not values:
return None
result = [Decimal(value) for value in values.split(",")]
if len(result) != 2:
raise argparse.ArgumentTypeError(f"Invalid list - must be blank or exactly 2 values x,y. Received: {values}")
return result


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--preset", dest="preset", required=True, help="Standardised file format. Example: webp")
Expand Down
Loading