Edgewall Software

Changes between Initial Version and Version 3 of Ticket #3045


Ignore:
Timestamp:
Apr 18, 2006, 8:21:55 AM (18 years ago)
Author:
Alec Thomas
Comment:

Here's an updated version using the new config option magic:

class OrderedExtensionOption(ListOption):
    def __init__(self, section, name, interface, default=None,
                 include_missing=True, doc=''):
        ListOption.__init__(self, section, name, default, doc=doc)
        self.xtnpt = ExtensionPoint(interface)
        self.include_missing = include_missing

    def __get__(self, instance, owner):
        if instance is None:
            return self
        order = ListOption.__get__(self, instance, owner)
        if not order and self.default is not None:
            items = filter(None, [item.strip() for item in
                                  self.default.split(self.sep, ',')])
        components = []
        for impl in self.xtnpt.extensions(instance):
            if self.include_missing or impl.__class__.__name__ in order:
                components.append(impl)

        if not components:
            if self.default is not None:
                return self.default(instance.env)
            raise AttributeError('Cannot find any implementations of the "%s" '
                                 'interface from "%s".  Please update the '
                                 'option %s.%s in trac.ini.'
                                 % (self.xtnpt.interface.__name__,
                                    ', '.join(order), self.section, self.name))
        if order:
            def compare(x, y):
                x, y = x.__class__.__name__, y.__class__.__name__
                if x not in order:
                    return int(y in order)
                if y not in order:
                    return -int(x in order)
                return cmp(order.index(x), order.index(y))
            components.sort(compare)

        return components

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #3045

    • Property Keywords rfc architecture added
    • Property Severity trivialminor
  • Ticket #3045 – Description

    initial v3  
    4949ipermissionrequestor = PermissionSystem
    5050}}}
     51
     52
     53...and yet another case for factoring `getbool` out into `trac.util`... ;)