Skip to content

Commit

Permalink
Utils: move kvpair helper function to msi module
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Oct 18, 2023
1 parent d9f113a commit 5c16d8e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
16 changes: 8 additions & 8 deletions unit-tests/test_util_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

sys.path.append('..')

from util import misc
from util.misc import human_readable_size


class UtilMiscTest(TestCase):

def test_dataset_parse_id(self):
output = misc.human_readable_size(0)
output = human_readable_size(0)
self.assertEquals(output, "0 B")
output = misc.human_readable_size(1024)
output = human_readable_size(1024)
self.assertEquals(output, "1.0 KiB")
output = misc.human_readable_size(1048576)
output = human_readable_size(1048576)
self.assertEquals(output, "1.0 MiB")
output = misc.human_readable_size(26843550000)
output = human_readable_size(26843550000)
self.assertEquals(output, "25.0 GiB")
output = misc.human_readable_size(989560500000000)
output = human_readable_size(989560500000000)
self.assertEquals(output, "900.0 TiB")
output = misc.human_readable_size(112590000000000000)
output = human_readable_size(112590000000000000)
self.assertEquals(output, "100.0 PiB")
output = misc.human_readable_size(3931462330709348188)
output = human_readable_size(3931462330709348188)
self.assertEquals(output, "3.41 EiB")
11 changes: 1 addition & 10 deletions util/misc.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# -*- coding: utf-8 -*-
"""Miscellaneous functions for interacting with iRODS."""
"""Miscellaneous util functions."""

__copyright__ = 'Copyright (c) 2019-2023, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import math

import irods_types

import msi


def kvpair(ctx, k, v):
"""Create a keyvalpair object, needed by certain msis."""
return msi.string_2_key_val_pair(ctx, '{}={}'.format(k, v), irods_types.BytesBuf())['arguments'][1]


def human_readable_size(size_bytes):
if size_bytes == 0:
Expand Down
9 changes: 8 additions & 1 deletion util/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
all errors to unambiguous Python exceptions.
"""

__copyright__ = 'Copyright (c) 2019-2022, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2023, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import irods_types

import error


Expand Down Expand Up @@ -134,3 +136,8 @@ def _make_exception(name, message):
rmw_avu, RmwAvuError = make('_rmw_avu', 'Could not remove metadata to object')

sudo_obj_acl_set, SudoObjAclSetError = make('SudoObjAclSet', 'Could not set ACLs as admin')


def kvpair(ctx, k, v):
"""Create a keyvalpair object, needed by certain msis."""
return string_2_key_val_pair(ctx, '{}={}'.format(k, v), irods_types.BytesBuf())['arguments'][1]
4 changes: 2 additions & 2 deletions vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def api_grant_read_access_research_group(ctx, coll):
if groups.user_role(ctx, 'datamanager-' + category, actor) in ['normal', 'manager']:
# Grant research group read access to vault package.
try:
acl_kv = misc.kvpair(ctx, "actor", actor)
acl_kv = msi.kvpair(ctx, "actor", actor)
msi.sudo_obj_acl_set(ctx, "recursive", "read", research_group_name, coll, acl_kv)
except Exception:
policy_error = policies_datamanager.can_datamanager_acl_set(ctx, coll, actor, research_group_name, "1", "read")
Expand Down Expand Up @@ -798,7 +798,7 @@ def api_revoke_read_access_research_group(ctx, coll):
if groups.user_role(ctx, 'datamanager-' + category, actor) in ['normal', 'manager']:
# Grant research group read access to vault package.
try:
acl_kv = misc.kvpair(ctx, "actor", actor)
acl_kv = msi.kvpair(ctx, "actor", actor)
msi.sudo_obj_acl_set(ctx, "recursive", "null", research_group_name, coll, acl_kv)
except Exception:
policy_error = policies_datamanager.can_datamanager_acl_set(ctx, coll, actor, research_group_name, "1", "read")
Expand Down

0 comments on commit 5c16d8e

Please sign in to comment.