本文整理汇总了Python中plugin_manager.PluginManager.activate_plugins方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.activate_plugins方法的具体用法?Python PluginManager.activate_plugins怎么用?Python PluginManager.activate_plugins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plugin_manager.PluginManager
的用法示例。
在下文中一共展示了PluginManager.activate_plugins方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StarryPyServerFactory
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_plugins [as 别名]
class StarryPyServerFactory(ServerFactory):
"""
Factory which creates `StarryPyServerProtocol` instances.
"""
protocol = StarryPyServerProtocol
def __init__(self):
"""
Initializes persistent objects and prepares a list of connected
protocols.
"""
self.config = ConfigurationManager()
self.protocol.factory = self
self.protocols = {}
self.plugin_manager = PluginManager()
self.plugin_manager.activate_plugins()
def stopFactory(self):
"""
Called when the factory is stopped. Saves the configuration.
:return: None
"""
self.config.save()
def broadcast(self, text, channel=1, world='', name=''):
"""
Convenience method to send a broadcasted message to all clients on the
server.
:param text: Message text
:param channel: Channel to broadcast on. 0 is global, 1 is planet.
:param world: World
:param name: The name to prepend before the message, format is <name>
:return: None
"""
for p in self.protocols.itervalues():
try:
p.send_chat_message(text)
except:
logger.exception("Exception in broadcast.", exc_info=True)
def buildProtocol(self, address):
"""
Builds the protocol to a given address.
:rtype : Protocol
"""
logger.debug("Building protocol to address %s", address)
p = ServerFactory.buildProtocol(self, address)
return p
示例2: StarryPyServerFactory
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_plugins [as 别名]
class StarryPyServerFactory(ServerFactory):
"""
Factory which creates `StarryPyServerProtocol` instances.
"""
protocol = StarryPyServerProtocol
def __init__(self):
"""
Initializes persistent objects and prepares a list of connected
protocols.
"""
self.config = ConfigurationManager()
self.protocol.factory = self
self.protocols = {}
self.plugin_manager = PluginManager(factory=self)
self.plugin_manager.activate_plugins()
self.reaper = LoopingCall(self.reap_dead_protocols)
self.reaper.start(self.config.reap_time)
def stopFactory(self):
"""
Called when the factory is stopped. Saves the configuration.
:return: None
"""
self.config.save()
def broadcast(self, text, channel=1, world='', name=''):
"""
Convenience method to send a broadcasted message to all clients on the
server.
:param text: Message text
:param channel: Channel to broadcast on. 0 is global, 1 is planet.
:param world: World
:param name: The name to prepend before the message, format is <name>
:return: None
"""
for p in self.protocols.itervalues():
try:
p.send_chat_message(text)
except:
logger.exception("Exception in broadcast.", exc_info=True)
def buildProtocol(self, address):
"""
Builds the protocol to a given address.
:rtype : Protocol
"""
logger.debug("Building protocol to address %s", address)
p = ServerFactory.buildProtocol(self, address)
return p
def reap_dead_protocols(self):
logger.debug("Reaping dead connections.")
count = 0
start_time = datetime.datetime.now()
for protocol in self.protocols.itervalues():
if (
protocol.packet_stream.last_received_timestamp - start_time).total_seconds() > self.config.reap_time:
protocol.connectionLost()
count += 1
continue
if protocol.client_protocol is not None and (
protocol.client_protocol.packet_stream.last_received_timestamp - start_time).total_seconds() > self.config.reap_time:
protocol.connectionLost()
count += 1
if count == 1:
logger.info("1 connection reaped.")
elif count > 1:
logger.info("%d connections reaped.")
else:
logger.debug("No connections reaped.")