Skip to content

Commit

Permalink
still trying
Browse files Browse the repository at this point in the history
  • Loading branch information
uchchwhash committed Apr 18, 2019
1 parent 39e451a commit a876901
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion datacube/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from datetime import datetime
from pathlib import Path
from uuid import UUID
import yaml
import zlib

from affine import Affine
from typing import Optional, List, Mapping, Any, Dict, Tuple, Iterator
Expand All @@ -35,6 +37,7 @@ class Dataset(object):
:param metadata_doc: the document (typically a parsed json/yaml)
:param uris: All active uris for the dataset
"""
# pylint: disable=too-many-public-methods

def __init__(self,
type_: 'DatasetType',
Expand All @@ -51,7 +54,8 @@ def __init__(self,

#: The document describing the dataset as a dictionary. It is often serialised as YAML on disk
#: or inside a NetCDF file, and as JSON-B inside the database index.
self.metadata_doc = metadata_doc
self._metadata_doc = None
self._metadata_doc_compressed = zlib.compress(yaml.dump(metadata_doc).encode('utf-8'))

if local_uri:
warnings.warn(
Expand All @@ -78,6 +82,18 @@ def __init__(self,
# When the dataset was archived. Null it not archived.
self.archived_time = archived_time

@property
def metadata_doc(self):
if self._metadata_doc is None:
self._metadata_doc = yaml.load(zlib.decompress(self._metadata_doc_compressed).decode('utf-8'))
del self._metadata_doc_compressed

return self._metadata_doc

@metadata_doc.setter
def metedata_doc(self, value):
self._metadata_doc = value

@property
def metadata_type(self) -> Optional['MetadataType']:
return self.type.metadata_type if self.type else None
Expand Down

0 comments on commit a876901

Please sign in to comment.