>>>>> "Adriano" == Adriano Marques <py.adriano(a)gmail.com> writes:
Adriano> I have a twisted application, which formely was run with command
Adriano> line arguments which were used during runtime, eg: I was passing
Adriano> the path to the log file as argument. Then, I decided to make my
Adriano> app run through twistd as a tac file but then I'm not able to pass
Adriano> command line arguments anymore. Is there any way to overcome this
I also ran into this, and asked for some way to pass args but got told
(paraphrasing, from memory) that that's not the way to do it...
The way to do it seems to be to convert your application to be a Twisted
plugin. It's not too hard. Then you make sure there's a twisted/plugins
dir accessible from your path (with no __init__.py files in/under it). Then
twistd will find your plugin (just run twistd with no options and you
should see your plugin name listed at the bottom among the commands). Then
you can add options processing by subclassing the Options class in
Sorry to be so terse - no time. The above does work though, and seems to be
the Twisted way. Rough (untested) guideline code below.
from zope.interface import implements
from twisted.python import usage
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
from ???? import myservice
optFlags = [
['verbose', None, 'If True, be verbose.'],
optParameters = [
['port', 'p', '0', 'The port number to listen on.'],
# The tapname will appear in the output of twistd when run with no args.
# Use twistd -n my-plugin-name
# to invoke it.
tapname = 'my-plugin-name'
description = 'My snazzy service.'
options = Options
def makeService(self, options):
serviceMaker = MyServiceMaker()