restrictedTraverse without acquisition
Hi!!! i have this directory structure / |- clients/projects/abc/batches/001 |- wg/projects/cba/batches/100 now i am running a script python from 001 folder. now i want to check whether there is any folder called abc in wg/projects folder. i do this by a try statedment try: foo = context.restrictedTraverse("wg/projects/abc") catch: ... # create the directory It goes into the workgroup folder. But when it sees the project folder, through acquisition it finds the projects folder inside clients hierarchy first and finds that the folder abc is actually present. I want context.restrictedTraverse to behave in a way that it acquire wg but after that projects should not be acquired but should follow the wg. Please help!! regards, R K ===== with "freedom" comes great responsibilities __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail
From: "R Karthick" <catchkarthick@yahoo.com>
i have this directory structure
/ |- clients/projects/abc/batches/001 |- wg/projects/cba/batches/100
now i am running a script python from 001 folder. now i want to check whether there is any folder called abc in wg/projects folder. i do this by a try statedment
try: foo = context.restrictedTraverse("wg/projects/abc") catch: ... # create the directory
It goes into the workgroup folder. But when it sees the project folder, through acquisition it finds the projects folder inside clients hierarchy first and finds that the folder abc is actually present.
I want context.restrictedTraverse to behave in a way that it acquire wg but after that projects should not be acquired but should follow the wg.
How about something like: (warning - untested) foo = context.restrictedTraverse("wg/projects") found = 0 for i in foo.objectItems(): if str(i[0]) == 'abc': found = 1 if not found: ... # create the directory HTH Jonathan
hi!! thank you for you reply. Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to? regards, R K --- Jonathan Hobbs <toolkit@magma.ca> wrote:
From: "R Karthick" <catchkarthick@yahoo.com>
i have this directory structure
/ |- clients/projects/abc/batches/001 |- wg/projects/cba/batches/100
now i am running a script python from 001 folder. now i want to check whether there is any folder called abc in wg/projects folder. i do this by a try statedment
try: foo = context.restrictedTraverse("wg/projects/abc") catch: ... # create the directory
It goes into the workgroup folder. But when it sees the project folder, through acquisition it finds the projects folder inside clients hierarchy first and finds that the folder abc is actually present.
I want context.restrictedTraverse to behave in a way that it acquire wg but after that projects should not be acquired but should follow the wg.
How about something like: (warning - untested)
foo = context.restrictedTraverse("wg/projects") found = 0 for i in foo.objectItems(): if str(i[0]) == 'abc': found = 1
if not found: ... # create the directory
HTH
Jonathan
===== with "freedom" comes great responsibilities __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail
I have never heard or read anything about turning acquisition 'off', and I would guess that it would not be a simple thing to do as many of the base classes used within zope inherit from or otherwise use acquisition classes (ie. acquisition is fundamental to many of the zope functions). Jonathan ----- Original Message ----- From: "R Karthick" <catchkarthick@yahoo.com> To: <zope@zope.org> Sent: July 13, 2004 1:50 PM Subject: Re: [Zope] restrictedTraverse without acquisition
hi!!
thank you for you reply.
Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to?
regards, R K
--- Jonathan Hobbs <toolkit@magma.ca> wrote:
From: "R Karthick" <catchkarthick@yahoo.com>
i have this directory structure
/ |- clients/projects/abc/batches/001 |- wg/projects/cba/batches/100
now i am running a script python from 001 folder. now i want to check whether there is any folder called abc in wg/projects folder. i do this by a try statedment
try: foo = context.restrictedTraverse("wg/projects/abc") catch: ... # create the directory
It goes into the workgroup folder. But when it sees the project folder, through acquisition it finds the projects folder inside clients hierarchy first and finds that the folder abc is actually present.
I want context.restrictedTraverse to behave in a way that it acquire wg but after that projects should not be acquired but should follow the wg.
How about something like: (warning - untested)
foo = context.restrictedTraverse("wg/projects") found = 0 for i in foo.objectItems(): if str(i[0]) == 'abc': found = 1
if not found: ... # create the directory
HTH
Jonathan
===== with "freedom" comes great responsibilities
__________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Tue, Jul 13, 2004 at 10:50:59AM -0700, R Karthick wrote:
hi!!
thank you for you reply.
Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to?
restrictedTraverse has no such feature. You could also item access rather than attribute access. This does not use acquisition. e.g.: try: context.wg['projects']['abc'] ...
How about something like: (warning - untested)
foo = context.restrictedTraverse("wg/projects") found = 0 for i in foo.objectItems(): if str(i[0]) == 'abc': found = 1
That works, as long as you don't mind wasting the cycles to look at every object in foo :-) but even in that case I would use objectIds() instead of objectItems(). -- Paul Winkler http://www.slinkp.com
On Tue, Jul 13, 2004 at 10:50:59AM -0700, R Karthick wrote:
hi!!
thank you for you reply.
Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to?
restrictedTraverse has no such feature.
You could also item access rather than attribute access. This does not use acquisition. e.g.:
try: context.wg['projects']['abc'] ...
If cycles are a concern, instead of raising an error condition try: foo = context.restrictedTraverse('/wg/projects') if not hasattr(foo, 'abc'): ... Jonathan
On Tue, Jul 13, 2004 at 03:56:51PM -0400, Jonathan Hobbs wrote:
On Tue, Jul 13, 2004 at 10:50:59AM -0700, R Karthick wrote:
hi!!
thank you for you reply.
Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to?
restrictedTraverse has no such feature.
You could also item access rather than attribute access. This does not use acquisition. e.g.:
try: context.wg['projects']['abc'] ...
If cycles are a concern, instead of raising an error condition try:
foo = context.restrictedTraverse('/wg/projects') if not hasattr(foo, 'abc'): ...
hasattr acquires. - Paul Winkler http://www.slinkp.com
----- Original Message ----- From: "Paul Winkler" <pw_lists@slinkp.com> To: <zope@zope.org> Sent: July 13, 2004 6:04 PM Subject: Re: [Zope] restrictedTraverse without acquisition
On Tue, Jul 13, 2004 at 03:56:51PM -0400, Jonathan Hobbs wrote:
On Tue, Jul 13, 2004 at 10:50:59AM -0700, R Karthick wrote:
hi!!
thank you for you reply.
Yeah it seems to be a good solution. but can't i just switch off acquisition in restrictedTraverse, when i need to?
restrictedTraverse has no such feature.
You could also item access rather than attribute access. This does not use acquisition. e.g.:
try: context.wg['projects']['abc'] ...
If cycles are a concern, instead of raising an error condition try:
foo = context.restrictedTraverse('/wg/projects') if not hasattr(foo, 'abc'): ...
hasattr acquires.
Point conceded... :) Jonathan
participants (3)
-
Jonathan Hobbs -
Paul Winkler -
R Karthick