home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import traceback
- import sys
- import logging
- import config
- import util
- import util.data_importer as importers
- 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
- else:
- 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 = self.path.name
- self.info = metainfo
-
-
- def init(self):
- self.name = self.info.name
- log.info('registered account type: %r', self.name)
-
-
- 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
- self.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
-
-
-
-
- class ProtocolPluginLoader(PluginLoader):
-
- def init(self, dictnames = None):
- PluginLoader.init(self)
- self.init_info(dictnames)
- self.init_skin(dictnames)
- self.init_actions(dictnames)
- self.init_notifications(dictnames)
-
-
- def init_skin(self, dictnames = None):
- self.get_component('skin')
-
-
- def init_info(self, dictnames = None):
- import common.protocolmeta as pm
- plugin_info = util.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
-
-
- def init_actions(self, dictnames = None):
- 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, dictnames = None):
- 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)
-
-
-
- class IMProtocolPluginLoader(ProtocolPluginLoader):
-
- def init(self):
- return ProtocolPluginLoader.init(self, [
- 'improtocols'])
-
-
- register_type_handler('im', IMProtocolPluginLoader)
-
- class EmailProtocolPluginLoader(ProtocolPluginLoader):
-
- def init(self):
- return ProtocolPluginLoader.init(self, [
- 'emailprotocols'])
-
-
- register_type_handler('email', EmailProtocolPluginLoader)
-
- class SocialProtocolPluginLoader(ProtocolPluginLoader):
-
- def init(self):
- return ProtocolPluginLoader.init(self, [
- 'socialprotocols'])
-
-
- register_type_handler('social', SocialProtocolPluginLoader)
-
- class MetaProtocolPluginLoader(ProtocolPluginLoader):
-
- def init(self):
- return ProtocolPluginLoader.init(self)
-
-
- register_type_handler('meta', MetaProtocolPluginLoader)
-
- class StatusPluginLoader(PluginLoader):
-
- def init(self):
- PluginLoader.init(self)
- log.info('Got new status type: %r', self.name)
- import_path = 'plugins.%s' % self.shortname
- log.info('Importing %r as %r', self.name, import_path)
-
- try:
- module = util.import_module(import_path)
- except ImportError:
- return None
-
- init = getattr(module, 'initialize', None)
- if init is not None:
- init()
-
-
-
- register_type_handler('status', StatusPluginLoader)
- pkg_dirs = set()
-
- def scan(dirname):
- root = path(dirname)
- 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.error('No protocol info found in %r', pkg_dir)
- else:
- pkg_dirs.add(pkg_dir.abspath())
- register_type(name, plugin)
- continue
- except Exception:
- traceback.print_exc()
- continue
-
-
-
-
-
- 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():
- trees = []
- import common.protocolmeta as pm
- for name, infodict in pm.protocols.iteritems():
- if 'skin' in infodict:
- trees.append(infodict['skin'])
- continue
-
- return trees
-
-
- def plugins_skinpaths():
- return list(pkg_dirs)
-
- from peak.util.plugins import Hook
- Hook('digsby.skin.load.trees', 'plugins_skin').register(plugins_skintrees)
- 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')
-
-