Question

I am fairly new to Trac plugins and python in general. For most of this day I have been looking for a way to get parameters into a Trac plugin that I am creating, via URL request.

So if I had a plugin on site wikitest, I could access it like this, and also provide an argument:

http://localhost:8080/tracEnvironment/wiki/wikiTest?name=annie

Then my plugin, located on wikitest could get the name provided via URL. Is this possible?

I have found some answers to similar problems, that suggest using a python framework, but I think that my case is different, because I'm dealing with Trac plugin, instead of standalone script.

What would be the best way to get this data to my plugin?

Was it helpful?

Solution

You speak about "your" Trac plugin. So I trust you to know about setting up a Trac development environment. Further on you'll need to know, how to deploy a Trac plugin. If it is rather simple, a one-file plugin might be sufficient. So you could copy in into the /plugins folder and use it right-away, probably needing to restart the web-server first.

Make yourself familiar with the great Trac component architecture. Code for acting on requests should in general make use of the IRequestHandler (from trac.web.api), one of several extension point interfaces. Read existing plugin code at Trac-Hacks.org to understand even better how to use it. Its rather easy to check, if the request coming in is directed at the path defined in your extension

if req.path_info.startswith('wikitest'):
    # Do something useful.

to test the request type and do more

if req.method == 'GET':
    # Handle the request
    if reg.args.get('name'):
        name = req.args['name']
        self.log.debug('Got request for name=%s' % name)

Read more code, discuss in the #trac IRC channel at freenode.net and keep asking as you progress.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top