[Chandler-dev] dump/reload issues

Morgen Sagen morgen at osafoundation.org
Wed Apr 4 11:26:00 PDT 2007

We need to settle on how we're going to dump and reload data that  
lives under //parcels, including preferences information.  Let me  
explain how I am doing things, and we can see if this works for  
everyone else.  (This assumes that the dump code is only going to  
iterate items outside of //parcels, and the logic for doing so is  
moving out of Main.py and into dumpreload.py)

So osaf.sharing has an out-of-the-box (OOTB) Reference item named  
"currentSharingAccount" which has a bi-directional-reference to  
whatever the "current" sharing account item is.  Originally, the OOTB  
sharing account item lived under //parcels.  I recently changed  
sharing/__init__.py to create the OOTB account outside of //parcels  
(//userdata now).  So now that account will get dumped just like any  
other account.

As for sharing preferences, I defined a model.SharePrefsRecord which  
contains the UUID of the "current" sharing account:

    class SharePrefsRecord(eim.Record):
        URI = "http://osafoundation.org/eim/sharing/prefs/0"
        currentAccount = eim.field(schema.UUID) # empty string means  
no account

...and added the following methods to DumpTranslator:

     def import_share_prefs(self, record):

         if record.currentAccount:
             def set_current(account):
                 ref = schema.ns("osaf.sharing",  
                 ref.item = account

     # Called from finishExport()
     def export_share_prefs(self):

         ref = schema.ns("osaf.sharing", self.rv).currentSharingAccount
         if ref.item is None:
             currentAccount = ""
             currentAccount = ref.item.itsUUID.str16()
         cur = ref.item

         yield model.SharePrefsRecord(currentAccount)

Note that export_share_prefs is a regular method called directly from  
DumpTranslator's finishExport( ) method.  The SharePrefsRecord is  
imported using the decorated import_share_prefs method.  Note also  
that since there is ever only one SharePrefsRecord instance, that  
record type doesn't need to have any key fields.

In the future we'll improve the Translator code so that parcels can  
register themselves and get hooked into what the translator is doing,  
but for now just add specific "yield" statements to  
DumpTranslator.finishExport( ).

Sound good?

More information about the chandler-dev mailing list