Skip to content

Commit

Permalink
dobj - implement latest version fetching for data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogopZ committed Oct 18, 2024
1 parent 15945e9 commit f12ec20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
39 changes: 15 additions & 24 deletions icoscp/src/icoscp/cpb/dobj.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
#!/usr/bin/env python
"""
Created on Fri Aug 9 10:40:27 2019
Use an ICOS digital object id (persistent identification url)
to load a binary representation of the data object.
"""

__author__ = ['Claudio D\'Onofrio']
__credits__ = 'ICOS Carbon Portal'
__license__ = 'GPL-3.0'
__version__ = '0.1.8'
__maintainer__ = 'ICOS Carbon Portal, elaborated products team'
__email__ = ['[email protected]', '[email protected]']
__status__ = 'stable'
__date__ = '2023-02-27'

import os
# Standard library imports.
from typing import Optional
from warnings import warn
import requests
import os
import struct

# Related third party imports.
import pandas as pd
import requests

# Local application/library specific imports.
from icoscp import __version__ as release_version
from icoscp import cpauth
from icoscp.cpb import dtype
from icoscp.cpb import metadata
import icoscp.const as CPC
from json.decoder import JSONDecodeError


class Dobj():
Expand All @@ -39,7 +27,7 @@ def __init__(self, digitalObject=None):
self._dobj = None # contains the pid
self._colSelected = None # 'none' -> ALL columns are returned
self._endian = 'big' # default "big endian conversion
self._dtconvert = True # convert Unixtimstamp to datetime object
self._dtconvert = True # convert Unix timestamp to datetime object
self._meta = None # contains metadata about dobj
self._variables = None # contains a list of variables, former info2
self._colSchema = None # format of columns (read struct bin data)
Expand Down Expand Up @@ -95,7 +83,12 @@ def next(self):
if self.valid and 'nextVersion' in self.meta.keys():
nextversion = self.meta['nextVersion']
return nextversion
#-----------
@property
def latest(self) -> Optional[str]:
latest_version = self.meta['latestVersion'] \
if self.valid and 'latestVersion' in self.meta.keys() else None
return latest_version

@property
def valid(self):
return self._dobjValid
Expand Down Expand Up @@ -273,11 +266,9 @@ def __set_meta(self):
self.meta
self.variables
'''

# get all the meta data and check..
self._meta = metadata.get(self.dobj)

if not self._meta:
if not self._meta:
return False
else:
# set conveniance excerpts from meta
Expand Down
4 changes: 4 additions & 0 deletions icoscp/src/icoscp/dobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def previous(self) -> URI | list[URI] | None:
def next(self) -> URI | list[URI] | None:
return self.metadata.nextVersion

@property
def latest(self) -> URI | list[URI]:
return self.metadata.latestVersion

@property
def colNames(self) -> list[str] | None:
specific_info = self.metadata.specificInfo
Expand Down

0 comments on commit f12ec20

Please sign in to comment.