Skip to content

Configuration Actions

lead2gold edited this page Jul 10, 2017 · 1 revision

Configuration Actions

These are actions that can be called from the NZBGet configuration page. These allow the users of your script to test functions of it from within NZBGet whenever they wish.

Usage

It's really easy to map an action; below is an example of the option chunk of code that would reside at the top of a NZBGet script. In this example we set up a new button called ConnectionTest. The user will see a button inside NZBGet that reads Check My Connection.

############################################################################
### OPTIONS                                                              ###

#
# To check connection parameters click the button.
# ConnectionTest@Check My Connection
#
#
# ...

Now we just need to map this button to a function; it can be done as follows:

# For all intent and purpose, we'll use a PostProcess Script, but this 
# Configuration action feature works with any type.
from nzbget import PostProcessScript

# Our function definition
class MyScript(PostProcessScript):

    # Your other code exists here

    # Define a function with the button label and action_ in front of it
    # and everything within this function will get called when the user
    # presses the button on the configuration page
    def action_ConnectionTest(self, *args, **kwargs):
        """ I get called whenever someone presses the ConnectionTest button
        """
        # It's that simple...

        # You can still validate the other variables the user has identified
        # here if you want (optional)
        if not self.validate(keys=(
            'Debug',
            'MyOptionA',
            'MyOptionB')):
            # Fail if your options aren't found
            return False

        # Write any tests you want here!

        # When you're done, just return
        return True

The lowercase version of the action command is also valid. Hence, with respect to this example, you'll you'll accomplish the same thing. defining the function def action_connectiontest(self, *args, **kwargs).

To avoid ambiguity, if both function names are defined, the case-sensitive one would over-ride the other.

You can’t perform that action at this time.