home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from __future__ import with_statement
- import traceback
- import logging
- import config
- import util.primitives as util
- import util.data_importer as importers
- import peak.util.plugins as Plugins
- from path import path
- log = logging.getLogger('plugin_registry')
- METAINFO_FILENAME = 'info.yaml'
- type_handlers = { }
-
- def register_plugin_default(name, metainfo):
- log.error('Not registering type %r because of unknown "type" key (%r). its metainfo is: %r', name, metainfo.get('type', None), metainfo)
-
-
- def register_type_handler(typename, handler):
- old_handler = type_handlers.get(typename, None)
- if old_handler is not None:
- log.warning('Overwriting handler for type %r: was %r, now %r', typename, old_handler, handler)
-
- type_handlers[typename] = handler
-
-
- def get_type_handler(typename):
-
- try:
- return type_handlers[typename]
- except KeyError:
- return register_plugin_default
-
-
-
- def type_handler(typename):
-
- def register_handler(f):
- register_type_handler(typename, f)
- return f
-
- return register_handler
-
-
- def register_type(name, metainfo):
- a_type = metainfo.get('type', None)
- if a_type is None:
- log.error('Not registering type %r because it did not have a "type" key. its metainfo is: %r', name, metainfo)
- return None
- platforms = metainfo.get('platforms', None)
- if platforms is None or config.platformName in platforms:
- PluginType = get_type_handler(a_type)
- plugin = PluginType(metainfo.__file__.parent, metainfo)
- plugin.init()
- return plugin
-
-
- class PluginLoader(object):
-
- def __init__(self, dirpath, metainfo):
- self.path = dirpath
- self.shortname = metainfo.get('shortname', self.path.name)
- self.info = metainfo
-
-
- def init(self):
- self.name = self.info.name
- self.init_skin()
- self.init_notifications()
- self.init_actions()
- log.info('registered plugin type: %r', self.name)
-
-
- def init_skin(self):
- self.skin = self.resolve_paths(self.get_component('skin'))
-
-
- def resolve_paths(self, d):
- if not isinstance(d, dict):
- return d
- ret = { }
- for k, v in d.items():
- if isinstance(v, basestring):
- pth = self.path / v
- if pth.isfile() or pth.isdir():
- v = pth
-
- elif isinstance(v, dict):
- v = self.resolve_paths(v)
-
- ret[k] = v
-
- return ret
-
-
- def init_actions(self):
- actions = self.get_component('actions')
- if actions is None:
- return None
- import common.actions as common
- common.actions.add_actions(actions)
-
-
- def init_notifications(self):
- nots = self.get_component('notifications')
- if nots is None:
- return None
- import common.notifications as n
- defaults = { }
- for d in nots:
- for k in d:
- not_ = d[k]
- default = not_.get('default', { })
- default_reactions = [ {
- 'reaction': reaction } for reaction in default.get('reaction', []) ]
- defaults[k.replace('_', '.')] = default_reactions
-
-
- n.add_notifications(nots)
- n.add_default_notifications(defaults)
- self.set_component('notifications', nots)
-
-
- def get_component(self, attr, yamlname = None):
- attempts = [
- None,
- (None, ((None, None), (lambda : getattr(self, attr, None))), (lambda : getattr(self.info, attr, None))),
- (lambda : if not yamlname:
- passgetattr(self.yaml_load(attr), '__content__', None))]
- for attempt in attempts:
- thing = attempt()
- if thing is not None:
- break
- continue
- else:
- return None
- None.set_component(attr, thing)
- return thing
-
-
- def set_component(self, attr, thing):
- setattr(self, attr, thing)
- setattr(self.info, attr, thing)
-
-
- def yaml_load(self, yamlname):
-
- try:
- return importers.yaml_import(yamlname, loadpath = [
- self.path])
- except ImportError:
- return None
-
-
-
- def load_entry_points(self):
- import pkg_resources
- PluginDistribution = PluginDistribution
- import plugin_resources
- import config as digsbyconfig
- platforms = self.get_component('platforms')
- if platforms is None or digsbyconfig.platformName in platforms:
- pkg_resources.working_set.add(PluginDistribution(location = str(self.path.parent), project_name = self.info.name, ep_yaml = self.get_component('entry_points')))
-
-
-
- def __repr__(self):
- return '<%s %r>' % (type(self).__name__, self.name)
-
-
-
- class ProtocolPluginLoader(PluginLoader):
-
- def init(self, dictnames = None):
- PluginLoader.init(self)
- self.init_info(dictnames)
-
-
- def init_info(self, dictnames = None):
- import common.protocolmeta as pm
- plugin_info = util.primitives.mapping.Storage(self.info)
- if dictnames is not None:
- for dictname in dictnames:
- d = getattr(pm, dictname, None)
- if d is not None:
- d[self.shortname] = plugin_info
- continue
-
-
- pm.protocols[self.shortname] = plugin_info
-
-
- IMProtocolPluginLoader = type_handler('im')(<NODE:12>)
- EmailProtocolPluginLoader = type_handler('email')(<NODE:12>)
- SocialProtocolPluginLoader = type_handler('social')(<NODE:12>)
- MetaProtocolPluginLoader = type_handler('meta')(<NODE:12>)
- PurePluginLoader = type_handler('pure')(<NODE:12>)
- MultiPluginLoader = type_handler('multi')(<NODE:12>)
- ServiceProviderPlugin = type_handler('service_provider')(<NODE:12>)
- ServiceComponentPlugin = type_handler('service_component')(<NODE:12>)
- pkg_dirs = set()
-
- def scan(dirname):
- root = path(dirname)
- plugins = []
- for pkg_dir in root.dirs() + root.files('*.zip') + root.files('*.egg'):
- name = pkg_dir.namebase
- if exclude_dir(name):
- continue
-
-
- try:
- plugin = _load_plugin_info_from_item(pkg_dir)
- if plugin is None:
- log.info('No protocol info found in %r', pkg_dir)
- else:
- pkg_dirs.add(pkg_dir.abspath())
- ret = register_type(name, plugin)
- plugins.append(ret)
- if hasattr(ret, 'plugins'):
- plugins.extend(ret.plugins)
- except Exception:
- plugin is None
- plugin is None
- traceback.print_exc()
- continue
-
- return plugins
-
-
-
- def exclude_dir(dirname):
- return dirname.startswith('.')
-
-
- def _load_plugin_info_from_item(pkgdir):
-
- try:
- return importers.yaml_import('info', loadpath = [
- pkgdir])
- except ImportError:
- return None
-
-
-
- def plugins_skintrees():
- import wx
- plugins = wx.GetApp().plugins
- trees = []
- for plugin in plugins:
- if not plugin.get_component('skin'):
- pass
- skin = None
- if skin is not None:
- trees.append(skin)
- continue
-
- return trees
-
-
- def plugins_skinpaths():
- return list(pkg_dirs)
-
- Plugins.Hook('digsby.skin.load.trees', 'plugins_skin').register(plugins_skintrees)
- Plugins.Hook('digsby.skin.load.skinpaths', 'plugins_skin').register(plugins_skinpaths)
- if __name__ == '__main__':
- import wx
- a = wx.App()
- logging.basicConfig()
- log.setLevel(1)
- scan('c:\\workspace\\digsby\\src\\plugins')
-
-