本文整理汇总了Python中plugin_manager.PluginManager.activate_all方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.activate_all方法的具体用法?Python PluginManager.activate_all怎么用?Python PluginManager.activate_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plugin_manager.PluginManager
的用法示例。
在下文中一共展示了PluginManager.activate_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_all [as 别名]
class ServerFactory:
def __init__(self):
try:
self.protocols = []
self.configuration_manager = ConfigurationManager()
self.configuration_manager.load_config(
path / 'config' / 'config.json',
default=True)
self.plugin_manager = PluginManager(self.configuration_manager)
self.plugin_manager.load_from_path(
path / self.configuration_manager.config.plugin_path)
self.plugin_manager.resolve_dependencies()
self.plugin_manager.activate_all()
asyncio.Task(self.plugin_manager.get_overrides())
except Exception as e:
print("Exception encountered during server startup.")
print(e)
loop.stop()
sys.exit()
def remove(self, protocol):
self.protocols.remove(protocol)
def __call__(self, reader, writer):
server = StarryPyServer(reader, writer, factory=self)
self.protocols.append(server)
print(self.protocols)
示例2: __init__
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_all [as 别名]
class ServerFactory:
def __init__(self):
try:
self.protocols = []
self.configuration_manager = ConfigurationManager()
self.configuration_manager.load_config(
path / 'config' / 'config.json',
default=True)
self.plugin_manager = PluginManager(self.configuration_manager,
factory=self)
self.plugin_manager.load_from_path(
path / self.configuration_manager.config.plugin_path)
self.plugin_manager.resolve_dependencies()
self.plugin_manager.activate_all()
asyncio.Task(self.plugin_manager.get_overrides())
except Exception as e:
logger.exception("Error during server startup.", exc_info=True)
loop.stop()
sys.exit()
@asyncio.coroutine
def broadcast(self, messages, *, world="", name="", channel=0,
client_id=0):
for protocol in self.protocols:
try:
yield from protocol.send_message(messages,
world=world,
name=name,
channel=channel,
client_id=client_id)
except ConnectionError:
continue
def remove(self, protocol):
self.protocols.remove(protocol)
def __call__(self, reader, writer):
server = StarryPyServer(reader, writer, factory=self)
self.protocols.append(server)
def kill_all(self):
for protocol in self.protocols:
protocol.die()
示例3: __init__
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_all [as 别名]
class ServerFactory:
def __init__(self):
try:
self.connections = []
self.configuration_manager = ConfigurationManager()
self.configuration_manager.load_config(
path / 'config' / 'config.json',
default=True)
self.plugin_manager = PluginManager(self.configuration_manager,
factory=self)
self.plugin_manager.load_from_path(
path / self.configuration_manager.config.plugin_path)
self.plugin_manager.resolve_dependencies()
self.plugin_manager.activate_all()
asyncio.ensure_future(self.plugin_manager.get_overrides())
except Exception as err:
logger.exception("Error during server startup.", exc_info=True)
loop.stop()
sys.exit()
@asyncio.coroutine
def broadcast(self, messages):
"""
Send a message to all connected clients.
:param messages: Message(s) to be sent.
:return: Null.
"""
for connection in self.connections:
try:
yield from connection.send_message(messages)
except Exception as err:
logger.exception("Error while trying to broadcast.")
logger.exception(err)
continue
def remove(self, connection):
"""
Remove a single connection.
:param connection: Connection to be removed.
:return: Null.
"""
self.connections.remove(connection)
def __call__(self, reader, writer):
"""
Whenever a client connects, ping the server factory to start
handling it.
:param reader: Reader transport socket.
:param writer: Writer transport socket.
:return: Null.
"""
server = StarryPyServer(reader, writer, self.configuration_manager,
factory=self)
self.connections.append(server)
logger.debug("New connection established.")
def kill_all(self):
"""
Drop all connections.
:return: Null.
"""
logger.debug("Dropping all connections.")
for connection in self.connections:
connection.die()
示例4: __init__
# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import activate_all [as 别名]
class TestPluginManager:
def __init__(self):
self.plugin_path = path / 'tests' / 'test_plugins'
self.good_plugin = self.plugin_path / 'test_plugin_2.py'
self.good_plugin_package = self.plugin_path / 'test_plugin_package'
self.bad_plugin = self.plugin_path / 'bad_plugin'
self.bad_path = self.plugin_path / 'bad_path.py'
self.dependent_plugins = self.plugin_path / "dependent_plugins"
self.plugin_manager = PluginManager(None)
self.loop = None
def setup(self):
self.plugin_manager = PluginManager(None)
self.loop = asyncio.new_event_loop()
def test_bad_paths(self):
assert_raises(FileNotFoundError,
self.plugin_manager._load_module, self.bad_path)
def test_load_good_plugins(self):
self.plugin_manager.load_plugin(self.good_plugin)
self.plugin_manager.load_plugin(self.good_plugin_package)
self.plugin_manager.resolve_dependencies()
assert_in("test_plugin_2",
self.plugin_manager.list_plugins().keys())
assert_in("test_plugin_1",
self.plugin_manager.list_plugins().keys())
def test_load_bad_plugin(self):
with assert_raises(SyntaxError):
self.plugin_manager.load_plugin(self.bad_plugin)
self.plugin_manager.resolve_dependencies()
def test_load_plugin_dir(self):
self.plugin_manager.load_from_path(self.plugin_path)
self.plugin_manager.resolve_dependencies()
assert_in("test_plugin_2",
self.plugin_manager.list_plugins())
assert_in("test_plugin_1",
self.plugin_manager.list_plugins())
assert_in("bad_plugin",
self.plugin_manager.failed)
def test_the_do_method(self):
self.plugin_manager.load_plugin(self.good_plugin)
self.plugin_manager.load_plugin(self.good_plugin_package)
self.plugin_manager.resolve_dependencies()
result = self.loop.run_until_complete(
self.plugin_manager.do("chat_sent", b""))
assert_equals(result, True)
def test_dependency_check(self):
with assert_raises(ImportError):
self.plugin_manager.load_plugin(self.dependent_plugins / 'b.py')
self.plugin_manager.resolve_dependencies()
def test_dependency_resolution(self):
self.plugin_manager.load_plugins([
self.dependent_plugins / 'a.py',
self.dependent_plugins / 'b.py'
])
self.plugin_manager.resolve_dependencies()
def test_circular_dependency_error(self):
with assert_raises(ImportError):
self.plugin_manager.load_plugin(
self.dependent_plugins / 'circular.py')
self.plugin_manager.resolve_dependencies()
def test_empty_overrides(self):
self.plugin_manager.resolve_dependencies()
owners = self.loop.run_until_complete(
self.plugin_manager.get_overrides())
assert_equal(owners, set())
def test_override(self):
self.plugin_manager.load_plugin(
self.plugin_path / 'test_plugin_package')
self.plugin_manager.load_plugin(self.plugin_path / 'test_plugin_2.py')
self.plugin_manager.resolve_dependencies()
self.plugin_manager.activate_all()
overrides = self.loop.run_until_complete(
self.plugin_manager.get_overrides())
assert_equal(overrides, {'on_chat_sent'})
def test_override_caching(self):
self.plugin_manager.load_plugin(self.plugin_path / 'test_plugin_2.py')
assert_equal(self.plugin_manager._overrides, set())
assert_equal(self.plugin_manager._override_cache, set())
self.plugin_manager.activate_all()
self.loop.run_until_complete(self.plugin_manager.get_overrides())
assert_is(self.plugin_manager._override_cache,
self.plugin_manager._activated_plugins)
cache = self.plugin_manager._override_cache
self.loop.run_until_complete(self.plugin_manager.get_overrides())
assert_is(self.plugin_manager._override_cache, cache)
def test_activate(self):
#.........这里部分代码省略.........