Re: [Zope-dev] oh boy [id,getId() madness]

2003-06-11 Thread Adrian van den Dries
On June 11, Stefan H. Holek wrote:
> This is definitely possible. You probably have a faulty factory method. In 
> Zope, construction is a two step process that looks something like
> 
>  def addSomething(self, id, title=''):
>  ob = Something(id, title)
>  self._setObject(id, ob)

That's why this should be:

def addSomething(self, id):
ob = Something(id)
self._setObject(ob.getId(), ob)

But I notice nobody seems to do this.

a.

-- 
 Adrian van den Dries   [EMAIL PROTECTED]
 Development team   www.dev.flow.com.au
 FLOW Communications Pty. Ltd.  www.flow.com.au

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Christian Scholz
Hi again!

> Christian Scholz wrote:
> > root_mapper, conns = createMapper(fspath)
> > ei=ExportImport(root_mapper,conns)
> > ei.exportObject(object)
> 
> Ah-ha, I just realized what went wrong.  You need to tell exportObject() 
> where to export.  PathKeychainGenerator refused to guess.  Try changing 
> the last line to:
> 
>  ei.exportObject(object, keychain=('some/path/under/fspath',))

I now tested it and had the following results:

- the last item of the path needs to be the same id as the object has
- only objects derived from Objectmanager in the end can be serialized.
- they are not written to disk as long as I don't do

conns['fs'].vote()
conns['fs'].finish()

After that it worked quite well :)

I now did the import the other way round with

obj=ei.importObject(keychain)

and then using _setObject with that object in order to store it again
in the usual ZODB (Data.fs). Is this ok? Or do I again need to do some copy?

> It's still obtuse.  I'll think about how to make that cleaner.

Well, for me the whole thing actually is magic. But maybe it helps
if there is an example of usage in the docstring. 

But it seems working now, so fine :-)

Thanks again!

Christian

-- 
COM.lounge  http://comlounge.net/
communication & design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] oh boy [id,getId() madness]

2003-06-11 Thread Chris McDonough
On Wed, 2003-06-11 at 14:13, Romain Slootmaekers wrote:
> 
> The questions are:
>- has anyone else experienced this ?

Yes...

>- what could be causing this ?

Assigning an object a different id than that passed to its constructor,
e.g.:

object = anobject(id='id')
folder._setObject('anotherid', object)




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] oh boy [id,getId() madness]

2003-06-11 Thread Stefan H. Holek
This is definitely possible. You probably have a faulty factory method. In 
Zope, construction is a two step process that looks something like

 def addSomething(self, id, title=''):
 ob = Something(id, title)
 self._setObject(id, ob)
An ObjectManager must know the ids of its subobjects and stores them in the 
_objects attribute.

Hm, _setObject() returns the id the object was actually added to the OM 
with. I think it is allowed to return a different id from the one which got 
passed in (but it never does that as far as I can tell).

Hope this helps,
Stefan
--On Mittwoch, 11. Juni 2003 20:13 +0200 Romain Slootmaekers 
<[EMAIL PROTECTED]> wrote:

Yo,
I have an error in this code fragment:
-  fragment --
for childObject in container.objectValues():
 id=childObject.getId()
 childObject2=container[id] # sometimes gives a KeyError 
 #...
- /fragment --
So it means that there are contained objects with an getId member that
returns something different than the key that is used for these objects
in the container object.
As it turns out, I indeed have such objects in my ZODB, and they cause
all kinds of problems (fe, you can't rename them with the management
interface)
The questions are:
   - has anyone else experienced this ?
   - what could be causing this ?


--
The time has come to start talking about whether the emperor is as well
dressed as we are supposed to think he is.   /Pete McBreen/
___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] oh boy [id,getId() madness]

2003-06-11 Thread Romain Slootmaekers
Yo,
I have an error in this code fragment:
-  fragment --
for childObject in container.objectValues():
id=childObject.getId()
childObject2=container[id] # sometimes gives a KeyError 
#...
- /fragment --
So it means that there are contained objects with an getId member that 
returns something different than the key that is used for these objects 
in the container object.

As it turns out, I indeed have such objects in my ZODB, and they cause 
all kinds of problems (fe, you can't rename them with the management 
interface)

The questions are:
  - has anyone else experienced this ?
  - what could be causing this ?
TIA,

Romain.





___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] what is manage_workspace supposed to do?

2003-06-11 Thread Oliver Bleutgen
Dieter Maurer wrote:
Oliver Bleutgen wrote at 2003-6-10 14:54 +0200:
 > ...
 > (*) if m.find('/'):
 >  raise 'Redirect', (
 >  "%s/%s" % (REQUEST['URL1'], m))
 >   return getattr(self, m)(self, REQUEST)
 > 
 > My question is about the marked block. I'd guess that the intent is to 
 > send a redirect if m (== options[0]['action']) contains a '/'.
 > 
 > But m.find('/') evaluates to false only if m[0] == '/', otherwise it 
 > yields either -1 (which is true), if there's no '/' in m, or something 
 > greater 0, if there's a slash after the first char.
 > 
 > Is this intended behavior or a bug?

It probably a bug. But one, that usually only adds an unnecessary
"redirect".
Usually, but not when m.find('/') == 0, which OTOH happens if you want 
to give nice, secure absolute paths to the methods.
The attribute error you get in that case is quite irritating.

I'll stick it in the collectior.

thanks,
oliver
___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
root_mapper, conns = createMapper(fspath)
ei=ExportImport(root_mapper,conns)
ei.exportObject(object)
Ah-ha, I just realized what went wrong.  You need to tell exportObject() 
where to export.  PathKeychainGenerator refused to guess.  Try changing 
the last line to:

ei.exportObject(object, keychain=('some/path/under/fspath',))

It's still obtuse.  I'll think about how to make that cleaner.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
I actually now have a (as it seems) working version of my first
approach, just using _setObject() etc. which even works recursively.
Has this some drawbacks except it looks a bit like a hack due to the
call of commit()?
I also have the deserialization working and basically it's just a 
copying between two ZODBs I'd say.
This will work if you duplicate the objects first.  apelib.zodb3.utils 
has a copyOf() function that reliably duplicates ZODB objects.

Doing it this way uses the whole ZODB machinery to import/export. 
There's nothing wrong with that other than it being a lot of extra work.

Unfortunately this results in an exception 

   Type: MappingError
   Error Value: Path keychains require a name
So can maybe somebody point me to the easiest way to serialize an object
using the fsmapper (Shane? ;-) ?
You're on the right track.  I wonder what went wrong.


I looked into that a bit and in core/io.py line 316 you do

   return kgen.makeKeychain(event, None, 1)

so name is None here as it seems. I just dunno if it's a special case
because I was doing something wrong or not ;-)
It's intentional, but perhaps it needs to explain itself better.  It's 
trying to figure out what OID to assign an object and there isn't enough 
information available.

(and the best would be of course some simple methods for reading/writing
a whole directory recursively. I don't know if something like this is already
in there somehow or how it works internally.. seems all a bit magic to me ;-)
Again, ExportImport is designed to do this.


Will it also do it recursively? I found out that when I do it via
folder._setObject() it will also serialize all content which is quite
nice :)
Yes, it's recursive.

What is actually the result of an export? Where in the fs is it stored then?
Is the whole path to the object in ZODB is taken ?
I don't know where it would try to export--I haven't thought about that 
yet. ;-)

But thanks for the answer and thanks for Ape! :)
You're welcome!

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Christian Scholz
Hi!

I actually now have a (as it seems) working version of my first
approach, just using _setObject() etc. which even works recursively.
Has this some drawbacks except it looks a bit like a hack due to the
call of commit()?
I also have the deserialization working and basically it's just a 
copying between two ZODBs I'd say.

On Wed, Jun 11, 2003 at 10:12:46AM -0400, Shane Hathaway wrote:
> Christian Scholz wrote:
> > I then detected the fascades in io.py which I tried to use (dunno if they're
> > thought to be used for such a purpose actually ;-):
> > 
> > root_mapper, conns = createMapper(fspath)
> > ei=ExportImport(root_mapper,conns)
> > ei.exportObject(object)
> 
> This is *exactly* the purpose ExportImport is meant for, but it's quite 
> new and unfinished.  I'm glad you found it, although it's only in CVS, 
> not in the released version of Ape.

Well, I am looking a bit on the repository and was reading
log messages ;-)

> > Unfortunately this results in an exception 
> > 
> > Type: MappingError
> > Error Value: Path keychains require a name
> > 
> > So can maybe somebody point me to the easiest way to serialize an object
> > using the fsmapper (Shane? ;-) ?
> 
> You're on the right track.  I wonder what went wrong.

I looked into that a bit and in core/io.py line 316 you do

   return kgen.makeKeychain(event, None, 1)

so name is None here as it seems. I just dunno if it's a special case
because I was doing something wrong or not ;-)

> > I am also interested in reading a serialized object from the fs again
> > and writing it to the fs. Also I wonder if I need to delete objects which
> > have been modified before another export or if there's a possibility to
> > just change it).
> 
> Ape will assign new OIDs on import, so you don't have to delete objects 
> first.

Well, at least with my first approach I need to do that because I just
do a folder._setObject() and this fails then of course.

> > (and the best would be of course some simple methods for reading/writing
> > a whole directory recursively. I don't know if something like this is already
> > in there somehow or how it works internally.. seems all a bit magic to me ;-)
> 
> Again, ExportImport is designed to do this.

Will it also do it recursively? I found out that when I do it via
folder._setObject() it will also serialize all content which is quite
nice :)
What is actually the result of an export? Where in the fs is it stored then?
Is the whole path to the object in ZODB is taken ?

But thanks for the answer and thanks for Ape! :)

-- christian

-- 
COM.lounge  http://comlounge.net/
communication & design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
I then detected the fascades in io.py which I tried to use (dunno if they're
thought to be used for such a purpose actually ;-):
root_mapper, conns = createMapper(fspath)
ei=ExportImport(root_mapper,conns)
ei.exportObject(object)
This is *exactly* the purpose ExportImport is meant for, but it's quite 
new and unfinished.  I'm glad you found it, although it's only in CVS, 
not in the released version of Ape.

Unfortunately this results in an exception 

Type: MappingError
Error Value: Path keychains require a name
So can maybe somebody point me to the easiest way to serialize an object
using the fsmapper (Shane? ;-) ?
You're on the right track.  I wonder what went wrong.

I am also interested in reading a serialized object from the fs again
and writing it to the fs. Also I wonder if I need to delete objects which
have been modified before another export or if there's a possibility to
just change it).
Ape will assign new OIDs on import, so you don't have to delete objects 
first.

(and the best would be of course some simple methods for reading/writing
a whole directory recursively. I don't know if something like this is already
in there somehow or how it works internally.. seems all a bit magic to me ;-)
Again, ExportImport is designed to do this.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] serialization with Ape

2003-06-11 Thread Christian Scholz
Hi list! :)

I am just playing around with Ape (very cool, btw :) and wondering
how it can be used from the outside, e.g. not controlled by transactions.
Main idea is to manually copy parts of the ZODB to the filesystem (from
a product).

I first tried the transaction based process, as I found it in
some tests:

# init (createMapper imported from fsmapper)
root_mapper, conns = createMapper(fspath)
conn=conns['fs']
resource = StaticResource(root_mapper)
storage = ApeStorage(resource, conns)
db = ApeDB(storage, resource)
get_transaction().begin()

# test object to store
object = getattr(self,'standard_template.pt')

c=db.open()
app=c.root()['Application']
id=object.getId()
app._setObject(id,object.aq_base,set_owner=0)
get_transaction().commit()
db.close()

which actually stores it but does not seem to me that clean because of
all the transaction stuff. I would here then recursively run through
all the objects and do that inside one transaction.

I then detected the fascades in io.py which I tried to use (dunno if they're
thought to be used for such a purpose actually ;-):

root_mapper, conns = createMapper(fspath)
ei=ExportImport(root_mapper,conns)
ei.exportObject(object)

Unfortunately this results in an exception 

Type: MappingError
Error Value: Path keychains require a name

So can maybe somebody point me to the easiest way to serialize an object
using the fsmapper (Shane? ;-) ?

I am also interested in reading a serialized object from the fs again
and writing it to the fs. Also I wonder if I need to delete objects which
have been modified before another export or if there's a possibility to
just change it).

(and the best would be of course some simple methods for reading/writing
a whole directory recursively. I don't know if something like this is already
in there somehow or how it works internally.. seems all a bit magic to me ;-)

So thanks in advance if anybody can help me :)

cheers,
  Christian

-- 
COM.lounge  http://comlounge.net/
communication & design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )