From e8c0450423e132ef5f75916f8c05dfa71d2fc5d8 Mon Sep 17 00:00:00 2001 From: "Krzysztof (Chris) Bernat" Date: Wed, 27 Sep 2017 19:21:37 +0100 Subject: [PATCH] #337 initial state for Data Source Status reporting --- cate/core/ds.py | 22 ++++++++++++++++++++++ cate/ds/local.py | 23 ++++++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/cate/core/ds.py b/cate/core/ds.py index 78bf76e48..dc4bad212 100644 --- a/cate/core/ds.py +++ b/cate/core/ds.py @@ -80,6 +80,7 @@ import glob from abc import ABCMeta, abstractmethod +from enum import Enum from math import ceil, sqrt from typing import Sequence, Optional, Union, Tuple, Any @@ -137,6 +138,13 @@ def protocols(self) -> []: def data_store(self) -> 'DataStore': """The data store to which this data source belongs.""" + @property + def status(self) -> 'DataSourceStatus': + """ + Return information about data source accessibility + """ + return DataSourceStatus.READY + # TODO (forman): issue #399 - remove "ds_id", see TODO on "DataStore.query()" def matches(self, ds_id: str = None, query_expr: str = None) -> bool: """ @@ -330,6 +338,20 @@ def _repr_html_(self): """Provide an HTML representation of this object for IPython.""" +class DataSourceStatus(Enum): + """ + Enum stating current state of Data Source accessibility. + * READY - data is complete and ready to use + * ERROR - data initialization process has been interrupted, causing that data source is incomplete or/and corrupted + * PROCESSING - data source initialization process is in progress. + * CANCELLED - data initialization process has been intentionally interrupted by user + """ + READY = "READY", + ERROR = "ERROR", + PROCESSING = "PROCESSING", + CANCELLED = "CANCELLED" + + class DataStore(metaclass=ABCMeta): """ Represents a data store of data sources. diff --git a/cate/ds/local.py b/cate/ds/local.py index 20604862a..29498b58c 100644 --- a/cate/ds/local.py +++ b/cate/ds/local.py @@ -53,7 +53,7 @@ from cate.conf import get_config_value, get_data_stores_path from cate.conf.defaults import NETCDF_COMPRESSION_LEVEL -from cate.core.ds import DATA_STORE_REGISTRY, DataStore, DataSource, open_xarray_dataset +from cate.core.ds import DATA_STORE_REGISTRY, DataSourceStatus, DataStore, DataSource, open_xarray_dataset from cate.core.types import Polygon, PolygonLike, TimeRange, TimeRangeLike, VarNames, VarNamesLike from cate.util.monitor import Monitor @@ -79,8 +79,8 @@ def add_to_data_store_registry(): # TODO (kbernat): document this class class LocalDataSource(DataSource): """ - - :param ds_id: + Local Data Source implementation provides access to locally stored data sets. + :param ds_id: unique ID of data source :param files: :param data_store: :param temporal_coverage: @@ -131,7 +131,7 @@ def __init__(self, 'standard_name': '' } for var_name in self._variables] - self._is_complete = True + self._state = DataSourceStatus.READY def _resolve_file_path(self, path) -> Sequence: return glob(os.path.join(self._data_store.data_store_path, path)) @@ -540,6 +540,10 @@ def spatial_coverage(self): def data_store(self) -> DataStore: return self._data_store + @property + def status(self) -> DataSourceStatus: + return self._status + @property def id(self) -> str: return self._id @@ -562,7 +566,7 @@ def is_complete(self) -> bool: Return a DataSource creation state :return: """ - return self._is_complete + return self._state is DataSourceStatus.READY @property def is_empty(self) -> bool: @@ -574,11 +578,12 @@ def is_empty(self) -> bool: def set_completed(self, state: bool): """ - Sets state of DataSource creation/completion - :param state: Is DataSource completed - :return: + Sets state of DataSource completion """ - self._is_complete = state + if state: + self._state = DataSourceStatus.READY + else: + self._state = DataSourceStatus.PROCESSING def _repr_html_(self): import html