summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2020-06-13 10:23:00 +0200
committerGard Spreemann <gspr@nonempty.org>2020-06-13 10:23:00 +0200
commit87031d3c36c2830586054ed706b1a28bd7e5c43f (patch)
tree39d9e6283cb61ca6da53cf9afa95a63746a1edcd
parent7a8cb4f4da753b19954d8c78d8588787a32e3ebe (diff)
Upstream 0.2.8 tarball as released on PyPI.upstream/0.2.8
-rw-r--r--PKG-INFO2
-rw-r--r--cdsapi.egg-info/PKG-INFO2
-rw-r--r--cdsapi.egg-info/SOURCES.txt1
-rw-r--r--cdsapi/api.py21
-rwxr-xr-xexample-era5-update.py47
-rw-r--r--setup.py2
6 files changed, 69 insertions, 6 deletions
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(