Skip to content

Commit

Permalink
fix: handle optional flags from Argo
Browse files Browse the repository at this point in the history
  • Loading branch information
amfage committed Feb 17, 2025
1 parent b96c851 commit 96cd6aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
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
9 changes: 6 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,16 +100,18 @@ 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,
default=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,
default=False,
)
parser.add_argument(
"--current-datetime",
Expand All @@ -129,6 +131,7 @@ def parse_args(args: List[str] | None) -> Namespace:
def main(args: List[str] | None = None) -> None:
start_time = time_in_ms()
arguments = parse_args(args)
print("capture dates:", arguments.capture_dates)
uri = arguments.uri
collection_id = arguments.collection_id

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

0 comments on commit 96cd6aa

Please sign in to comment.