Skip to content

Instantly share code, notes, and snippets.

@cbcunc
Last active January 26, 2024 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbcunc/e7b9680cf6d01f57b99c8c6bd8ce605a to your computer and use it in GitHub Desktop.
Save cbcunc/e7b9680cf6d01f57b99c8c6bd8ce605a to your computer and use it in GitHub Desktop.
import os.path
from genquery import Query, AS_DICT
def testFunc(rule_args, callback, rei):
callback.writeLine("serverLog", "Entering testFunc")
x = rule_args[0]
y = rule_args[1]
callback.writeLine("serverLog", "x = [{}]".format(x))
callback.writeLine("serverLog", "y = [{}]".format(y))
rule_args[1] = "This is new!"
return "Returning from testFunc"
def getQuotaOwner(rule_args, callback, rei):
objPath = rule_args[0]
hsUserName = ""
hsColParts = os.path.normpath(objPath).split(os.path.sep)
callback.writeLine("serverLog", "hsColParts = [{}]".format(hsColParts))
if len(hsColParts) > 7:
# WHAT HYDROSHARE USER OWNS THIS DATA OBJECT?
# This comes from an AVU on the HS resource collection, which will be deleted prior
# to the delayed rule, and thus must be computed and passed to the delay rule via
# the BOOST-constructed rule_args parameter.
# Use the first four subcollection names to form the HS resource collection path.
# Look for the value of the attribute called quotaUserName on the HS resource collection.
hsColPath = os.path.join(os.path.sep, *hsColParts[1:5])
callback.writeLine("serverLog", "hsColPath = [{}]".format(hsColPath))
rows = list(Query(callback,
["META_COLL_ATTR_VALUE",],
"COLL_NAME = '{}' and META_COLL_ATTR_NAME = 'quotaUserName'".format(hsColPath),
AS_DICT, 0, 2))
callback.writeLine("serverLog", "len(rows) = [{}]".format(len(rows)))
if rows:
hsUserName = rows[0]["META_COLL_ATTR_VALUE"]
# rule_args are In/Out variables!!!
rule_args[1] = hsUserName
return
irule -r irods_rule_engine_plugin-irods_rule_language-instance '*whatwewant = "This is y"; *rc = testFunc("This is x", *whatwewant); writeLine("serverLog", *whatwewant)' null ruleExecOut
irule -r irods_rule_engine_plugin-irods_rule_language-instance '*quotaOwner = ""; getQuotaOwner("/hydrotestZone/home/betaDataProxy/ffff6f96cca64204befa58c8177592bb/data/contents/WRC01_6.hobo", *quotaOwner); writeLine("serverLog", *quotaOwner)' null ruleExecOut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment