This is a specialized version of: How to replace existing Python class methods of (or otherwise extend) RepoSurgeon by means of 'exec' and 'eval'?
How can one add a new function to RepoSurgeon using the exec
facility (i.e. without editing the upstream code) to add a new function, augmenting existing functionality.
Problem: if you are using RepoSurgeon and you call a function from your script or on the command line and the function throws an exception, this will throw off nested function calls.
Example: you want to find all fossils on a branch by branch name in a single function. The following compound command will do the job for a branch named BRANCH
:
@dsc(@min(/BRANCH/)) list
This works fine if BRANCH
exists. But what if it doesn't? In such a case RepoSurgeon will get quite angry with us and throw an exception:
@dsc(@min(/NO_SUCH_BRANCH/)) list
[...]
ValueError: min() arg is an empty sequence
The problem is that this means that your whole lift script will get derailed.
What to do?