def list_datasets_per_rse(rse, filters=None, limit=None, session=None):
"""
List datasets at a RSE.
:param rse: the rse name.
:param filters: dictionary of attributes by which the results should be filtered.
:param limit: limit number.
:param session: Database session to use.
:returns: A list of dict dataset replicas
"""
query = session.query(models.CollectionReplica.scope,
models.CollectionReplica.name,
models.RSE.rse,
models.CollectionReplica.bytes,
models.CollectionReplica.length,
models.CollectionReplica.available_bytes,
models.CollectionReplica.available_replicas_cnt.label("available_length"),
models.CollectionReplica.state,
models.CollectionReplica.created_at,
models.CollectionReplica.updated_at,
models.CollectionReplica.accessed_at)\
.filter_by(did_type=DIDType.DATASET)\
.filter(models.CollectionReplica.rse_id == models.RSE.id)\
.filter(models.RSE.rse == rse)\
.filter(models.RSE.deleted == false())
for (k, v) in filters and filters.items() or []:
if k == 'name' or k == 'scope':
if '*' in v or '%' in v:
if session.bind.dialect.name == 'postgresql': # PostgreSQL escapes automatically
query = query.filter(getattr(models.CollectionReplica, k).like(v.replace('*', '%')))
else:
query = query.filter(getattr(models.CollectionReplica, k).like(v.replace('*', '%'), escape='\\'))
else:
query = query.filter(getattr(models.CollectionReplica, k) == v)
# hints ?
elif k == 'created_before':
created_before = str_to_date(v)
query = query.filter(models.CollectionReplica.created_at <= created_before)
elif k == 'created_after':
created_after = str_to_date(v)
query = query.filter(models.CollectionReplica.created_at >= created_after)
else:
query = query.filter(getattr(models.CollectionReplica, k) == v)
if limit:
query = query.limit(limit)
for row in query:
yield row._asdict()
评论列表
文章目录