Skip to content

Commit

Permalink
log orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Jun 27, 2023
1 parent de867f5 commit 7588434
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions irodsadmin/management/commands/irodsorphans.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def get_orphans(irods, irods_backend, expected, assays):
Return a list of orphans in a given irods session that are not in a given
list of expected collections.
"""
orphans = []
collections = irods.collections.get('/{}/projects'.format(irods.zone))

for collection in irods_backend.get_colls_recursively(collections):
Expand All @@ -141,7 +140,7 @@ def get_orphans(irods, irods_backend, expected, assays):
or is_project(collection)
):
if collection.path not in expected:
orphans.append(collection.path)
log_orphan(collection.path, irods_backend, irods)

for assay in assays:
if not assay.get_plugin():
Expand All @@ -151,37 +150,33 @@ def get_orphans(irods, irods_backend, expected, assays):
irods, irods_backend.get_path(assay)
):
if collection.path not in expected:
orphans.append(collection.path)
return orphans


def get_output(orphans, irods_backend, irods):
lines = []
for orphan in orphans:
stats = irods_backend.get_object_stats(irods, orphan)
m = re.search(r'/projects/([^/]{2})/(\1[^/]+)', orphan)
if m:
uuid = m.group(2)
try:
project = Project.objects.get(sodar_uuid=uuid)
title = project.full_title
except Project.DoesNotExist:
title = '<DELETED>'
else:
uuid = '<ERROR>'
title = '<ERROR>'
lines.append(
';'.join(
[
uuid,
title,
orphan,
str(stats['file_count']),
filesizeformat(stats['total_size']).replace(u'\xa0', ' '),
]
)
log_orphan(collection.path, irods_backend, irods)


def log_orphan(orphan, irods_backend, irods):
stats = irods_backend.get_object_stats(irods, orphan)
m = re.search(r'/projects/([^/]{2})/(\1[^/]+)', orphan)
if m:
uuid = m.group(2)
try:
project = Project.objects.get(sodar_uuid=uuid)
title = project.full_title
except Project.DoesNotExist:
title = '<DELETED>'
else:
uuid = '<ERROR>'
title = '<ERROR>'
logger.debug(
';'.join(
[
uuid,
title,
orphan,
str(stats['file_count']),
filesizeformat(stats['total_size']).replace(u'\xa0', ' '),
]
)
return lines
)


class Command(BaseCommand):
Expand All @@ -201,7 +196,4 @@ def handle(self, *args, **options):
*get_assay_subcollections(studies, irods_backend),
)
with irods_backend.get_session() as irods:
orphans = get_orphans(irods, irods_backend, expected, assays)
output = get_output(orphans, irods_backend, irods)
if output:
self.stdout.write('\n'.join(output))
get_orphans(irods, irods_backend, expected, assays)

0 comments on commit 7588434

Please sign in to comment.