From 87031d3c36c2830586054ed706b1a28bd7e5c43f Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Sat, 13 Jun 2020 10:23:00 +0200 Subject: Upstream 0.2.8 tarball as released on PyPI. --- PKG-INFO | 2 +- cdsapi.egg-info/PKG-INFO | 2 +- cdsapi.egg-info/SOURCES.txt | 1 + cdsapi/api.py | 21 +++++++++++++++++--- example-era5-update.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 6 files changed, 69 insertions(+), 6 deletions(-) create mode 100755 example-era5-update.py diff --git a/PKG-INFO b/PKG-INFO index 3498dd5..ab34266 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cdsapi -Version: 0.2.7 +Version: 0.2.8 Summary: Climate Data Store API Home-page: https://software.ecmwf.int/stash/projects/CDS/repos/cdsapi Author: ECMWF diff --git a/cdsapi.egg-info/PKG-INFO b/cdsapi.egg-info/PKG-INFO index 3498dd5..ab34266 100644 --- a/cdsapi.egg-info/PKG-INFO +++ b/cdsapi.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cdsapi -Version: 0.2.7 +Version: 0.2.8 Summary: Climate Data Store API Home-page: https://software.ecmwf.int/stash/projects/CDS/repos/cdsapi Author: ECMWF diff --git a/cdsapi.egg-info/SOURCES.txt b/cdsapi.egg-info/SOURCES.txt index cbd1fce..8c59e21 100644 --- a/cdsapi.egg-info/SOURCES.txt +++ b/cdsapi.egg-info/SOURCES.txt @@ -2,6 +2,7 @@ CONTRIBUTING.rst LICENSE.txt MANIFEST.in README.rst +example-era5-update.py example-era5.py example-glaciers.py setup.cfg diff --git a/cdsapi/api.py b/cdsapi/api.py index 1c8e598..70efa25 100644 --- a/cdsapi/api.py +++ b/cdsapi/api.py @@ -192,6 +192,16 @@ class Result(object): self.debug(metadata.headers) return metadata + def update(self, request_id=None): + if request_id is None: + request_id = self.reply['request_id'] + task_url = '%s/tasks/%s' % (self._url, request_id) + self.debug("GET %s", task_url) + + result = self.robust(self.session.get)(task_url, verify=self.verify) + result.raise_for_status() + self.reply = result.json() + def delete(self): if self._deleted: @@ -238,6 +248,7 @@ class Client(object): delete=True, retry_max=500, sleep_max=120, + wait_until_complete=True, info_callback=None, warning_callback=None, error_callback=None, @@ -287,6 +298,7 @@ class Client(object): self.full_stack = full_stack self.delete = delete self.last_state = None + self.wait_until_complete = wait_until_complete self.debug_callback = debug_callback self.warning_callback = warning_callback @@ -329,11 +341,11 @@ class Client(object): result = self._api('%s/tasks/services/%s/clientid-%s' % (self.url, name, uuid.uuid4().hex), request, 'PUT') return result - def workflow(self, code, *args, **kwargs): + def workflow(self, code, *args, workflow_name='application', **kwargs): params = dict(code=code, args=args, kwargs=kwargs, - workflow_name='application') + workflow_name=workflow_name) return self.service("tool.toolbox.orchestrator.run_workflow", params) def status(self, context=None): @@ -411,6 +423,9 @@ class Client(object): else: raise + if not self.wait_until_complete: + return Result(self, reply) + sleep = 1 while True: @@ -548,7 +563,7 @@ class Client(object): while tries < self.retry_max: try: r = call(*args, **kwargs) - except requests.exceptions.ConnectionError as e: + except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) as e: r = None self.warning("Recovering from connection error [%s], attemps %s of %s", e, tries, self.retry_max) diff --git a/example-era5-update.py b/example-era5-update.py new file mode 100755 index 0000000..5749e84 --- /dev/null +++ b/example-era5-update.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +# (C) Copyright 2018 ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation nor +# does it submit to any jurisdiction. + +import time +import cdsapi + +c = cdsapi.Client(debug=True, wait_until_complete=False) + +r = c.retrieve( + "reanalysis-era5-single-levels", + { + "variable": "2t", + "product_type": "reanalysis", + "date": "2015-12-01", + "time": "14:00", + "format": "netcdf", + }, +) + +sleep = 30 +while True: + r.update() + reply = r.reply + r.info("Request ID: %s, state: %s" % (reply['request_id'], reply['state'])) + + if reply['state'] == 'completed': + break + elif reply['state'] in ('queued', 'running'): + r.info("Request ID: %s, sleep: %s", reply['request_id'], sleep) + time.sleep(sleep) + elif reply['state'] in ('failed',): + r.error("Message: %s", reply['error'].get('message')) + r.error("Reason: %s", reply['error'].get('reason')) + for n in reply.get('error', {}).get('context', {}).get('traceback', '').split('\n'): + if n.strip() == '': + break + r.error(" %s", n) + raise Exception("%s. %s." % (reply['error'].get('message'), reply['error'].get('reason'))) + +r.download("test.nc") diff --git a/setup.py b/setup.py index ba51367..339549b 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def read(fname): return io.open(file_path, encoding='utf-8').read() -version = '0.2.7' +version = '0.2.8' setuptools.setup( -- cgit v1.2.3 From 127331bfa39c411d4994aadf0d3e1bb973575239 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Sat, 13 Jun 2020 10:27:28 +0200 Subject: Upstream 0.2.9 tarball as released on PyPI. --- PKG-INFO | 2 +- cdsapi.egg-info/PKG-INFO | 2 +- cdsapi.egg-info/SOURCES.txt | 1 - example-era5-update.py | 47 --------------------------------------------- setup.py | 2 +- 5 files changed, 3 insertions(+), 51 deletions(-) delete mode 100755 example-era5-update.py diff --git a/PKG-INFO b/PKG-INFO index ab34266..30e252e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cdsapi -Version: 0.2.8 +Version: 0.2.9 Summary: Climate Data Store API Home-page: https://software.ecmwf.int/stash/projects/CDS/repos/cdsapi Author: ECMWF diff --git a/cdsapi.egg-info/PKG-INFO b/cdsapi.egg-info/PKG-INFO index ab34266..30e252e 100644 --- a/cdsapi.egg-info/PKG-INFO +++ b/cdsapi.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cdsapi -Version: 0.2.8 +Version: 0.2.9 Summary: Climate Data Store API Home-page: https://software.ecmwf.int/stash/projects/CDS/repos/cdsapi Author: ECMWF diff --git a/cdsapi.egg-info/SOURCES.txt b/cdsapi.egg-info/SOURCES.txt index 8c59e21..cbd1fce 100644 --- a/cdsapi.egg-info/SOURCES.txt +++ b/cdsapi.egg-info/SOURCES.txt @@ -2,7 +2,6 @@ CONTRIBUTING.rst LICENSE.txt MANIFEST.in README.rst -example-era5-update.py example-era5.py example-glaciers.py setup.cfg diff --git a/example-era5-update.py b/example-era5-update.py deleted file mode 100755 index 5749e84..0000000 --- a/example-era5-update.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright 2018 ECMWF. -# -# This software is licensed under the terms of the Apache Licence Version 2.0 -# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -# In applying this licence, ECMWF does not waive the privileges and immunities -# granted to it by virtue of its status as an intergovernmental organisation nor -# does it submit to any jurisdiction. - -import time -import cdsapi - -c = cdsapi.Client(debug=True, wait_until_complete=False) - -r = c.retrieve( - "reanalysis-era5-single-levels", - { - "variable": "2t", - "product_type": "reanalysis", - "date": "2015-12-01", - "time": "14:00", - "format": "netcdf", - }, -) - -sleep = 30 -while True: - r.update() - reply = r.reply - r.info("Request ID: %s, state: %s" % (reply['request_id'], reply['state'])) - - if reply['state'] == 'completed': - break - elif reply['state'] in ('queued', 'running'): - r.info("Request ID: %s, sleep: %s", reply['request_id'], sleep) - time.sleep(sleep) - elif reply['state'] in ('failed',): - r.error("Message: %s", reply['error'].get('message')) - r.error("Reason: %s", reply['error'].get('reason')) - for n in reply.get('error', {}).get('context', {}).get('traceback', '').split('\n'): - if n.strip() == '': - break - r.error(" %s", n) - raise Exception("%s. %s." % (reply['error'].get('message'), reply['error'].get('reason'))) - -r.download("test.nc") diff --git a/setup.py b/setup.py index 339549b..337f08f 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def read(fname): return io.open(file_path, encoding='utf-8').read() -version = '0.2.8' +version = '0.2.9' setuptools.setup( -- cgit v1.2.3