Skip to content

Commit

Permalink
Merge pull request #189 from kjsanger/chore/logging-tweaks
Browse files Browse the repository at this point in the history
Adjust the levels and content of logging messages
  • Loading branch information
kjsanger authored Jun 13, 2024
2 parents 608996a + 8c266ba commit a1450d2
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/partisan/irods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2020, 2021, 2022, 2023 Genome Research Ltd. All rights
# reserved.
# Copyright © 2020, 2021, 2022, 2023, 2024 Genome Research Ltd. All
# rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -28,7 +28,7 @@
from abc import abstractmethod
from collections import defaultdict
from contextlib import contextmanager
from datetime import datetime
from datetime import datetime, timezone
from enum import Enum, unique
from functools import total_ordering, wraps
from os import PathLike
Expand Down Expand Up @@ -1561,26 +1561,34 @@ def supersede_metadata(
Returns: Tuple[int, int]
"""
if history_date is None:
history_date = datetime.utcnow()
history_date = datetime.now(timezone.utc)

current = self.metadata()
log.info("Superseding AVUs", path=self, current=current, new=avus)

rem_attrs = set(map(lambda avu: avu.attribute, avus))
to_remove = set(filter(lambda a: a.attribute in rem_attrs, current))
rem_attrs = {avu.attribute for avu in avus}
to_remove = {a for a in current if a.attribute in rem_attrs}

# If the argument AVUs have some AVUs to remove amongst them, we don't want
# to remove them from the item, just to add them back.
to_remove.difference_update(avus)
to_remove = sorted(to_remove)
to_add = sorted(set(avus).difference(current))
log.debug(
"Preparing AVUs",
path=self,
current=current,
new=[*avus],
add=to_add,
rem=to_remove,
)

if to_remove:
log.info("Removing AVUs", path=self, avus=to_remove)
item = self._to_dict()
item[Baton.AVUS] = to_remove
with client(self.pool) as c:
c.remove_metadata(item, timeout=timeout, tries=tries)

to_add = sorted(set(avus).difference(current))
if history:
hist = []
for avus in AVU.collate(*to_remove).values():
Expand Down Expand Up @@ -1614,15 +1622,10 @@ class for methods handling recursive operations.
"""
current = self.acl()
to_add = sorted(set(acs).difference(current))
log.debug(
"Adding to ACL",
path=self,
curr=current,
arg=acs,
add=to_add,
)
log.debug("Preparing ACL", path=self, curr=current, arg=acs, add=to_add)

if to_add:
log.info("Adding to ACL", path=self, ac=to_add)
item = self._to_dict()
item[Baton.ACCESS] = to_add
with client(self.pool) as c:
Expand All @@ -1648,15 +1651,10 @@ class for methods handling recursive operations.
"""
current = self.acl()
to_remove = sorted(set(current).intersection(acs))
log.debug(
"Removing from ACL",
path=self,
curr=current,
arg=acs,
rem=to_remove,
)
log.debug("Preparing ACL", path=self, curr=current, arg=acs, rem=to_remove)

if to_remove:
log.info("Removing from ACL", path=self, ac=to_remove)
# In iRODS we "remove" permissions by setting them to NULL
to_null = [AC(ac.user, Permission.NULL, zone=ac.zone) for ac in to_remove]

Expand Down Expand Up @@ -1684,12 +1682,19 @@ class for methods handling recursive operations.
Returns: Tuple[int, int]
"""
current = self.acl()
log.info("Superseding ACL", path=self, current=current, new=acs)

to_remove = sorted(set(current).difference(acs))
to_add = sorted(set(acs).difference(current))
log.debug(
"Preparing ACL",
path=self,
current=current,
new=acs,
add=to_add,
rem=to_remove,
)

if to_remove:
log.info("Removing from ACL", path=self, ac=to_remove)

# In iRODS we "remove" permissions by setting them to NULL
to_null = [AC(ac.user, Permission.NULL, zone=ac.zone) for ac in to_remove]

Expand All @@ -1698,7 +1703,6 @@ class for methods handling recursive operations.
with client(self.pool) as c:
c.set_permission(item, timeout=timeout, tries=tries)

to_add = sorted(set(acs).difference(current))
if to_add:
log.info("Adding to ACL", path=self, ac=to_add)
item = self._to_dict()
Expand Down

0 comments on commit a1450d2

Please sign in to comment.