Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files

Better plugin-fu.

  • Loading branch information
wsanchez committed Dec 12, 2013
1 parent 19a7f8b commit 58ca0a2aae212073718a2797bf9627b32b7c1794
Showing with 61 additions and 22 deletions.
  1. +12 −0 twext/application/
  2. +49 −22 twisted/plugins/
@@ -289,6 +289,12 @@ class MasterServiceMaker(object):
log = Logger()

def __init__(self):
self.tapname = "master"
self.description = self.__class__.__doc__
self.options = MasterOptions

def makeService(self, options):
service = MasterService()

@@ -516,6 +522,12 @@ class ChildServiceMaker(object):
Child process service maker.

def __init__(self):
self.tapname = "child"
self.description = self.__class__.__doc__
self.options = ChildOptions

def makeService(self, options):
factory = ServerFactory.forProtocol(options["protocol"])
service = ChildService(options["inherited-fd"], factory)
@@ -20,39 +20,66 @@
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker

from twext.application.masterchild import MasterOptions, ChildOptions

@implementer(IPlugin, IServiceMaker)
class ServiceMaker(object):
def __init__(self, name, description, options, serviceMakerClass):
self.tapname = name
self.description = description
self.options = options
self.serviceMakerClass = serviceMakerClass
self._serviceMaker = None
class ServiceMakerWrapper(object):
ServiceMaker that instantiates and wraps a ServiceMaker, given a class name
and arguments.

def __init__(self, className, *args, **kwargs):
@param className: The fully qualified name of the
L{IServiceMaker}-providing class to instiantiate.
@type className: L{str}
def makeService(self, options):
if self._serviceMaker is None:
self._serviceMaker = namedClass(self.serviceMakerClass)()
@param args: Sequential arguments to pass to the class's constructor.
@type args: arguments L{list}
return self._serviceMaker.makeService(options)
@param kwargs: Keyword arguments to pass to the class's constructor.
@type args: arguments L{dict}
self.className = className
self.args = args
self.kwargs = kwargs

def wrappedServiceMaker(self):
if not hasattr(self, "_wrappedServiceMaker"):
makerClass = namedClass(self.className)
maker = makerClass(*self.args, **self.kwargs)
self._wrappedServiceMaker = maker

return self._wrappedServiceMaker

def tapname(self):
return self.wrappedServiceMaker.tapname

def description(self):
return self.wrappedServiceMaker.description

masterServiceMaker = ServiceMaker(
"Master process application container",

def options(self):
return self.wrappedServiceMaker.options

childServiceMaker = ServiceMaker(
"Child process application container",
def makeService(self, options):
return self.wrappedServiceMaker.makeService(options)

masterServiceMaker = ServiceMakerWrapper(

childServiceMaker = ServiceMakerWrapper(

0 comments on commit 58ca0a2

Please sign in to comment.
You can’t perform that action at this time.