Skip to content

Commit

Permalink
pyDKB/storages: implement RucioClient.get() method.
Browse files Browse the repository at this point in the history
Original Rucio `Client` does not have `get()` method.
  • Loading branch information
mgolosova committed Jul 10, 2019
1 parent 703e61e commit d0eb05e
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion Utils/Dataflow/pyDKB/storages/atlas/rucio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os

from ..client import Client
from ..exceptions import StorageException
from ..exceptions import (StorageException, NotFound)
from pyDKB.common.misc import (log, logLevel)
from pyDKB.common.misc import try_to_import

Expand Down Expand Up @@ -50,3 +50,61 @@ class RucioClient(Client, ParentClientClass):
def __init__(self, *args, **kwargs):
""" Initialize parent client class. """
ParentClientClass.__init__(self, *args, **kwargs)

def get(self, oid, **kwargs):
""" Get dataset metadata.
Implementation of interface method `Clent.get()`.
:param oid: dataset name
:type oid: str
:param fields: list of requested metadata fields
(None = all metadata)
:type fields: list
:return: dataset metadata
:rtype: dict
"""
scope, name = self._scope_and_name(oid)
try:
result = self.get_metadata(scope=scope, name=name)
except ValueError, err:
raise StorageException("Failed to get metadata from Rucio: %s"
% err)
except RucioException, err:
if 'Data identifier not found' in str(err):
raise NotFound(scope=scope, name=name)
raise StorageException("Failed to get metadata from Rucio: %s"
% err)
if kwargs.get('fields') is not None:
result = {f: result.get(f, None) for f in kwargs['fields']}
return result

def _scope_and_name(self, dsn):
""" Construct normalized scope and dataset name.
As input accepts dataset names in two forms:
* dot-separated string: "<XXX>.<YYY>[.<...>]";
* dot-separated string with prefix: "<scope>:<XXX>.<YYY>[.<...>]".
In first case ID is taken as a canonical dataset name and scope is set
to its first field (or two first fields, if the ID starts with 'user'
or 'group').
In second case prefix is taken as scope, and removed from ID to get the
canonical dataset name.
:param dsn: dataset name
:type dsn: str
:return: scope, datasetname
:rtype: tuple
"""
result = dsn.split(':')
if len(result) < 2:
splitted = dsn.split('.')
if dsn.startswith('user') or dsn.startswith('group'):
scope = '.'.join(splitted[0:2])
else:
scope = splitted[0]
result = (scope, dsn)
return result

0 comments on commit d0eb05e

Please sign in to comment.