[TransWarp] component path - property name dualism, does
this make sense?
Phillip J. Eby
pje at telecommunity.com
Mon Aug 18 15:48:51 EDT 2003
At 08:35 PM 8/18/03 +0200, Matthias Drochner wrote:
>pje at telecommunity.com said:
> > Have you looked at ZConfig?
>
>Thanks for your reply -- while I consider the XML-like syntax not
>too well suited for end-"users", it has its advantages, and since
>in my case the config-file-supplied data are primarily for
>testing in absence of the real database, this is acceptable.
>
>I'll look into it; this might take a while...
I'll also note that there is another possibility here... it may be that
PEAK components are the wrong tool for the job you're trying to do. If
these axes and suchlike components are really dynamic, and want to come
from a database, it may be that the peak.model package offers better tools
for the job (and can handle persistence and transactions via
peak.storage). But that depends a bit on what your overall schema looks like.
Alas, peak.model is even less well documented at present than peak.binding
and peak.config. But feel free to post your questions and I will do my
best to answer them.
Also, here's a slightly cleaned up alternative to your original post:
class ConfigDelegate(binding.Component):
def propertyMap(self,d,a):
path = binding.getComponentPath(self)
return PropertyName('devconfig.' + '.'.join(path[1:-1])).of(self)
propertyMap = binding.Once(propertyMap)
def __getattr__(self, attr):
value = self.propertyMap.get(attr,NOT_FOUND)
if value is NOT_FOUND:
raise AttributeError(attr)
return value
class testaxis(binding.Component):
protocols.advise(
instancesProvide = [movable.Imovable]
)
currentpos = 0
moving = 0
logger = binding.bindToProperty('logging.movement')
delegate = binding.New(ConfigDelegate)
speed = ll = ul = binding.delegateTo('delegate')
def __init(self, d, a):
self.logger.debug('testaxis: initializing %s', self.path)
__init = binding.whenAssembled(__init)
Now, as you can see, you need only have a ConfigDelegate in your classes,
and use delegateTo to lookup the data. I left your '__init()' method in
place above, mainly to illustrate that it's not necessary to use a lambda:
to call it, and also to illustrate that you really don't need the method at
all!
This approach uses a slightly different config structure, here's your
example .ini file recast for the above:
[devconfig.movetest]
* = naming.LinkRef('tacodb:movetest.%s/' % ruleSuffix)
group1.member1.ll = 0
group1.member1.ul = 100
group1.member1.speed = 0.4
group1.member2.ll = 0
group1.member2.ul = 100
group1.member2.speed = 0.2
Now, any data that is not supplied in the configuration file, will come
from your 'tacodb' thing. I presume that that's what your use case for
this is, anyway. That is, you want to have data come from the DB unless
you override it in the config file.
More information about the PEAK
mailing list