From 0440d6d402012b46482bf98b93907a35cf48ab90 Mon Sep 17 00:00:00 2001 From: Shannon Osborne Date: Mon, 26 Aug 2019 12:41:52 -0400 Subject: [PATCH 1/3] Add check for PRD version --- pysiaf/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pysiaf/__init__.py b/pysiaf/__init__.py index 71d71d0c..b9228ff2 100644 --- a/pysiaf/__init__.py +++ b/pysiaf/__init__.py @@ -4,6 +4,9 @@ from __future__ import absolute_import, print_function, division +import re +import requests + from .version import * from .aperture import Aperture, HstAperture, JwstAperture @@ -14,4 +17,14 @@ # from .tests import test_aperture#, test_polynomial from .utils import polynomial, rotations, tools, projection -__all__ = ['Aperture', 'HstAperture', 'JwstAperture', 'SIAF', 'JWST_PRD_VERSION', 'JWST_PRD_DATA_ROOT', 'HST_PRD_VERSION', 'HST_PRD_DATA_ROOT', '_JWST_STAGING_ROOT', 'siaf', 'iando', 'polynomial', 'rotations', 'tools', 'compare', 'JWST_PRD_DATA_ROOT_EXCEL', 'generate', 'projection'] \ No newline at end of file +__all__ = ['Aperture', 'HstAperture', 'JwstAperture', 'SIAF', 'JWST_PRD_VERSION', 'JWST_PRD_DATA_ROOT', 'HST_PRD_VERSION', 'HST_PRD_DATA_ROOT', '_JWST_STAGING_ROOT', 'siaf', 'iando', 'polynomial', 'rotations', 'tools', 'compare', 'JWST_PRD_DATA_ROOT_EXCEL', 'generate', 'projection'] + +# Check PRD version is up to date +req = requests.get('https://github.com/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST').text +p = re.compile("/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST/(.*?)/SIAFXML") +prd_list = p.findall(req) +newest_prd = [x for x in sorted(prd_list, reverse=True)][0] + +if JWST_PRD_VERSION != newest_prd: + print("Warning: Local JWST PRD version {} is behind the current online version {}".format( + JWST_PRD_VERSION, newest_prd)) From 1620ce5050961b62cbcf4aa062c996da8da137e1 Mon Sep 17 00:00:00 2001 From: Shannon Osborne Date: Mon, 30 Sep 2019 10:39:06 -0400 Subject: [PATCH 2/3] Catch ConnectionError and make warning more bold --- pysiaf/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pysiaf/__init__.py b/pysiaf/__init__.py index b9228ff2..7a79a1d1 100644 --- a/pysiaf/__init__.py +++ b/pysiaf/__init__.py @@ -20,11 +20,15 @@ __all__ = ['Aperture', 'HstAperture', 'JwstAperture', 'SIAF', 'JWST_PRD_VERSION', 'JWST_PRD_DATA_ROOT', 'HST_PRD_VERSION', 'HST_PRD_DATA_ROOT', '_JWST_STAGING_ROOT', 'siaf', 'iando', 'polynomial', 'rotations', 'tools', 'compare', 'JWST_PRD_DATA_ROOT_EXCEL', 'generate', 'projection'] # Check PRD version is up to date -req = requests.get('https://github.com/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST').text -p = re.compile("/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST/(.*?)/SIAFXML") -prd_list = p.findall(req) -newest_prd = [x for x in sorted(prd_list, reverse=True)][0] - -if JWST_PRD_VERSION != newest_prd: - print("Warning: Local JWST PRD version {} is behind the current online version {}".format( - JWST_PRD_VERSION, newest_prd)) +try: + req = requests.get('https://github.com/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST').text + p = re.compile("/spacetelescope/pysiaf/tree/master/pysiaf/prd_data/JWST/(.*?)/SIAFXML") + prd_list = p.findall(req) + newest_prd = [x for x in sorted(prd_list, reverse=True)][0] + + if JWST_PRD_VERSION != newest_prd: + print("**WARNING**: LOCAL JWST PRD VERSION {} IS BEHIND THE CURRENT ONLINE VERSION {}\nPlease " + "consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf".format( + JWST_PRD_VERSION, newest_prd)) +except requests.exceptions.ConnectionError: + pass From 8454eb7120c3209134866e2f9877bf0486d16bc8 Mon Sep 17 00:00:00 2001 From: ` Date: Mon, 21 Oct 2019 21:23:58 -0400 Subject: [PATCH 3/3] print warning when offline --- pysiaf/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pysiaf/__init__.py b/pysiaf/__init__.py index 7a79a1d1..4f03e995 100644 --- a/pysiaf/__init__.py +++ b/pysiaf/__init__.py @@ -31,4 +31,6 @@ "consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf".format( JWST_PRD_VERSION, newest_prd)) except requests.exceptions.ConnectionError: + print("**WARNING**: NO INTERNET CONNECTION\nLOCAL JWST PRD VERSION {} CANNOT BE CHECKED AGAINST " + "ONLINE VERSION".format(JWST_PRD_VERSION)) pass