本文整理汇总了Python中twisted.application.service.IServiceMaker方法的典型用法代码示例。如果您正苦于以下问题:Python service.IServiceMaker方法的具体用法?Python service.IServiceMaker怎么用?Python service.IServiceMaker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.application.service
的用法示例。
在下文中一共展示了service.IServiceMaker方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def makeService(self, options):
"""Override IServiceMaker.makeService."""
factory = bashplex.DelimitedBashReceiverFactory()
factory.ping_interval = int(options['ping-interval'])
factory.ping_timeout = int(options['ping-timeout'])
factory.startup_commands = filter_bash(
'/usr/share/epoptes/client-functions')
if config.system['ENCRYPTION']:
client_service = internet.SSLServer(
int(config.system['PORT']), factory, ServerContextFactory())
else:
client_service = internet.TCPServer(
int(config.system['PORT']), factory)
gid = grp.getgrnam(config.system['SOCKET_GROUP'])[2]
if not os.path.isdir(config.system['DIR']):
# TODO: for some reason this does 0750 instead
os.makedirs(config.system['DIR'], 0o2770)
os.chmod(config.system['DIR'], 0o2770)
os.chown(config.system['DIR'], -1, gid)
gui_service = internet.UNIXServer(
"%s/epoptes.socket" % config.system['DIR'],
guiplex.GUIFactory())
top_service = service.MultiService()
top_service.addService(client_service)
top_service.addService(gui_service)
return top_service
示例2: createOrGetApplication
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def createOrGetApplication(self):
"""
Create or load an Application based on the parameters found in the
given L{ServerOptions} instance.
If a subcommand was used, the L{service.IServiceMaker} that it
represents will be used to construct a service to be added to
a newly-created Application.
Otherwise, an application will be loaded based on parameters in
the config.
"""
if self.config.subCommand:
# If a subcommand was given, it's our responsibility to create
# the application, instead of load it from a file.
# loadedPlugins is set up by the ServerOptions.subCommands
# property, which is iterated somewhere in the bowels of
# usage.Options.
plg = self.config.loadedPlugins[self.config.subCommand]
ser = plg.makeService(self.config.subOptions)
application = service.Application(plg.tapname)
ser.setServiceParent(application)
else:
passphrase = getPassphrase(self.config['encrypted'])
application = getApplication(self.config, passphrase)
return application
示例3: subCommands
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def subCommands(self):
plugins = self._getPlugins(service.IServiceMaker)
self.loadedPlugins = {}
for plug in sorted(plugins, key=attrgetter('tapname')):
self.loadedPlugins[plug.tapname] = plug
yield (plug.tapname,
None,
# Avoid resolving the options attribute right away, in case
# it's a property with a non-trivial getter (eg, one which
# imports modules).
lambda plug=plug: plug.options(),
plug.description)
示例4: test_subCommands
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def test_subCommands(self):
"""
subCommands is built from IServiceMaker plugins, and is sorted
alphabetically.
"""
class FakePlugin(object):
def __init__(self, name):
self.tapname = name
self._options = 'options for ' + name
self.description = 'description of ' + name
def options(self):
return self._options
apple = FakePlugin('apple')
banana = FakePlugin('banana')
coconut = FakePlugin('coconut')
donut = FakePlugin('donut')
def getPlugins(interface):
self.assertEqual(interface, IServiceMaker)
yield coconut
yield banana
yield donut
yield apple
config = twistd.ServerOptions()
self.assertEqual(config._getPlugins, plugin.getPlugins)
config._getPlugins = getPlugins
# "subCommands is a list of 4-tuples of (command name, command
# shortcut, parser class, documentation)."
subCommands = config.subCommands
expectedOrder = [apple, banana, coconut, donut]
for subCommand, expectedCommand in zip(subCommands, expectedOrder):
name, shortcut, parserClass, documentation = subCommand
self.assertEqual(name, expectedCommand.tapname)
self.assertIsNone(shortcut)
self.assertEqual(parserClass(), expectedCommand._options),
self.assertEqual(documentation, expectedCommand.description)
示例5: __init__
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def __init__(self, className, *args, **kwargs):
"""
@param className: The fully qualified name of the
L{IServiceMaker}-providing class to instantiate.
@type className: L{str}
@param args: Sequential arguments to pass to the class's constructor.
@type args: arguments L{list}
@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
示例6: subCommands
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def subCommands(self):
from twisted import plugin
plugins = plugin.getPlugins(service.IServiceMaker)
self.loadedPlugins = {}
for plug in plugins:
self.loadedPlugins[plug.tapname] = plug
yield (plug.tapname, None, lambda: plug.options(), plug.description)
示例7: loadPlugins
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def loadPlugins(debug = None, progress = None):
tapLookup = {}
plugins = plugin.getPlugins(IServiceMaker)
for plug in plugins:
tapLookup[plug.tapname] = plug
return tapLookup
示例8: init
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IServiceMaker [as 别名]
def init(self, tapLookup):
sc = []
for (name, module) in tapLookup.iteritems():
if IServiceMaker.providedBy(module):
sc.append((
name, None, lambda m=module: m.options(), module.description))
else:
sc.append((
name, None, lambda obj=module: obj.load().Options(),
getattr(module, 'description', '')))
sc.sort()
self.subCommands = sc