[Commits] (morgen) A first attempt at resolving a VersionConflict error

commits at osafoundation.org commits at osafoundation.org
Tue Jul 27 12:46:47 PDT 2004


Commit by: morgen
Modified files:
chandler/application/Application.py 1.255 1.256
chandler/parcels/osaf/views/main/Main.py 1.21 1.22
chandler/repository/persistence/XMLRepositoryView.py 1.45 1.46

Log message:
A first attempt at resolving a VersionConflict error

Now if the IMAP Account is modified in another thread while the "Edit
Mail account" dialog is open, the resulting version conflict is handled
by cancelling the transaction, reapplying the values from the dialog,
and recommitting.

Also fixed a typo in XMLRepositoryView.py


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/application/Application.py.diff?r1=text&tr1=1.255&r2=text&tr2=1.256
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/views/main/Main.py.diff?r1=text&tr1=1.21&r2=text&tr2=1.22
http://cvs.osafoundation.org/index.cgi/chandler/repository/persistence/XMLRepositoryView.py.diff?r1=text&tr1=1.45&r2=text&tr2=1.46

Index: chandler/parcels/osaf/views/main/Main.py
diff -u chandler/parcels/osaf/views/main/Main.py:1.21 chandler/parcels/osaf/views/main/Main.py:1.22
--- chandler/parcels/osaf/views/main/Main.py:1.21	Mon Jul 26 16:06:05 2004
+++ chandler/parcels/osaf/views/main/Main.py	Tue Jul 27 12:46:45 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.21 $"
-__date__ = "$Date: 2004/07/26 23:06:05 $"
+__version__ = "$Revision: 1.22 $"
+__date__ = "$Date: 2004/07/27 19:46:45 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -14,6 +14,7 @@
 from osaf.mail.IMAPMailTask import IMAPDownloader
 import osaf.framework.utils.imports.OutlookContacts as OutlookContacts
 import osaf.contentmodel.tests.GenerateItems as GenerateItems
+from repository.persistence.RepositoryError import VersionConflictError
 
 class MainView(View):
     """
@@ -42,17 +43,50 @@
         notification.data ['Enable'] = False
 
     def onEditMailAccountEvent (self, notification):
+        account = \
+         Globals.repository.findPath('//parcels/osaf/mail/IMAPAccount One')
         if application.Application.promptForItemValues(
          Globals.wxApplication.mainFrame,
          "IMAP Account",
-         Globals.repository.findPath('//parcels/osaf/mail/IMAPAccount One'),
+         account,
          [
            { "attr":"serverName", "label":"IMAP Server" },
            { "attr":"accountName", "label":"Username" },
            { "attr":"password", "label":"Password", "password":True },
          ]
         ):
-            Globals.repository.commit()
+            try:
+                Globals.repository.commit()
+            except VersionConflictError, e:
+                # A first experiment with resolving conflicts.  Not sure
+                # yet where the logic for handling this should live.  Could
+                # be here, could be handled by the conflicting item itself(?).
+
+                # Retrieve the conflicting item
+                conflict = e.getItem()
+                itemPath = conflict.itsPath
+                serverName = conflict.serverName
+                accountName = conflict.accountName
+                password = conflict.password
+                print "Got a conflict with item:", itemPath
+                # The conflict item has *our* values in it; to see the
+                # values that were committed by the other thread, we need
+                # to cancel our transaction, commit, and refetch the item.
+                Globals.repository.cancel()
+                # Get the latest items committed from other threads
+                Globals.repository.commit()
+                # Refetch item
+                account = Globals.repository.findPath(itemPath)
+                # To resolve this conflict we're going to simply reapply the 
+                # values that were set in the dialog box.
+                account.serverName = serverName
+                account.accountName = accountName
+                account.password = password
+                Globals.repository.commit()
+                # Note: this commit, too, could get a conflict I suppose, so
+                # do we need to put this sort of conflict resolution in a loop?
+                print "Conflict resolved"
+
 
 
     def onGetNewMailEvent (self, notification):

Index: chandler/application/Application.py
diff -u chandler/application/Application.py:1.255 chandler/application/Application.py:1.256
--- chandler/application/Application.py:1.255	Mon Jul 26 16:06:04 2004
+++ chandler/application/Application.py	Tue Jul 27 12:46:44 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.255 $"
-__date__ = "$Date: 2004/07/26 23:06:04 $"
+__version__ = "$Revision: 1.256 $"
+__date__ = "$Date: 2004/07/27 19:46:44 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -543,7 +543,7 @@
         sizer = wx.BoxSizer(wx.VERTICAL)
 
         textControls = []
-        for (valueDict) in attrList:
+        for valueDict in attrList:
             box = wx.BoxSizer(wx.HORIZONTAL)
 
             label = wx.StaticText(self, -1, valueDict["label"])

Index: chandler/repository/persistence/XMLRepositoryView.py
diff -u chandler/repository/persistence/XMLRepositoryView.py:1.45 chandler/repository/persistence/XMLRepositoryView.py:1.46
--- chandler/repository/persistence/XMLRepositoryView.py:1.45	Wed Jul 21 14:32:29 2004
+++ chandler/repository/persistence/XMLRepositoryView.py	Tue Jul 27 12:46:45 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.45 $"
-__date__      = "$Date: 2004/07/21 21:32:29 $"
+__revision__  = "$Revision: 1.46 $"
+__date__      = "$Date: 2004/07/27 19:46:45 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -63,7 +63,7 @@
                 item.setDirty(0)
                 item._unloadItem()
 
-        for item in self._log():
+        for item in self._log:
             if not item.isNew():
                 self.logger.debug('reloading version %d of %s',
                                   self.version, item)



More information about the Commits mailing list