I'm familiar with
http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture and have
managed to implement some Extension Points and toyed with
ExtensionOption, etc. but none of that seems to quite do what I want.
In the Project Management support for TracJSGantt, I have:
class ITaskSorter(Interface):
and then implement two different sorters. My idea is that a user would
install the plugin then use Trac admin to enable the sorter that better
suits their needs (or implement their own and disable both of the
built-in sorters). 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...
? It seems there must be an idiom for controlling what EP is active
from admin and getting that one from a plugin.
(This is in 0.11.6, BTW.)
Chris
--
Christopher Nelson, Software Engineering Manager
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173, x135
yep . I think I have replied similar Qs as well
;)
[...]
>
>
> ? It seems there must be an idiom for controlling what EP is active from admin and getting that one from a plugin.
>
trac.config.ExtensionOption
trac.config.OrderedExtensionOption
TracIniAdminPlugin
--
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.
Reminds me of these threads:
http://thread.gmane.org/gmane.comp.version-control.subversion.trac.devel/6825
http://thread.gmane.org/gmane.comp.version-control.subversion.trac.devel/6921
http://thread.gmane.org/gmane.comp.version-control.subversion.trac.general/32450/
> I'm familiar with
> http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture and have
> managed to implement some Extension Points and toyed with
> ExtensionOption, etc. but none of that seems to quite do what I want. In
Based on the rest of your description, I would have thought
ExtensionOption is exactly what you want:
task_sorter = ExtensionOption('trac-jsgantt', 'task_sorter', ITaskSorter,
'DefaultTaskSorter',
"""Name of the component implementing `ITaskSorter`, which is used
for sorting tasks.""")
...
theSorter = task_sorter
...
Then implement DefaultTaskSorter and say AdvancedTaskSorter. The user
would keep both enabled (or disable the unused one although that's not
required). By default DefaultTaskSorter would be used, and if the user
wants to switch, he should put this in his trac.ini file:
[trac-jsgantt]
task_sorter = AdvancedTaskSorter
That's how it usually works in Trac. Are you sure this does not fit your
needs? Why not?
--
Peter
Yes. Definitely. The second and third are right on topic. And I don't
think I got an answer that applies.
>...
> Based on the rest of your description, I would have thought
> ExtensionOption is exactly what you want:
>
> task_sorter = ExtensionOption('trac-jsgantt', 'task_sorter', ITaskSorter,
> 'DefaultTaskSorter',
> """Name of the component implementing `ITaskSorter`, which is used
> for sorting tasks.""")
> ...
> theSorter = task_sorter
> ...
> That's how it usually works in Trac. Are you sure this does not fit your
> needs? Why not?
I can and have done that as I've experimented but that requires a user
to edit trac.ini to choose. What I want is for them to enable the
component they want in the web admin.
On 03/21/2012 03:15 PM, Peter Suter wrote:
On 21.03.2012 19:36, Chris Nelson wrote:
...
Based on the rest of your description, I would have thought
ExtensionOption is exactly what you want:
task_sorter = ExtensionOption('trac-jsgantt', 'task_sorter', ITaskSorter,
'DefaultTaskSorter',
"""Name of the component implementing `ITaskSorter`, which is used
for sorting tasks.""")
...
theSorter = task_sorter
...That's how it usually works in Trac. Are you sure this does not fit your
needs? Why not?
I can and have done that as I've experimented but that requires a user to edit trac.ini to choose. What I want is for them to enable the component they want in the web admin.
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
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!
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)