def result(self): """ :return: The return value of the function for this completed task. """ if self._task_result is None: self.get_result(wait=True) if not self.is_success: return None if not self._is_return_value_loaded: return_value = Storage().get(self._task_result.result_key, storage_type='result') result_type = self._task_result.get('result_type', ResultType.LEGACY_PICKLE) if result_type == ResultType.LEGACY_PICKLE: return_value = cloudpickle.loads(return_value) if isinstance(return_value, dict): # For backwards-compatibility reasons, for legacy pickles the result is # wrapped in a dictionary. self._return_value = return_value['result'] else: self._return_value = return_value elif result_type == ResultType.JSON: self._return_value = json.loads(return_value.decode('utf-8')) else: raise RuntimeError( "Unknown result type: %s - update your tasks client") self._is_return_value_loaded = True return self._return_value
def setUp(self): url = "http://example.com" self.url = url self.client = Storage(url=url, auth=Auth(jwt_token=public_token, token_info_path=None)) self.match_url = re.compile(url)
def result(self): """ Property indicating the return value of the function for this completed task. :rtype: json or pickled type :return: The return value of the function for this completed task. """ if not self.is_success: return None if not self._is_return_value_loaded: if self._task_result.result_size_bytes > 0: return_value = Storage().get(self._task_result.result_key, storage_type="result") result_type = self._task_result.get("result_type", ResultType.LEGACY_PICKLE) if result_type == ResultType.JSON: self._return_value = json.loads( return_value.decode("utf-8")) elif result_type == ResultType.LEGACY_PICKLE: return_value = pickle.loads(return_value) if isinstance(return_value, dict): # For backwards-compatibility reasons (the old dlrun client requires it), # results to be pickled have always been wrapped in a dictionary. However, # all clients since version 0.10.0 ignore all the dictionary items except # for 'result', and all clients have always extracted the 'result' element. # In order for the service to remain compatible with older clients, we # must continue to do this even though it is wasteful. self._return_value = return_value["result"] else: # for the above reason, this code will likely never be reached. self._return_value = return_value else: raise RuntimeError( "Unknown result type: %s - update your tasks client") else: self._return_value = None self._is_return_value_loaded = True return self._return_value
def get_file(self, file_obj): """Download the exported Storage object to a local file. :param str file_obj: A file-like object or name of file to download into. :raises TransientResultError: If the export hasn't completed yet. """ if self.key is None: raise TransientResultError() else: return Storage().get_file(self.key, file_obj)
def log(self): """ :return: The log output for this completed task. """ if self._task_result is None: self.get_result(wait=True) if not self._is_log_loaded and self._task_result.get( 'log_size_bytes', 1) > 0: try: self._log = Storage().get(self._task_result.result_key, storage_type='logs') except NotFoundError: self._log = None self._is_log_loaded = True return self._log
def log(self): """ Property indicating the log output for this completed task. :rtype: str :return: The log output """ self.get_result(wait=True) if not self._is_log_loaded and self._task_result.get( "log_size_bytes", 1) > 0: try: self._log = Storage().get(self._task_result.result_key, storage_type="logs") except NotFoundError: self._log = None self._is_log_loaded = True return self._log
import logging import matplotlib.pyplot as plt from descarteslabs import metadata, raster from descarteslabs.client.services.cache import cached from descarteslabs.client.services.storage import Storage logging.basicConfig( level=logging.DEBUG, format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", ) client = Storage() @cached(client) def load_data(dltile): ids = metadata.ids( dltile=dltile, products=["landsat:LC08:01:RT:TOAR"], start_datetime="2017-08-01", end_datetime="2017-08-16", ) arrs = [] for id_ in ids: arr, meta = raster.ndarray( id_, bands=["red", "green", "blue", "nir", "swir1", "alpha"], dltile=dltile, order="gdal", )
from descarteslabs.client.services.storage import Storage storage_client = Storage() storage_client.set("my-key", "some-value") v = storage_client.get("my-key") assert v == "some-value" key_list = storage_client.list() assert "my-key" in key_list for key in storage_client.iter_list(): if "my-key" == key: print("Found it!") break else: raise RuntimeError("Failed to find it!")