On 03/22/2012 12:04 PM, Olemis Lang wrote:
Granted that this may be a strange way to program Trac, it seems like it is
valid. But when I do:
self.sorters = ExtensionPoint(ITaskSorter)
i = 0
for s in self.sorters:
i += 1
self.env.log.debug('Found %d enabled sorters' % i)
I get:
'ExtensionPoint' object is not iterable
I'm in Trac 0.11.6 but I Googled uses of ExtensionPoint and there seem to be
some quite old ones in the style that iterates over an ExtensionPoint. What am
I doing wrong?
ExtensionPoint is a descriptor (like property objects ;) so it makes
its magic happen when it's declared in the class suite i.e.
{{{
#!python
class MyComponent(Component):
xp = ExtensionPoint(IMyInterface)
c = MyComponent(env)
for x in c.xp :
# Do something
}}}
...
Thahks.
What I have working is:
# The ResourceScheduler uses the Bridge design pattern to separate
# the overall scheduling process from the implementation of
# prioritizing tasks, via an ITaskSorter implementation and
# determining resource availability, via an IResourceCalendar
# implementation.
#
# We identify all the enabled implementations via ExtensionPoint()
# then use _mixIn() to pick one (if more than one is enabled).
# Find any enabled sorters and calendars. We'll pick one each in
__init__
sorters = ExtensionPoint(ITaskSorter)
calendars = ExtensionPoint(IResourceCalendar)
# Pick one of N enabled implementations of interface or fall back
# to default if none are found.
# interface - The name of the interface (e.g., 'ITaskSorter')
# expt - The extension point to process
# default - default implementation to use
def _mixIn(self, interface, extpt, default = None):
# Count the enabled implementations
i = 0
for e in extpt:
i += 1
# If none
if i == 0:
# Use default, if set
if default:
self.env.log.info(('No %s implementations enabled. ' +
'Using default, %s') %
(interface, default))
e = default(self.env)
# Otherwise, we can't go on.
else:
raise TracError('No %s implementations enabled.' %
interface)
# If more than one, log the one we picked.
elif i > 1:
self.env.log.info(('Found %s enabled %s implementations. ' +
'Using %s.') %
(i, interface, e))
# Return the chosen (or default) implementation.
return e
def __init__(self):
# Instantiate the PM component
self.pm = TracPM(self.env)
self.cal = self._mixIn('IResourceCalendar',
self.calendars,
SimpleCalendar)
self.cmp = self._mixIn('ITaskSorter',
self.sorters,
SimpleSorter)
--
Christopher Nelson, Software Engineering Manager
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173, x135
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to trac-dev@googlegroups.com.
To unsubscribe from this group, send email to
trac-dev+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en.