Mustafa,
you are correct, i often forget that 3.6 has format strings and is a reasonable if not happy medium between Python's comfortable present and glorious future! : )
I was able to achieve, I think, what you were after. Here is my /etc/irods/core.py :
import session_vars
def pep_api_mod_avu_metadata_post(rule_args, callback, rei):
user_name = str(session_vars.get_map(rei)["client_user"]["user_name"])
items = dict(rule_args[2].items())
obj_path = str(items["arg2"])
obj_type = items["arg1"]
metadata_operation = items["arg0"]
metadata_attribute = items["arg3"]
metadata_value = str(items["arg4"])
metadata_unit = str(items.get("arg5"))
if metadata_attribute.startswith("rules::"):
if metadata_operation in ("rm", "rmw") and user_name not in ("rods", "operator"):
# original code:
# error_code_with_message(irods_errors.USER_NOT_ALLOWED_TO_EXEC_CMD,
# "ADMIN METADATA cannot be removed or altered!", callback)
callback.writeLine("serverLog","DEBUG - preventing rm,rmw by other than rodsadmin.")
return;
else:
if obj_type == "-d" and metadata_attribute == "rules::soft_delete":
callback.delayExec(f"<INST_NAME>irods_rule_engine_plugin-python-instance</INST_NAME><PLUSET>{metadata_value}{metadata_unit}</PLUSET>",
f"callback.change_permission_as_admin({obj_path!r},{user_name!r})",
"")
import irods.test.helpers
from irods.access import iRODSAccess
def SWITCH():
return irods.test.helpers.make_session()
def change_permission_as_admin(rule_args, callback, rei):
(obj_path, user_name) = rule_args
new_permission = iRODSAccess('own', obj_path, user_name)
with SWITCH() as session:
session.acls.set(new_permission, admin = True)
If I then iadmin set -M -d /tempZone/home/alice/adat rules::soft_delete 10 s
then I will see in iqstat:
id name
10030 callback.change_permission_as_admin('/tempZone/home/alice/adat','rods')