[Checkins] SVN: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ Added support for avoiding conflicts after commit in metadata files.

Amos Latteier amos at latteier.com
Tue Mar 10 15:51:48 EDT 2009


Log message for revision 97816:
  Added support for avoiding conflicts after commit in metadata files. 
  This change requires recent changes in zope.fssync.
  
  The test demonstrates the change.
  

Changed:
  U   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py
  U   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.txt
  U   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/main.py

-=-
Modified: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py	2009-03-10 19:28:57 UTC (rev 97815)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py	2009-03-10 19:51:48 UTC (rev 97816)
@@ -315,7 +315,8 @@
 
 class FSSync(object):
 
-    def __init__(self, metadata=None, network=None, rooturl=None):
+    def __init__(self, metadata=None, network=None, rooturl=None,
+                 overwrite_local=False):
         if metadata is None:
             metadata = Metadata()
         if network is None:
@@ -323,7 +324,8 @@
         self.metadata = metadata
         self.network = network
         self.network.setrooturl(rooturl)
-        self.fsmerger = FSMerger(self.metadata, self.reporter)
+        self.fsmerger = FSMerger(self.metadata, self.reporter,
+                                 overwrite_local)
 
     def login(self, url=None, user=None):
         scheme, host_port, user = self.get_login_info(url, user)

Modified: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.txt
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.txt	2009-03-10 19:28:57 UTC (rev 97815)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.txt	2009-03-10 19:51:48 UTC (rev 97816)
@@ -360,6 +360,116 @@
     SynchronizationError: object already exists 'test'
 
 
+Let's test changing metadata.
+
+First let's examine an existing metadata file.
+
+    >>> path = (os.path.join(localdir, '@@Zope', 'Extra', 'file1.txt',
+    ...     'contentType'))
+    >>> open(path).read()
+    '<?xml version="1.0" encoding="utf-8" ?>\n<pickle> <string>text/plain</string> </pickle>\n'
+
+Now let's change it.
+
+    >>> f = open(path, 'w')
+    >>> f.write('<?xml version="1.0" encoding="utf-8" ?>\n<pickle>\n')
+    >>> f.write('<string>text/html</string>\n</pickle>\n')
+    >>> f.close()
+
+Now we commit our changes.
+
+    >>> zsync.update(localdir)
+    BeforeTraverseEvent None
+    BeforeTraverseEvent test
+    BeforeTraverseEvent toFS.snarf
+    EndRequestEvent show
+    M .../test/@@Zope/Extra/file1.txt/contentType
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    U .../test/@@Zope/Annotations/file2.txt/zope.app.dublincore.ZopeDublinCore
+    U .../test/@@Zope/Annotations/file3.txt/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+    >>> zsync.commit(localdir)
+    BeforeTraverseEvent None
+    BeforeTraverseEvent test
+    BeforeTraverseEvent fromFS.snarf
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent file1.txt Attributes
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    EndRequestEvent run
+    C .../test/@@Zope/Extra/file1.txt/contentType
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+The problem is that we formatted the XML slightly differently than the
+synchronizer does. Thus the client thinks there's a conflict after the
+commit. The solution is to set overwrite_local to True on the FSSync's
+merger object. (This is normally done in the FSSync constructor, but
+we'll do it manually in this test.)
+
+Let's return things to how they were.
+
+    >>> zsync.revert(path)
+    Reverted .../test/@@Zope/Extra/file1.txt/contentType
+
+    >>> serverfile1.contentType = 'text/plain'
+    >>> zsync.update(localdir)
+    BeforeTraverseEvent None
+    BeforeTraverseEvent test
+    BeforeTraverseEvent toFS.snarf
+    EndRequestEvent show
+    U .../test/@@Zope/Extra/file1.txt/contentType
+    All done.
+
+Make our metadata change again.
+
+    >>> f = open(path, 'w')
+    >>> f.write('<?xml version="1.0" encoding="utf-8" ?>\n<pickle>\n')
+    >>> f.write('<string>text/html</string>\n</pickle>\n')
+    >>> f.close()
+    >>> zsync.update(localdir)
+    BeforeTraverseEvent None
+    BeforeTraverseEvent test
+    BeforeTraverseEvent toFS.snarf
+    EndRequestEvent show
+    M .../test/@@Zope/Extra/file1.txt/contentType
+    All done.
+
+Now we commit again, but this time using overwrite_local.
+
+    >>> zsync.fsmerger.overwrite_local = True
+    >>> zsync.commit(localdir)
+    BeforeTraverseEvent None
+    BeforeTraverseEvent test
+    BeforeTraverseEvent fromFS.snarf
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent file1.txt Attributes
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    ObjectModifiedEvent  ObjectSynchronized
+    EndRequestEvent run
+    U .../test/@@Zope/Extra/file1.txt/contentType
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+Let's confirm that the change was made.
+
+    >>> serverfile1.contentType
+    'text/html'
+
+Also, note that our metadata file was overwritten with the server verion.
+
+    >>> open(path).read()
+    '<?xml version="1.0" encoding="utf-8" ?>/n<pickle> <string>text/html</string> </pickle>/n'
+
 Clean up
 --------
 

Modified: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/main.py
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/main.py	2009-03-10 19:28:57 UTC (rev 97815)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/main.py	2009-03-10 19:51:48 UTC (rev 97816)
@@ -127,7 +127,7 @@
     for o, a in opts:
         if o in ("-r", "--raise-on-conflicts"):
             raise_on_conflicts = True
-    fs = FSSync()
+    fs = FSSync(overwrite_local=True)
     fs.multiple(args, fs.commit, message, raise_on_conflicts)
 
 def update(opts, args):
@@ -287,7 +287,7 @@
             raise Usage("checkin requires at most one TARGETDIR argument")
     else:
         target = os.curdir
-    fs = FSSync(rooturl=rooturl)
+    fs = FSSync(rooturl=rooturl, overwrite_local=True)
     fs.checkin(target, message)
 
 def login(opts, args):



More information about the Checkins mailing list