[TransWarp] Component hierarchy traversal

Phillip J. Eby pje at telecommunity.com
Fri Oct 10 12:11:19 EDT 2003


At 05:24 PM 10/10/03 +0200, Radek Kanovsky wrote:
>On Wed, Oct 01, 2003 at 02:46:29PM -0400, Phillip J. Eby wrote:
>
> > This issue in general is rather interesting.  None of the approaches to
> > dealing with it are perfect: it seems there is a distinct tension between
> > broad resource discoverability, and lazy creation of those same resources.
>
>I think that genereal solution would require some changes in peak.binding.
>
>Bellow is my solution of problem with special command invocation
>without hierarchy traversal.

Please note that it's a bad idea to subclass ConfigurationRoot, as it makes 
it more difficult for others to use your components as part of a larger 
application.  And, there isn't any need for you to, in order to implement 
what you did.  There's no reason the "root" application object can't simply:

     _me = binding.Obtain('.', offerAs=[ICommandRoot])

...or something similar, for all the children to be able to access 
it.  Your 'registerCommand' binding could then simply do this:

     root = binding.lookupComponent(ICommandRoot)

So, there's no reason to make it a configuration root, and hardcode its 
location.  Doing it this way instead, will allow your apps to be invoked as 
'peak import:whatever.Application' if you derive the application class from 
peak.running.commands.AbstractCommand.

Even if you prefer to make the application a self-contained executable 
script, you can do:

if __name__=='__main__':
     sys.exit(Application(config.makeRoot()).run())

But others will still be able to use your application class as an invokable 
command according to PEAK conventions.




More information about the PEAK mailing list