durusmail: durus-users: renaming module/classes problem
renaming module/classes problem
2005-03-15
2005-03-15
2005-03-15
2005-03-15
2005-03-15
renaming module/classes problem
Mario Ruggier
2005-03-15
Hello,

I am trying to move a durus database file to another module, that is
named differently, and almost identical to original.

I am running the db file thru this script (code is pseudo-ed, somewhat)
:


#### start

# make old names available, with new values

import my.new.module
import my.old.module

old_module_name = my.old.module'
import sys
sys.modules[old_module_name] = my.new.module

for attr in dir(my.old.module):
     setattr(my.old.module, attr, getattr(my.new.module, attr) )

# set _p_changed on all items

mydbcon = 

for name,container in mydbcon.get_root().items():
     print container.__class__
     # always prints: 

     if container._p_connection != mydbcon:
         print '!=', container, container._p_connection
         # never passes here

     for item in container.get_items():
         print item.__class__
         # always prints: 

         item._p_changed = True

         if item._p_connection != mydbcon:
             print '!=', item, item._p_connection
             # never passes here

# save

mydbcon.commit()
mydbcon.pack()

#### end


However, when I try to run a downsized version of the same script, but
using only the new names (and I hide the old module from the path),
thus, the script becomes really trivial:


####
import my.new.module
mydbcon = 
for key in mydbcon.get_root().keys():
     print mydbcon.get_root().get(key).__class__
####


I get the following Traceback:


Traceback (most recent call last):
   File "./update_db_rename.py", line 63, in ?
     for key in mydbcon.get_root().keys():
   File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/durus/persistent.py", line 124, in
_p_load_state
     self._p_connection.load_state(self)
   File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/durus/connection.py", line 154, in load_state
     state = self.reader.get_state(pickle)
   File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/durus/serialize.py", line 134, in get_state
     state = unpickler.load()
ImportError: No module named old.module


If I do not hide the old module, the 2nd script prints a list of:



I have just re-tried the entire process from scratch, after updating to
durus 1.5, with same results. I have no idea what to do here, and have
been trying to understand for a while...

What can i do here?

Thanks, mario


reply