From 0694662f789a22354d615b92839182aab137469c Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 25 Feb 2023 14:43:37 -0800 Subject: [PATCH] Moved custom param types to param_types --- osxphotos/cli/batch_edit.py | 34 +--------------------------------- osxphotos/cli/param_types.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/osxphotos/cli/batch_edit.py b/osxphotos/cli/batch_edit.py index aaf8ecac..e864462b 100644 --- a/osxphotos/cli/batch_edit.py +++ b/osxphotos/cli/batch_edit.py @@ -17,39 +17,7 @@ from osxphotos.sqlitekvstore import SQLiteKVStore from .cli_commands import echo, echo_error, selection_command, verbose from .kvstore import kvstore -from .param_types import TemplateString - - -class Latitude(click.ParamType): - - name = "Latitude" - - def convert(self, value, param, ctx): - try: - latitude = float(value) - if latitude < -90 or latitude > 90: - raise ValueError - return latitude - except Exception: - self.fail( - f"Invalid latitude {value}. Must be a floating point number between -90 and 90." - ) - - -class Longitude(click.ParamType): - - name = "Longitude" - - def convert(self, value, param, ctx): - try: - longitude = float(value) - if longitude < -180 or longitude > 180: - raise ValueError - return longitude - except Exception: - self.fail( - f"Invalid longitude {value}. Must be a floating point number between -180 and 180." - ) +from .param_types import Latitude, Longitude, TemplateString @selection_command(name="batch-edit") diff --git a/osxphotos/cli/param_types.py b/osxphotos/cli/param_types.py index 56daf658..2ce200cf 100644 --- a/osxphotos/cli/param_types.py +++ b/osxphotos/cli/param_types.py @@ -23,6 +23,8 @@ __all__ = [ "DeprecatedPath", "ExportDBType", "FunctionCall", + "Latitude", + "Longitude", "PathOrStdin", "StrpDateTimePattern", "TemplateString", @@ -274,3 +276,35 @@ class StrpDateTimePattern(click.ParamType): self.fail(f"Invalid strpdatetime format string: {value}. {e}") else: return value + + +class Latitude(click.ParamType): + + name = "Latitude" + + def convert(self, value, param, ctx): + try: + latitude = float(value) + if latitude < -90 or latitude > 90: + raise ValueError + return latitude + except Exception: + self.fail( + f"Invalid latitude {value}. Must be a floating point number between -90 and 90." + ) + + +class Longitude(click.ParamType): + + name = "Longitude" + + def convert(self, value, param, ctx): + try: + longitude = float(value) + if longitude < -180 or longitude > 180: + raise ValueError + return longitude + except Exception: + self.fail( + f"Invalid longitude {value}. Must be a floating point number between -180 and 180." + )