-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved Example #19
base: v3.6-dev
Are you sure you want to change the base?
Improved Example #19
Conversation
Improved the custom_m_codes.py script to include handling parameters as well as Meta Variables.
Thanks! I've adopted that change from Yet I'm not quite happy with the way you evaluate expressions. Instead of checking if the string param starts with |
That does sound like a better solution. Unfortunately I modified my code on my test system and is_expression does not seem to be getting set. Here is debug output:
Looking in code_parameter.py I am not sure if this would work correctly:
pretty sure it should be:
even then I would think the parameter would be set in the JSON. |
Good catch ! On a side note about your initial commit, you can remove the parenthesis around the if expressions, they are useless in python. |
Switched from using startswith() for checking if a S parameter is an expression to using is_expression. Also made formatting changes.
I switched: I also switched my example to use is_expression and made some formatting changes. |
@chrishamm Is there anything else you need to get this code merged? |
Please look at my comments above |
Sorry. I did not see the part about the sanity checks before subprocess.run(). I will add a check to make sure that it is passing specifically an integer. Are there any other checks you would like me to add? |
command_connection.connect() | ||
|
||
try: | ||
res = command_connection.perform_command(evaluate_expression( channel, meta_var )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't have to use perform_command
. You should rather use command_connection.evaluate_expression
directly as evaluate_expression
is a method of BaseCommandConnection
. See https://github.com/vicimikec/dsf-python/blob/main/src/dsf/connections/base_command_connection.py#L56
It may also be possible to pass the intercept connection as parameter of eval_expr
function so you won't have to open another connection to send that command.
finally: | ||
command_connection.close() | ||
|
||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result
will be undefined if there is an exception triggered above. You have to define result = 1
before the try...finally
clause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Problem there is that 1 is a valid return value even though the function failed. Would it be better to set this to False or None? I will be honest Python is not my strongest programming language so I am not sure what the convention of indicating a failure in these instances is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set it to None
. If something fails, an exception will be thrown anyway
Sorry, I didn't see I needed to "submit" these review changes ... |
Improved the custom_m_codes.py script to include handling a S parameter. This includes evaluating a Meta Variable passed in the S parameter.
Also fixed the call to resolve_code on line 56. It was being passed MessageType.Warn. It should be MessageType.Warning.