本文整理汇总了Python中plugin_manager.PluginManager类的典型用法代码示例。如果您正苦于以下问题:Python PluginManager类的具体用法?Python PluginManager怎么用?Python PluginManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startup
def startup(config_path=DEFAULT_SETTINGS_FILE):
#init logging
setup_logging()
#load the config file and start the listener, daemon
logging.debug("init starting up")
config = ConfigParser.ConfigParser()
logging.debug('reading setting from: %s' % config_path)
config.read(config_path)
#Load the plugin manager to get a handle to the plugins.
_plugin_manager = PluginManager(config)
locator = _plugin_manager.get_resource_locator()
datastore = _plugin_manager.get_datastore()
driver = _plugin_manager.get_driver()
_registrar = Registrar(datastore, driver)
#should the listener be started?
start_server = config.getboolean('DEFAULT', 'start_server')
if start_server:
server.set_registrar(registrar)
Thread.start(server.start())
#start looking for backends and updating the driver
#THIS CALL WILL NOT RETURN
daemon.start(_registrar, locator, config)
示例2: test_prepare
def test_prepare(
self, mock_config, mock_path, mock_sys, mock_load_plugins
):
mock_factory = Mock()
mock_path.child.return_value = Mock(path='test child')
mock_config.return_value = Mock(
plugin_path='test path',
config={
'initial_plugins': 'test initial plugins'
}
)
pm = PluginManager(mock_factory)
pm.prepare()
mock_path.child.assert_called_with('test path')
mock_sys.path.append.assert_called_with('test child')
self.assertEqual(mock_load_plugins.call_count, 2)
mock_load_plugins.assert_has_calls(
[
call(
[
'core.admin_commands_plugin',
'core.colored_names',
'core.command_plugin',
'core.player_manager_plugin',
'core.starbound_config_manager'
]
),
call('test initial plugins')
]
)
示例3: main
def main():
# create the Application
app = QtWidgets.QApplication(sys.argv)
# create the event loop
event_loop = QEventLoop(app)
asyncio.set_event_loop(event_loop)
# Create the Gui
main_window = MainWindow()
# plugins to include different websites (and listeners?)
plugin_manager = PluginManager()
plugin_manager.register_main_window(main_window)
# User Settings
settings_manager = SettingsManager()
settings_manager.register_main_window(main_window)
settings_manager.register_plugin_manager(plugin_manager)
main_window.show()
try:
event_loop.run_forever()
except KeyboardInterrupt:
pass
app.deleteLater()
plugin_manager.terminate_plugins()
event_loop.close()
sys.exit()
示例4: JoyManager
class JoyManager():
def __init__(self):
self.pre_status = None
self.history = StatusHistory(max_length=10)
self.controller_type = rospy.get_param('~controller_type', 'xbox')
self.plugins = rospy.get_param('~plugins', [])
self.current_plugin_index = 0
if self.controller_type == 'xbox':
self.JoyStatus = XBoxStatus
elif self.controller_type == 'ps3':
self.JoyStatus = PS3Status
elif self.controller_type == 'ps3wired':
self.JoyStatus = PS3WiredStatus
elif self.controller_type == 'auto':
s = rospy.Subscriber('/joy', Joy, autoJoyDetect)
while not rospy.is_shutdown():
if AUTO_DETECTED_CLASS:
self.JoyStatus = AUTO_DETECTED_CLASS
s.unregister()
break
else:
rospy.sleep(1)
self.plugin_manager = PluginManager('jsk_teleop_joy')
self.loadPlugins()
def loadPlugins(self):
self.plugin_manager.loadPlugins()
self.plugin_instances = self.plugin_manager.loadPluginInstances(self.plugins)
def nextPlugin(self):
rospy.loginfo('switching to next plugin')
self.current_plugin_index = self.current_plugin_index + 1
if len(self.plugin_instances) == self.current_plugin_index:
self.current_plugin_index = 0
self.current_plugin.disable()
self.current_plugin = self.plugin_instances[self.current_plugin_index]
self.current_plugin.enable()
def start(self):
if len(self.plugin_instances) == 0:
rospy.logfatal('no valid plugins are loaded')
return
self.current_plugin = self.plugin_instances[0]
self.current_plugin.enable()
self.joy_subscriber = rospy.Subscriber('/joy', Joy, self.joyCB)
def joyCB(self, msg):
status = self.JoyStatus(msg)
if self.pre_status and status.select and not self.pre_status.select:
self.nextPlugin()
else:
self.current_plugin.joyCB(status, self.history)
self.pre_status = status
self.history.add(status)
示例5: test_installed_plugins
def test_installed_plugins(self, mock_config, mock_path, mock_sys):
mock_child = Mock(path='test child')
mock_child.globChildren.return_value = [
Mock(basename=lambda: 'plugin'),
Mock(basename=lambda: None),
Mock(basename=lambda: 'core')
]
mock_path.child.return_value = mock_child
pm = PluginManager(Mock())
result = pm.installed_plugins()
self.assertListEqual(result, ['plugin'])
示例6: startup
def startup():
#load the config file and start the listener, daemon
config = ConfigParser.ConfigParser()
config.read('C:\dev\projects\elasticd\conf\settings.cfg')
logging.debug("init starting up")
p_manager = PluginManager(config)
datastore = p_manager.get_datastore()
registrar = Registrar(datastore)
server.set_registrar(registrar)
server.start()
示例7: StarryPyServerFactory
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
示例8: start_qq
def start_qq(
no_gui=False, new_user=False, debug=False,
vpath="./v.jpg",
smart_qq_refer="http://d1.web2.qq.com/proxy.html?v=20030916001&callback=1&id=2",
cookie_file="cookie.data",
plugin_setting={
"plugin_root": "./plugins",
"plugins": [
"pluginmanage",
"test1"
],
"timers": [
"timer_weather"
]
},
dbhandler='sqlite:///message-record.db',
):
bot = QQBot(vpath, smart_qq_refer, cookie_file)
# update the modules and enbale utf-8 decoding.
reload(sys)
sys.setdefaultencoding("utf-8")
# set the mode for logger.
if debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
# login
bot.login(no_gui)
# initialze the handler
handler = SuperHandler(dbhandle=dbhandler, workers=5)
handler.update_group_list(bot)
logger.info("Update group list...")
# dbhandler = DBHandler()
# initialize the plugin manager
plmanager = PluginManager(plugin_setting["plugin_root"])
timermanager = PluginManager(plugin_setting["plugin_root"])
# load the plugins
for plugin_name in plugin_setting["plugins"]:
# plmanager.add_plugin(plugin_name)
try:
plmanager.add_plugin(plugin_name)
except Exception, e:
print(e)
logger.error("Failed to load plugin: %s" % plugin_name)
示例9: test_map_plugin_packets
def test_map_plugin_packets(self, mock_config, mock_path, mock_sys):
mock_plugin = Mock()
mock_plugin.name = 'Test'
mock_plugin.overridden_packets = {
1: {
'on': 'add me on 1',
'after': 'add me after 1'
}
}
mock_plugin2 = Mock()
mock_plugin2.name = 'Test2'
mock_plugin2.overridden_packets = {
2: {
'on': 'add me on 2'
},
3: {
'after': 'add me after 2'
}
}
pm = PluginManager(Mock())
pm.map_plugin_packets(mock_plugin)
self.assertDictEqual(
pm.packets,
{
1: {
'on': {'Test': (mock_plugin, 'add me on 1')},
'after': {'Test': (mock_plugin, 'add me after 1')}
}
}
)
pm.map_plugin_packets(mock_plugin2)
self.assertDictEqual(
pm.packets,
{
1: {
'on': {'Test': (mock_plugin, 'add me on 1')},
'after': {'Test': (mock_plugin, 'add me after 1')}
},
2: {
'on': {'Test2': (mock_plugin2, 'add me on 2')}
},
3: {
'after': {'Test2': (mock_plugin2, 'add me after 2')}
}
}
)
示例10: __init__
def __init__(self, *args, **kwargs):
discord.Client.__init__(self, *args, **kwargs)
self.redis_url = kwargs.get('redis_url')
self.db = Db(self.redis_url)
self.plugin_manager = PluginManager(self)
self.plugin_manager.load_all()
self.last_messages = []
示例11: test_get_plugin_name_from_file
def test_get_plugin_name_from_file(self):
mock_f = Mock()
mock_f.isdir.return_value = True
mock_f.basename.return_value = 'test base'
result = PluginManager.get_plugin_name_from_file(mock_f)
self.assertEqual(result, 'test base')
self.assertTrue(mock_f.isdir.called)
self.assertTrue(mock_f.basename.called)
mock_f = Mock()
mock_f.isdir.return_value = False
result = PluginManager.get_plugin_name_from_file(mock_f)
self.assertIsNone(result)
self.assertTrue(mock_f.isdir.called)
self.assertFalse(mock_f.basename.called)
示例12: __init__
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)
示例13: __init__
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
示例14: __init__
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()
示例15: __init__
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.redis_url = kwargs.get('redis_url')
self.mongo_url = kwargs.get('mongo_url')
self.dd_agent_url = kwargs.get('dd_agent_url')
self.db = Db(self.redis_url, self.mongo_url, self.loop)
self.plugin_manager = PluginManager(self)
self.plugin_manager.load_all()
self.last_messages = []
self.stats = DDAgent(self.dd_agent_url)