From a115349c06fa7da5c1bdeb4e11901392ac2f4923 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 24 Sep 2025 16:41:15 -0600 Subject: [PATCH 1/5] add function to validate dsid --- src/gdex_api_client/gdex_client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gdex_api_client/gdex_client.py b/src/gdex_api_client/gdex_client.py index 3883bc2..aa9ac50 100755 --- a/src/gdex_api_client/gdex_client.py +++ b/src/gdex_api_client/gdex_client.py @@ -26,6 +26,7 @@ import argparse import codecs import pdb +import ms BASE_URL = 'https://gdex.ucar.edu/api/' @@ -79,6 +80,14 @@ def add_ds_str(ds_num): sys.exit() return ds_num +def validate_dsid(dsid): + """ Validate dsid from command line input """ + ms = re.match(r'^([a-z]{1})(\d{3})(\d{3})$', dsid) + if ms: + return dsid + else: + raise click.BadParameter("format must be 'dnnnnnn'") + def get_userinfo(): """Get token from command line.""" print('Please visit https://gdex.ucar.edu/accounts/profile/ to access token.') From cdac6d0467a4af3ae3c673fc015a5c7f6d291842 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 24 Sep 2025 16:43:14 -0600 Subject: [PATCH 2/5] Update gdex_client.py --- src/gdex_api_client/gdex_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gdex_api_client/gdex_client.py b/src/gdex_api_client/gdex_client.py index aa9ac50..e0a7e32 100755 --- a/src/gdex_api_client/gdex_client.py +++ b/src/gdex_api_client/gdex_client.py @@ -26,7 +26,7 @@ import argparse import codecs import pdb -import ms +import re BASE_URL = 'https://gdex.ucar.edu/api/' @@ -86,7 +86,7 @@ def validate_dsid(dsid): if ms: return dsid else: - raise click.BadParameter("format must be 'dnnnnnn'") + raise ValueError("dataset number 'dsid' must be formatted as 'dnnnnnn'") def get_userinfo(): """Get token from command line.""" From 23dff232f679c4c58942b7bad370d792836fc998 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 24 Sep 2025 16:49:37 -0600 Subject: [PATCH 3/5] Refactor control file template generation to use validated dsid --- src/gdex_api_client/gdex_client.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/gdex_api_client/gdex_client.py b/src/gdex_api_client/gdex_client.py index e0a7e32..dcd9259 100755 --- a/src/gdex_api_client/gdex_client.py +++ b/src/gdex_api_client/gdex_client.py @@ -68,18 +68,6 @@ def query(args=None): print(json.dumps(result, indent=3)) return result -def add_ds_str(ds_num): - """Adds 'ds' to ds_num if needed. - Throws error if ds number isn't valid. - """ - ds_num = ds_num.strip() - if ds_num[0:2] != 'ds': - ds_num = 'ds' + ds_num - if len(ds_num) != 7: - print("'" + ds_num + "' is not valid.") - sys.exit() - return ds_num - def validate_dsid(dsid): """ Validate dsid from command line input """ ms = re.match(r'^([a-z]{1})(\d{3})(\d{3})$', dsid) @@ -520,10 +508,11 @@ def write_control_file_template(ds, write_location='./'): Returns: dict: JSON decoded result of the query. """ + dsid = validate_dsid(ds) _json = get_control_file_template(ds) control_str = _json['data']['template'] - template_filename = write_location + add_ds_str(ds) + '_control.ctl' + template_filename = write_location + dsid + '_control.ctl' if os.path.exists(template_filename): print(template_filename + " already exists.\nExiting") exit(1) From ba971f50a119bf94335346aca8537b705d76c3d3 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 24 Sep 2025 16:49:57 -0600 Subject: [PATCH 4/5] Bump version to 2.0.2 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e5bc36a..a997d62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "gdex-api-client" -version = "2.0.1" +version = "2.0.2" dependencies = [ "requests", ] From bd5fab316d8d1283ac190f150bc13a08ad9d4072 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 24 Sep 2025 16:54:05 -0600 Subject: [PATCH 5/5] Bump version to 2.0.3 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a997d62..4780a63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "gdex-api-client" -version = "2.0.2" +version = "2.0.3" dependencies = [ "requests", ]