Esempio n. 1
0
    def discover_classes(pluginklass, baseclass):
        '''Yields a list of classes derived from C{baseclass} and
		defined in the same module as the plugin
		'''
        module = get_module(pluginklass.__module__)
        for klass in lookup_subclasses(module, baseclass):
            yield klass
Esempio n. 2
0
    def lookup_subclass(pluginklass, klass):
        '''Returns first subclass of C{klass} found in the module of
		this plugin. (Similar to L{zim.utils.lookup_subclass}).
		@param pluginklass: plugin class
		@param klass: base class of the wanted class
		'''
        module = get_module(pluginklass.__module__)
        return lookup_subclass(module, klass)
Esempio n. 3
0
	def discover_extensions_classes(pluginklass):
		# Find related extension classes in same module
		# any class with the "__extends__" field will be added
		# (Being subclass of ObjectExtension is optional)
		module = get_module(pluginklass.__module__)
		for n, klass in inspect.getmembers(module, inspect.isclass):
			if hasattr(klass, '__extends__') and klass.__extends__:
				yield klass.__extends__, klass
Esempio n. 4
0
File: __init__.py Progetto: gdw2/zim
	def lookup_subclass(pluginklass, klass):
		'''Returns first subclass of C{klass} found in the module of
		this plugin. (Similar to L{zim.utils.lookup_subclass})
		@param pluginklass: plugin class
		@param klass: base class of the wanted class
		'''
		module = get_module(pluginklass.__module__)
		return lookup_subclass(module, klass)
Esempio n. 5
0
def get_plugin_class(name):
	'''Get the plugin class for a given name

	@param name: the plugin module name (e.g. "calendar")
	@returns: the plugin class object
	'''
	mod = get_module('zim.plugins.' + name)
	return lookup_subclass(mod, PluginClass)
Esempio n. 6
0
    def get_plugin_class(klass, name):
        '''Get the plugin class for a given name

		@param name: the plugin module name
		@returns: the plugin class object
		'''
        modname = 'zim.plugins.' + name
        mod = get_module(modname)
        return lookup_subclass(mod, PluginClass)
Esempio n. 7
0
    def discover_extensions_classes(pluginklass):
        '''Find extension classes in same module as the plugin
		object class.
		@returns: yields 2-tuple of the name of the object class to be
		extended (as set by the L{extends} decorator) and the extension
		class object
		'''
        # Any class with the "__extends__" field will be added
        # (Being subclass of ObjectExtension is optional)
        module = get_module(pluginklass.__module__)
        for n, klass in inspect.getmembers(module, inspect.isclass):
            if hasattr(klass, '__extends__') and klass.__extends__:
                yield klass.__extends__, klass
Esempio n. 8
0
def build_command(args, pwd=None):
    '''Parse all commandline options
	@returns: a L{Command} object
	@raises UsageError: if args is not correct
	'''
    args = list(args)

    if args and args[0] == '--plugin':
        args.pop(0)
        try:
            cmd = args.pop(0)
        except IndexError:
            raise UsageError('Missing plugin name')

        try:
            mod = get_module('zim.plugins.' + cmd)
            klass = lookup_subclass(mod, Command)
        except:
            if '-D' in args or '--debug' in args:
                logger.exception('Error while loading: zim.plugins.%s.Command',
                                 cmd)
                # Can't use following because log level not yet set:
                # logger.debug('Error while loading: zim.plugins.%s.Command', cmd, exc_info=sys.exc_info())
            raise UsageError(
                'Could not load commandline command for plugin "%s"' % cmd)
    else:
        if args and args[0].startswith('--') and args[0][2:] in commands:
            cmd = args.pop(0)[2:]
            if cmd == 'server' and '--gui' in args:
                args.remove('--gui')
                cmd = 'servergui'
        elif args and args[0] == '-v':
            args.pop(0)
            cmd = 'version'
        elif args and args[0] == '-h':
            args.pop(0)
            cmd = 'help'
        else:
            cmd = 'gui'  # default

        klass = commands[cmd]

    obj = klass(cmd, pwd=pwd)
    obj.parse_options(*args)
    return obj
Esempio n. 9
0
File: main.py Progetto: gdw2/zim
def build_command(argv):
	'''Parse all commandline options
	@returns: a L{Command} object
	@raises UsageError: if argv is not correct
	'''
	argv = list(argv)

	if argv and argv[0] == '--plugin':
		argv.pop(0)
		try:
			cmd = argv.pop(0)
		except IndexError:
			raise UsageError, 'Missing plugin name'

		try:
			mod = get_module('zim.plugins.' + cmd)
			klass = lookup_subclass(mod, Command)
		except:
			raise UsageError, 'Could not load commandline command for plugin "%s"' % cmd
	else:
		if argv and argv[0].startswith('--') and argv[0][2:] in commands:
			cmd = argv.pop(0)[2:]
			if cmd == 'server' and '--gui' in argv:
				argv.remove('--gui')
				cmd = 'servergui'
		elif argv and argv[0] == '-v':
			argv.pop(0)
			cmd = 'version'
		elif argv and argv[0] == '-h':
			argv.pop(0)
			cmd = 'help'
		else:
			cmd = 'gui' # default

		klass = commands[cmd]

	obj = klass(cmd)
	obj.parse_options(*argv)
	return obj
Esempio n. 10
0
def build_command(argv):
    '''Parse all commandline options
	@returns: a L{Command} object
	@raises UsageError: if argv is not correct
	'''
    argv = list(argv)

    if argv and argv[0] == '--plugin':
        argv.pop(0)
        try:
            cmd = argv.pop(0)
        except IndexError:
            raise UsageError, 'Missing plugin name'

        try:
            mod = get_module('zim.plugins.' + cmd)
            klass = lookup_subclass(mod, Command)
        except:
            raise UsageError, 'Could not load commandline command for plugin "%s"' % cmd
    else:
        if argv and argv[0].startswith('--') and argv[0][2:] in commands:
            cmd = argv.pop(0)[2:]
            if cmd == 'server' and '--gui' in argv:
                argv.remove('--gui')
                cmd = 'servergui'
        elif argv and argv[0] == '-v':
            argv.pop(0)
            cmd = 'version'
        elif argv and argv[0] == '-h':
            argv.pop(0)
            cmd = 'help'
        else:
            cmd = 'gui'  # default

        klass = commands[cmd]

    obj = klass(cmd)
    obj.parse_options(*argv)
    return obj