Skip to content

Commit

Permalink
get_vault_data_packages: extract to common_queries
Browse files Browse the repository at this point in the history
So that it can be re-used in other tools
  • Loading branch information
stsnel committed Feb 14, 2025
1 parent 802f4d6 commit 825b7fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
16 changes: 16 additions & 0 deletions yclienttools/common_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,19 @@ def group_exists(session, groupname):
'''Returns a boolean value that indicates whether a user group with the provided name exists.'''
return (len(list(session.query(UserGroup.name).filter(
UserGroup.name == groupname).get_results())) > 0)


def get_vault_data_packages(session):
"""Returns a list of collections of all data packages in the vault space."""
vault_collections = session.query(Collection.name).filter(
Collection.parent_name == f'/{session.zone}/home').filter(
Like(Collection.name, f'/{session.zone}/home/vault-%')).get_results()

datapackage_collections = []
for vault_collection in [coll[Collection.name] for coll in vault_collections]:
these_datapackage_collections = session.query(Collection.name).filter(
Collection.parent_name == vault_collection).filter(
Like(Collection.name, f"/{session.zone}/home/vault-%/%[%]")).get_results()
datapackage_collections.extend([coll[Collection.name] for coll in these_datapackage_collections])

return datapackage_collections
22 changes: 3 additions & 19 deletions yclienttools/reportdatapackagestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import sys
import time

from irods.column import Like
from irods.models import Collection, CollectionMeta
from yclienttools import common_args, common_config
from yclienttools import common_args, common_config, common_queries
from yclienttools import session as s

from email.mime.multipart import MIMEMultipart
Expand Down Expand Up @@ -96,7 +95,8 @@ def time_ago_to_readable(days, hours):

def report_data_package_status(args, session):
report = ""
for data_package in get_data_packages(session):
data_packages = common_queries.get_vault_data_packages(session)
for data_package in data_packages:

status = get_vault_status(session, data_package)
if args.pending and status in [
Expand Down Expand Up @@ -129,22 +129,6 @@ def report_data_package_status(args, session):
report)


def get_data_packages(session):
"""Returns a list of collections of all data packages."""
vault_collections = session.query(Collection.name).filter(
Collection.parent_name == f'/{session.zone}/home').filter(
Like(Collection.name, f'/{session.zone}/home/vault-%')).get_results()

datapackage_collections = []
for vault_collection in [coll[Collection.name] for coll in vault_collections]:
these_datapackage_collections = session.query(Collection.name).filter(
Collection.parent_name == vault_collection).filter(
Like(Collection.name, f"/{session.zone}/home/vault-%/%[%]")).get_results()
datapackage_collections.extend([coll[Collection.name] for coll in these_datapackage_collections])

return datapackage_collections


def get_current_timestamp():
return time.time()

Expand Down

0 comments on commit 825b7fe

Please # to comment.