On Thu, Mar 22, 2012 at 10:31 AM, Chris Nelson <[email protected]> wrote:
>
> On 03/21/2012 02:36 PM, Chris Nelson wrote:
>>
>> ... But how do I make sure that only one sorter is
>>
>> enabled? Do I have to resort to something like:
>>
>> sorters = ExtensionPoint(ITaskSorter)
>>
>> count = 0
>> for sorter i self.sorters:
>> count++
>> theSorter = sorter
>> if count > 1:
>> ...raise an error...
>>
>> ? ...
>
>
> 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
}}}
In order to use it that way you'll need to do something like this
{{{
#!python
self.sorters = ExtensionPoint(ITaskSorter)
i = 0
for s in self.sorters.extensions(self):
i += 1
self.env.log.debug('Found %d enabled sorters' % i)
}}}
... but IMO last approach's not recommended
;)
--
Regards,
Olemis
Facebook => http://www.facebook.com/olemis
Twitter => http://www.twitter.com/olemislc (@olemislc)
Blog ES => http://simelo-es.blogspot.com
Blog EN => http://simelo-en.blogspot.com
Quora => http://www.quora.com/olemis
Youtube => http://youtube.com/user/greatsoftw
Featured article : [svn r11148] XmlRpcPlugin: `wiki.getPageHTML()` now
supports wiki manipulators that can possibly modify the wiki text
content before rendering. With test.
Tweet: yo no puedo creer q haya pasado inadvertido el 1/2/12 12:12 ...
@elainediaz2003 no dijo na' ... OMG ! ... much more coming soon ;) #fb
Follow @olemislc Reply Retweet 12:59 Feb-01
Get this email app!
Get a signature like this. CLICK HERE.
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en.