Index: twisted/internet/reactors.py =================================================================== RCS file: twisted/internet/reactors.py diff -N twisted/internet/reactors.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ twisted/internet/reactors.py 28 Jul 2003 06:47:43 -0000 @@ -0,0 +1,58 @@ +# Twisted, the Framework of Your Internet +# Copyright (C) 2001-2003 Matthew W. Lefkowitz +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +"""Discovering and using reactors.""" + +reactors = { + 'gtk' : 'twisted.internet.gtkreactor', + 'gtk2' : 'twisted.internet.gtk2reactor', + 'glade' : 'twisted.internet.gladereactor', + 'default' : 'twisted.internet.default', + 'win32' : 'twisted.internet.win32eventreactor', + 'poll' : 'twisted.internet.pollreactor', + 'qt': 'twisted.internet.qtreactor', + 'c' : 'twisted.internet.cReactor', + 'kqueue' : 'twisted.internet.kqreactor' + } + +reactorSynonyms = { + 'gtkreactor' : 'twisted.internet.gtkreactor', + 'gtk2reactor' : 'twisted.internet.gtk2reactor', + 'gladereactor' : 'twisted.internet.gladereactor', + 'win32eventreactor' : 'twisted.internet.win32eventreactor', + 'win' : 'twisted.internet.win32eventreactor', + 'pollreactor' : 'twisted.internet.pollreactor', + 'qtreactor' : 'twisted.internet.qtreactor', + 'cReactor' : 'twisted.internet.cReactor', + 'kqreactor' : 'twisted.internet.kqreactor' + } + +def getReactorNames(): + names = reactors.keys() + names.sort() + return names + +def installReactorByName(name): + module = reactors.get(name) + if not module: + module = reactorSynonyms.get(name) + if name.startswith('java'): + from twisted.internet import javareactor + javareactor.install() + else: + from twisted.python.reflect import namedModule + namedModule(module).install() Index: twisted/python/usage.py =================================================================== RCS file: /cvs/Twisted/twisted/python/usage.py,v retrieving revision 1.45 diff -u -r1.45 usage.py --- twisted/python/usage.py 20 Jul 2003 09:55:01 -0000 1.45 +++ twisted/python/usage.py 28 Jul 2003 06:47:45 -0000 @@ -129,9 +129,8 @@ self._gather_handlers, ] - for (longOpt, shortOpt, docs, settings, synonyms, dispatch)\ - in map( lambda c: c(), collectors): - + for c in collectors: + (longOpt, shortOpt, docs, settings, synonyms, dispatch) = c() self.longOpt.extend(longOpt) self.shortOpt = self.shortOpt + shortOpt self.docs.update(docs) @@ -345,7 +344,7 @@ #docs[name] = string.split(doc, '\n')[0] docs[prettyName] = doc else: - docs[prettyName] = None + docs[prettyName] = self.docs.get(prettyName) synonyms[prettyName] = prettyName Index: twisted/scripts/trial.py =================================================================== RCS file: /cvs/Twisted/twisted/scripts/trial.py,v retrieving revision 1.46 diff -u -r1.46 trial.py --- twisted/scripts/trial.py 19 Jul 2003 21:36:49 -0000 1.46 +++ twisted/scripts/trial.py 28 Jul 2003 06:47:46 -0000 @@ -18,6 +18,7 @@ # FIXME # - Hangs. +from twisted.internet.reactors import getReactorNames, installReactorByName from twisted.python import usage, reflect, failure from twisted.trial import unittest, util, reporter as reps import sys, os, types, inspect @@ -39,7 +40,7 @@ ["recurse", "R", "Search packages recursively"]] optParameters = [["reactor", "r", None, - "The Twisted reactor to install before running the tests (looked up as a module contained in twisted.internet)"], + 'Which reactor to use out of: %s.' % ', '.join(getReactorNames())], ["logfile", "l", "test.log", "log file name"], ["random", "z", None, "Run tests in random order using the specified seed"], @@ -58,10 +59,9 @@ def opt_reactor(self, reactorName): # this must happen before parseArgs does lots of imports - mod = 'twisted.internet.' + reactorName - print "Using %s reactor" % mod - reflect.namedModule(mod).install() - + print "Using %s reactor" % reactorName + installReactorByName(reactorName) + def opt_testmodule(self, file): "Module to find a test case for" # only look at the first two lines of the file. Try to behave as Index: twisted/scripts/twistd.py =================================================================== RCS file: /cvs/Twisted/twisted/scripts/twistd.py,v retrieving revision 1.53 diff -u -r1.53 twistd.py --- twisted/scripts/twistd.py 19 Jul 2003 21:36:49 -0000 1.53 +++ twisted/scripts/twistd.py 28 Jul 2003 06:47:47 -0000 @@ -17,6 +17,7 @@ from __future__ import nested_scopes from twisted import copyright +from twisted.internet.reactors import getReactorNames, installReactorByName from twisted.python import usage, util, runtime from twisted.python import log, logfile @@ -38,19 +39,6 @@ import imp import sys, os, errno -reactorTypes = { - 'gtk': 'twisted.internet.gtkreactor', - 'gtk2': 'twisted.internet.gtk2reactor', - 'glade': 'twisted.internet.gladereactor', - 'default': 'twisted.internet.default', - 'win32': 'twisted.internet.win32eventreactor', - 'win': 'twisted.internet.win32eventreactor', - 'poll': 'twisted.internet.pollreactor', - 'qt': 'twisted.internet.qtreactor', - 'c' : 'twisted.internet.cReactor', - 'kqueue': 'twisted.internet.kqreactor' - } - class ServerOptions(usage.Options): synopsis = "Usage: twistd [options]" @@ -90,7 +78,7 @@ ['chroot', None, None, 'Chroot to a supplied directory before running'], ['reactor', 'r', None, - 'Which reactor to use out of: %s.' % ', '.join(reactorTypes.keys())], + 'Which reactor to use out of: %s.' % ', '.join(getReactorNames())], ['report-profile', None, None, 'E-mail address to use when reporting dynamic execution profiler stats. ' 'This should not be combined with other profiling options. ' @@ -231,11 +219,10 @@ if config['reactor']: if platformType == 'java': - from twisted.internet import javareactor - javareactor.install() + reactorName = 'java' else: - from twisted.python.reflect import namedModule - namedModule(reactorTypes[config['reactor']]).install() + reactorName = config['reactor'] + installReactorByName(reactorName) if platformType != 'posix' or config['debug']: # only posix can fork, and debugging requires nodaemon