本文整理汇总了Python中yapsy.PluginManager.PluginManagerSingleton类的典型用法代码示例。如果您正苦于以下问题:Python PluginManagerSingleton类的具体用法?Python PluginManagerSingleton怎么用?Python PluginManagerSingleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginManagerSingleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_filesystem_plugins
def load_filesystem_plugins(self):
"""Looks for *.yapsy-plugin files, loads them and returns a list
of :class:`VersionedPluginInfo \
<yapsy.VersionedPluginManager.VersionedPluginInfo>` objects
Note:
Plugin search locations:
* $(rawdisk package location)/plugins/filesystems
* $(home dir)/.local/share/rawdisk/plugins/filesystems
* /usr/local/share/rawdisk/plugins/filesystems
* /usr/share/rawdisk/plugins/filesystems
"""
self.logger.info('Loading filesystem plugins')
search_path = self.__get_fs_plugin_search_path()
fs_plugins = []
PluginManagerSingleton.setBehaviour([
VersionedPluginManager,
])
# Load the plugins from the plugin directory.
plugin_manager = PluginManagerSingleton.get()
plugin_manager.setPluginPlaces(search_path)
plugin_manager.setCategoriesFilter({
"Filesystem": IFilesystemPlugin,
})
# Load plugins
plugin_manager.collectPlugins()
for pluginInfo in plugin_manager.getPluginsOfCategory("Filesystem"):
fs_plugins.append(pluginInfo)
return fs_plugins
示例2: __init__
def __init__(self):
"""
Initialize the PluginManager including:
- plugin configuration directory
- plugin search locations
"""
self.config_path = save_config_path("yasibo")
self.config_file = os.path.join(self.config_path, "plugins.conf")
places = []
[places.append(os.path.join(path, "yasibo", "plugins")) for path in xdg_data_dirs]
# dev location
places.append("%s/../plugins" % os.path.dirname(os.path.abspath(__file__)))
PluginManagerSingleton.setBehaviour([ConfigurablePluginManager,
VersionedPluginManager])
self.manager = PluginManagerSingleton.get()
locator = self.manager.getPluginLocator()
locator.setPluginInfoExtension("yasibo-plugin")
self.manager.setPluginPlaces(places)
self.config = SafeConfigParser()
self.config.read(self.config_file)
self.manager.setConfigParser(self.config, self.save)
self.manager.collectPlugins()
log.debug("Config file: %s" % self.config_file)
示例3: _init_plugin_engine
def _init_plugin_engine(self):
self.debug("Initializing plugin engine")
places = []
if hasattr(self, '_plugin_dir'):
# run_local.py will pass in a plugin directory
places.append(self._plugin_dir)
for path in xdg_data_dirs:
path = os.path.join(path, self._package, "plugins")
places.append(path)
PluginManagerSingleton.setBehaviour([
ConfigurablePluginManager,
VersionedPluginManager,
])
manager = PluginManagerSingleton.get()
manager.application = self
manager.setConfigParser(self._config, self.write_config)
manager.setPluginInfoExtension("plugin")
manager.setPluginPlaces(places)
#manager.setCategoriesFilter({
# "Application" : WindowPlugin,
#})
manager.collectPlugins()
#for info in manager.getPluginsOfCategory("Window"):
for info in manager.getAllPlugins():
plugin = info.plugin_object
plugin.application = self
示例4: _load_filesystem_plugins
def _load_filesystem_plugins(self):
# import logging
# logging.basicConfig(level=logging.DEBUG)
"""Looks for *.yapsy-plugin files and loads them. It calls 'register' \
method for each plugin, which in turn registers with \
:class:`FilesystemDetector \
<rawdisk.filesystems.detector.FilesystemDetector>`.
Note:
Plugin search locations:
* $(rawdisk package location)/plugins/filesystems
* $(home dir)/.local/share/rawdisk/plugins/filesystems
* /usr/local/share/rawdisk/plugins/filesystems
* /usr/share/rawdisk/plugins/filesystems
"""
PluginManagerSingleton.setBehaviour([
VersionedPluginManager,
])
# Load the plugins from the plugin directory.
self.manager = PluginManagerSingleton.get()
self.manager.setPluginPlaces(self.search_path)
self.manager.setCategoriesFilter({
"Filesystem": IFilesystemPlugin,
})
# Load plugins
self.manager.collectPlugins()
for pluginInfo in self.manager.getPluginsOfCategory("Filesystem"):
self.fs_plugins.append(pluginInfo)
示例5: deferred_botmsg
def deferred_botmsg(self, user, channel, task, args):
if task == "rep":
user = user.split("!")[0]
if args[0] == "give":
manager = PluginManagerSingleton.get()
user_stat = yield manager.app.is_user_online(args[1])
if user_stat == False:
logging.warning(manager.app.is_user_online(args[1]))
manager.app.msg(channel, "This user doesn't appear to be here!")
return
if args[1] == user:
manager.app.msg(channel, "You cannot give yourself rep.")
return
lastRep = manager.app.plugin_get_setting("repPlugin", "lastRep")
if user + ":" + args[1] == str(lastRep):
manager.app.msg(channel, "You've already given this person rep!")
return
self.give_rep(args[1])
manager.app.plugin_set_setting("repPlugin", "lastRep", user + ":" + args[1])
manager.app.msg(channel, args[1] + " has received 1 rep from " + user)
elif args[0] == "check":
manager = PluginManagerSingleton.get()
manager.app.msg(channel, args[1] + " has " + str(self.get_rep(args[1])) + " rep!")
elif args[0] == "purge":
manager = PluginManagerSingleton.get()
if user in manager.app.plugin_get_setting("repPlugin", "allowedUsers"):
self.cleanup()
manager.app.msg(channel, "Rep data purged.")
示例6: __init__
def __init__ (self):
""" Class initialiser """
# Get singleton instance
PluginManagerSingleton.setBehaviour([
VersionedPluginManager,
])
manager = PluginManagerSingleton.get()
# A referrence for plugins to access the app
manager.app = self
# Set environment
self.env = jinja2.Environment(loader=jinja2.FileSystemLoader("./template/"),
**TEMPLATE_OPTIONS)
# Set ArgParser
self.parser = argparse.ArgumentParser(description='Simple Static Web Generator')
self.parser.add_argument('--cache', dest='cache', action='store_true')
# A referrence for plugins to access the env object
# manager.env = self.env
# Set plugin's directories path
manager.setPluginPlaces(['plugins'])
# Locates and Loads the plugins
manager.collectPlugins()
示例7: botmsg
def botmsg(self, user, channel, task, args):
manager = PluginManagerSingleton.get()
if user.split("!")[0] not in manager.app.plugin_get_setting("pluginAdmin", "allowedUsers") and task == "plugin" :
manager.app.msg(channel, "You're not authorised to do that!")
return
if task == "plugin":
if args[0] == "rehash":
manager.app.rehash_plugins()
manager.app.msg(channel, "Plugins rehashed!")
elif args[0] == "load":
manager = PluginManagerSingleton.get()
pname = string.join(args[1:])
if pname in manager.app.plugin_get_setting("pluginAdmin", "disallowedPlugins"):
manager.app.msg(channel, "Plugin \"" + pname + "\" is protected!")
return
manager.app.load_plugin(pname)
manager.app.msg(channel, "Plugin \"" + string.join(args[1:]) + "\" has been loaded.")
elif args[0] == "unload":
manager = PluginManagerSingleton.get()
pname = string.join(args[1:])
if pname in manager.app.plugin_get_setting("pluginAdmin", "disallowedPlugins"):
manager.app.msg(channel, "Plugin \"" + pname + "\" is protected!")
return
manager.app.unload_plugin(string.join(args[1:]))
manager.app.msg(channel, "Plugin \"" + string.join(args[1:]) + "\" has been unloaded.")
示例8: botmsg
def botmsg(self, user, channel, task, args):
user = user.split("!")[0]
if task == "note" and args[0] == "send":
manager = PluginManagerSingleton.get()
self.add_note(args[1], "\"" + string.join(args[2:]) + "\" (from " + user + ")")
manager.app.msg(args[1], "You have a new note! Use !note read to read it.")
manager.app.msg(user, "Your message has been sent.")
elif task == "note" and args[0] == "read":
manager = PluginManagerSingleton.get()
_notes = manager.app.plugin_get_setting("notePlugin", "notes")
x = None
try:
x = _notes[user]
if len(x) == 0:
raise KeyError("x")
except KeyError:
manager.app.msg(user, "You don't have any messages.")
return
manager.app.msg(user, str(x[0]))
_notes[user].remove(x[0])
manager.app.msg(user, "You now have " + str(len(x)) + " messages. Use !note read to read the next one.")
if len(x) == 0:
_notes.pop(user, None)
manager.app.plugin_set_setting("notePlugin", "notes", _notes)
elif task == "note" and args[0] == "purge":
manager = PluginManagerSingleton.get()
if not user in manager.app.plugin_get_setting("notePlugin", "allowedUsers"):
return
self.cleanup()
manager.app.msg(user, "Notes purged.")
示例9: _loadPlugins
def _loadPlugins(self):
PluginManagerSingleton.setBehaviour([
VersionedPluginManager,
])
manager = PluginManagerSingleton.get()
manager.setPluginPlaces(self.pluginDirs)
manager.setCategoriesFilter(pluginCategories)
manager.collectPlugins()
示例10: testActivationAndDeactivation
def testActivationAndDeactivation(self):
"""
Test if the activation/deactivaion procedures work.
"""
self.plugin_activate()
PluginManagerSingleton.get().deactivatePluginByName(self.plugin_info.name,
self.plugin_info.category)
self.assertTrue(not self.plugin_info.plugin_object.is_activated)
示例11: plugin_activate
def plugin_activate(self):
"""
Activate the plugin with basic checking
"""
self.plugin_loading_check()
if not self.plugin_info.plugin_object.is_activated:
PluginManagerSingleton.get().activatePluginByName(self.plugin_info.name,
self.plugin_info.category)
self.assertTrue(self.plugin_info.plugin_object.is_activated)
示例12: __init__
def __init__(self, win):
self.app = win.app
self.parent = win
# Build a list of directories which may contain plugins. This will
# include the 'plugins' folder where this file resides as well as every
# directory in xdg.BaseDirectory.xdg_data_dirs. This way users can
# install plugins in something like ~/.local/yapsy-gtk-example/plugins
# but your installer could also install those plugins to something like
# /usr/share/yapsy-gtk-example/plugins. You'll see Yapsy checking each
# of these directories if logging is set to logging.DEBUG
xdg_data_dirs = [os.path.join(os.path.expanduser("~"),
'.local', 'share')]
this_dir = os.path.abspath(self.app.FULL_PATH)
plugin_dir = os.path.join(this_dir, 'data', 'plugins')
places = [plugin_dir, ]
for path in xdg_data_dirs:
places.append(os.path.join(path, self.app.APP_NAME, "plugins"))
# The singleton versino of the Yapsy plugin manager is used rather than
# passing around a PluginManager instance. Prior to getting the
# singleton instance, some "plugin manager decorators" are installed to:
# 1. Automatically save active and non-active plugins to the config file
# 2. Ensure only the newest versions of plugins are used.
# This call to setBehaviour() must occur before getting the singleton
# instance.
PluginManagerSingleton.setBehaviour([
ConfigurablePluginManager,
VersionedPluginManager,
])
# Get singleton instance
manager = PluginManagerSingleton.get()
# I like to give the manager a reference to the application class so
# that plugins can connect to signals and access windows through
# the manager singleton.
manager.app = self.app
manager.parent = self.parent
# Give manager the config file and a callback function to call when it
# changes the config (eg. when a plugin is activated or deactivated).
manager.setConfigParser(self.app.config, self.app.config.write_settings)
# Setup a file extension for plugin information files. In this it's
# just ".plugin" but you may want to do something specific to your
# application like ".myapp-plugin"
manager.setPluginInfoExtension("gs-plugin")
# Pass the manager the list of plugin directories
manager.setPluginPlaces(places)
# CollectPlugins is a shortcut for locatePlugins() and loadPlugins().
manager.collectPlugins()
示例13: create_plugin_manager
def create_plugin_manager(self):
from yapsy.ConfigurablePluginManager import ConfigurablePluginManager
from yapsy.PluginManager import PluginManagerSingleton
from yapsy.VersionedPluginManager import VersionedPluginManager
PluginManagerSingleton.setBehaviour([
ConfigurablePluginManager,
VersionedPluginManager,
])
return PluginManagerSingleton.get()
示例14: __init__
def __init__(self, cfg):
"""
Initialise the plugin system.
"""
assert cfg
self.cfg = cfg
# Get plugin locations.
plugin_search_path_b = self.cfg.get_config_str(
"PluginSearchPath",
default=b"/etc/rdiffweb/plugins")
# Determine the search path
searchpath = []
# Append core plugins directory (in bytes)
path_b = pkg_resources.resource_filename('rdiffweb', b'plugins') # @UndefinedVariable
searchpath.append(path_b)
# Append user plugins directory
plugin_locations = plugin_search_path_b.split(b',')
searchpath.extend(plugin_locations)
# Build the manager
logger.debug("plugin search path [%s]" % (searchpath))
# Create the plugin manager.
PluginManagerSingleton.setBehaviour([FilteredPluginManager])
self.manager = PluginManagerSingleton.get()
# Sets plugins locations.
plugin_locator = PluginLocator()
self.manager.setPluginLocator(plugin_locator)
plugin_locator.setPluginPlaces(searchpath)
# Define categories
self.manager.setCategoriesFilter({
IDatabase.CATEGORY: IDatabase,
IDeamonPlugin.CATEGORY: IDeamonPlugin,
ILocationsPagePlugin.CATEGORY: ILocationsPagePlugin,
IPasswordStore.CATEGORY: IPasswordStore,
IPreferencesPanelProvider.CATEGORY: IPreferencesPanelProvider,
IUserChangeListener.CATEGORY: IUserChangeListener,
})
# Set filter.
self.manager.isPluginOk = self.is_plugin_enabled
# Load all plugins
self.manager.collectPlugins()
示例15: list
def list(args):
xh.setuputil.collectPlugins()
pm = PluginManagerSingleton.get()
pluginInfoStr = 'Plugins:'
for p in pm.getAllPlugins():
infos = ['%s (%s%s)'
% (p.name, os.path.basename(p.path), os.path.sep)]
if '?' not in p.version:
infos.append('v' + p.version)
if p.description is not None:
infos.append(p.description)
pluginInfoStr += '\n\t' + ' '.join(infos)
log.info(pluginInfoStr)
serialDevice = (xh.setuputil.FAKE_SERIAL if args.fakeSerial
else args.serialDevice)
nodeInfoList = listNodeIds(
serialDevice=serialDevice,
timeout=args.timeout)
nodeInfoStr = 'XBees:'
for n in nodeInfoList:
lineStr = str(n)
nodeInfoStr += '\n\t' + lineStr
log.info(nodeInfoStr)