Unable to get the rule output
Hi, I am calling a rule for a data object in the EUDAT project.
I'm following the metadata rule example here.
Here's my rule from command line:
irule \
"{EUDATCreatePID(*parent_pid, *path, *ror, *fio, *fixed, *newPID)}" \
"*parent_pid=%*path=ABSOLUTE_IPATH%*ror=%*fio=%*fixed=true" \
"*newPID" #output
It gives you a PID in output in the form *newPID = SOMEPID.
Now the point is that I can call the rule and see the PID created on server side, but on the python client side there is no output to handle.
Specifically I have been looking again the example here. But in my case out_array.MsParam_PI is an empty list:
# python rule output pretty printed
object: <irods.message.MsParamArray object at 0x7efe6ea5db38>
instance(MsParamArray):
MsParam_PI: [],
_creation_counter: 168,
_name: 'MsParamArray_PI',
_ordered_properties: [
(
'paramLen',
instance(IntegerProperty):
_creation_counter: 164,
name: 'paramLen'
),
(
'oprType',
instance(IntegerProperty):
_creation_counter: 165,
name: 'oprType'
),
(
'MsParam_PI',
instance(ArrayProperty):
_creation_counter: 167,
name: 'MsParam_PI',
prop: instance(SubmessageProperty):
_creation_counter: 166,
message_cls: <class 'irods.message.MsParam'>,
name: 'MsParam_PI'
),
],
_values: {
'MsParam_PI': [],
'oprType': 0,
'paramLen': 0,
},
oprType: 0,
paramLen: 0
Could someone point me in the right direction? Thank you!
Not sure... can you write the PID to stdout - and get that in the rule output?
Adding writeLine("stdout", *newPID); to the rule content?
I've found my problem, due to not much experience with rules.
I was using the python function like this:
myrule = Rule(self.prc, body=rule_body, params=inputs, output='newPID')
where I expected I could use in the output the variable name to be printed.
Instead it works if I do
myrule = Rule(self.prc, body=rule_body, params=inputs, output='ruleExecOut')
and also add writeLine("stdout", *newPID); at the end of the rule.
My question, hope it's not too dummy: Is this the only way to get the variables in output in Python?
Can't I access to the dictionary of variables at the end of the rule execution?
Why do I get the variable printed in the rule execution from the icommands without the writeLine?
I'm not sure I exactly follow.
the only way to get the variables in output in Python?
I don't think there is a way to get Python dicts back from the rule engine framework. I'm not entirely sure on that, but I cannot remember seeing anyone passing data structures around, rather than strings.
Why do I get the variable printed in the rule execution from the icommands without the writeLine?
With the similar/exact rule run via irule... e.g. irule -F rulefile.r you should not see any output unless you have written things to stdout. Can you share a counterexample?
Sorry if I didn't make my self clear, probably I might be expecting something that it's not there. I'll try a last time :)
Reading the help from the irule command line:
The inputFile should contain 3 lines of non-comments:
1) The first line specifies the rule.
2) The second line specifies the input arguments as label=value pairs separated by %
3) The third line contains output parameters as labels separated by %.
I tested something like this:
irule \
'writeLine("stdout", "");' \
'*some_string="hello"' \
'*some_string'
# this will output in the terminal:
*some_string = "hello"
So even if I printed nothing (an empty line I guess) since in the third line I am using as output the variable some_string I get that as output of the rule execution in my terminal.
My question would be how to access variables in output in Python in the same way, without relying on ruleExecOut to print and get the buffer.
This is because the "buffer way" of getting the output also add some extra chars (spaces and more many \x00) that I have to remove after decoding with:
buf = re.sub(r'\s+', '', buf)
buf = re.sub(r'\\x00', '', buf)
If there's no alternatives I'd still be quite happy since the mechanism works.
Closing. We have examples of getting rule output from the server.