Awasu » Writing Awasu extensions: Integrating with Awasu
Monday 6th April 2015 10:00 AM []

In the first part of this tutorial, we wrote a stand-alone script that generated an RSS feed based upon the files it found in a directory. We'll now convert this script into a channel plugin that Awasu can run.

Defining the plugin's parameters

We would like the directory to be monitored to be configurable by the user, so we need to set up a .PLUGIN file that defines the plugin's parameters:

[ChannelParameterDefinition-1]
Name = Directory to monitor
Type = string
Description = The directory containing the files you want to monitor.
IsRequired = 1

This is a simple INI file [1]This file must have the same base name as the plugin script, but with a .PLUGIN extension. that contains one ChannelParameterDefinition section for each parameter the plugin has.

If you are running Awasu 3.0.2 or later, you can set the parameter type to "dir", and the user will be able to configure the directory using a picker dialog, instead of having to type it in as a string.


How Awasu invokes the plugin channel

When Awasu updates the plugin channel, it runs the script with a single argument, the path to an INI file that contains information the plugin will need to run, in particular, the configuration parameters we defined above:

[ChannelParameters]
Directory to monitor = ...

Since this is just a regular INI file, scripts can use the normal WIN32 calls to retrieve the information, but since there are some subtleties in how Awasu passes information through in these INI files, awasu_tools provides a class that takes care of everything for you:

from awasu_tools.config import ConfigFile

# get our parameters 
invocation_config = ConfigFile( sys.argv[1] )
dir_to_monitor = invocation_config.get_string( "ChannelParameters" , "Directory to monitor" )

Instead of having a hard-coded directory path, we now instantiate a ConfigFile object using the INI file Awasu passes us (via sys.argv[1]), then retrieve the directory the user wants to monitor from that.

And we're done, this plugin channel can now be used in Awasu. It really is that easy!

Download the source code here.



   [ + ]

1. This file must have the same base name as the plugin script, but with a .PLUGIN extension.
Have your say