Skip to content

Commit 174a9b3

Browse files
committed
pyDKB/storages: implement RucioClient.get() method.
Original Rucio `Client` does not have `get()` method.
1 parent 589ba8b commit 174a9b3

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

  • Utils/Dataflow/pyDKB/storages/atlas

Utils/Dataflow/pyDKB/storages/atlas/rucio.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66

77
from ..client import Client
8-
from ..exceptions import StorageException
8+
from ..exceptions import (StorageException, NotFound)
99
from pyDKB.common.misc import (log, logLevel)
1010
from pyDKB.common.misc import try_to_import
1111

@@ -50,3 +50,61 @@ class RucioClient(Client, ParentClientClass):
5050
def __init__(self, *args, **kwargs):
5151
""" Initialize parent client class. """
5252
ParentClientClass.__init__(self, *args, **kwargs)
53+
54+
def get(self, oid, **kwargs):
55+
""" Get dataset metadata.
56+
57+
Implementation of interface method `Clent.get()`.
58+
59+
:param oid: dataset name
60+
:type oid: str
61+
:param fields: list of requested metadata fields
62+
(None = all metadata)
63+
:type fields: list
64+
65+
:return: dataset metadata
66+
:rtype: dict
67+
"""
68+
scope, name = self._scope_and_name(oid)
69+
try:
70+
result = self.get_metadata(scope=scope, name=name)
71+
except ValueError, err:
72+
raise StorageException("Failed to get metadata from Rucio: %s"
73+
% err)
74+
except RucioException, err:
75+
if 'Data identifier not found' in str(err):
76+
raise NotFound(scope=scope, name=name)
77+
raise StorageException("Failed to get metadata from Rucio: %s"
78+
% err)
79+
if kwargs.get('fields') is not None:
80+
result = {f: result.get(f, None) for f in kwargs['fields']}
81+
return result
82+
83+
def _scope_and_name(self, dsn):
84+
""" Construct normalized scope and dataset name.
85+
86+
As input accepts dataset names in two forms:
87+
* dot-separated string: "<XXX>.<YYY>[.<...>]";
88+
* dot-separated string with prefix: "<scope>:<XXX>.<YYY>[.<...>]".
89+
90+
In first case ID is taken as a canonical dataset name and scope is set
91+
to its first field (or two first fields, if the ID starts with 'user'
92+
or 'group').
93+
In second case prefix is taken as scope, and removed from ID to get the
94+
canonical dataset name.
95+
96+
:param dsn: dataset name
97+
:type dsn: str
98+
99+
:return: scope, datasetname
100+
:rtype: tuple
101+
"""
102+
result = dsn.split(':')
103+
if len(result) < 2:
104+
splitted = dsn.split('.')
105+
if dsn.startswith('user') or dsn.startswith('group'):
106+
scope = '.'.join(splitted[0:2])
107+
else:
108+
scope = splitted[0]
109+
result = (scope, dsn)
110+
return result

0 commit comments

Comments
 (0)