Hi, Over the last month or so, I've rather wonderfully managed to corrupt my ZODB with artifacts of my Currency class that no longer exist. This is due to: (i) moving the module to a different package (twice) (ii) renaming the module (iii) changing it's inheritance hierarchy (having removed all Zope-awareness from class has caused loads of setstate issues in regard to either __basicnew__ not found, AttributeErrors, and problems with non-derivation from AcquireImplicitWrapper) I now desperately need to write a parser to convert all of these nasties to ZCurrency types. I've come up with the following ExternalMethod - whereby I've defined a __currency__ attribute in each obselete incantation's product (Currency object's are used in the spirit of DateTime rather than within ObjectManager containment structures): from Acquisition import aq_base from Products.BastionBanking.ZCurrency import ZCurrency def repair(container, counter=0): for (k,v) in container.__dict__.items(): if hasattr(v, '__currency__'): setattr(container, k, ZCurrency(v._currency, v._amount)) counter += 1 for object in container.objectValues(): for (k,v) in object.__dict__.items(): if hasattr(v, '__currency__'): setattr(object, k, ZCurrency(v._currency, v._amount)) counter += 1 if hasattr(aq_base(object), 'objectValues'): repair(object, counter) return counter However, it doesn't seem to find anything to convert. Does anyone have any ideas? TIA, Alan _________________________________________________________________ Surf the net and talk on the phone with Xtra Jetstream @ http://www.xtra.co.nz/products/0,,5803,00.html !
I now desperately need to write a parser to convert all of these nasties to ZCurrency types. I've come up with the following ExternalMethod - whereby I've defined a __currency__ attribute in each obselete incantation's product (Currency object's are used in the spirit of DateTime rather than within ObjectManager containment structures):
Attributes added to product code are not automatically present in the objects defined by that code, only those created by that code. Methods, however, will be present on all instances of a given class. I won't bother to connect the dots for you. Are you sure that you have a product for all those potential orphans out there? Otherwise, the above won't work: you'll need to look for distinct signature somehow, presuming those objects even function: I don't know how true orphans behave.
from Acquisition import aq_base from Products.BastionBanking.ZCurrency import ZCurrency
def repair(container, counter=0): for (k,v) in container.__dict__.items(): if hasattr(v, '__currency__'): setattr(container, k, ZCurrency(v._currency, v._amount)) counter += 1
for object in container.objectValues(): for (k,v) in object.__dict__.items(): if hasattr(v, '__currency__'): setattr(object, k, ZCurrency(v._currency, v._amount)) counter += 1 if hasattr(aq_base(object), 'objectValues'): repair(object, counter) return counter
I'll trust that your __dict__ stuff up there works: never tried it myself. --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
alan milligan wrote at 2003-11-2 14:13 +0000:
... I now desperately need to write a parser to convert all of these nasties to ZCurrency types. I've come up with the following ExternalMethod - whereby I've defined a __currency__ attribute in each obselete incantation's product ... def repair(container, counter=0): ... counter += 1 ... repair(object, counter) return counter ... However, it doesn't seem to find anything to convert. Does anyone have any ideas?
"counter" is an integer and integers are immutable. Therefore, "counter += 1" does not change the integer object but assigns a new one to "counter". This change is local to the "repair" incarnation. The "counter" in the caller is not changed. -- Dieter
participants (3)
-
alan milligan -
Dieter Maurer -
J. Cameron Cooper