[Zope3-checkins] CVS: Zope3/src/zope/fssync - fssync.py:1.13

Guido van Rossum guido@python.org
Tue, 13 May 2003 16:56:45 -0400


Update of /cvs-repository/Zope3/src/zope/fssync
In directory cvs.zope.org:/tmp/cvs-serv12148

Modified Files:
	fssync.py 
Log Message:
Implement recursive diffing of directories, don't diff files that
don't differ, skip files that were added or removed, and raise
explicit exceptions about missing or non-file originals.


=== Zope3/src/zope/fssync/fssync.py 1.12 => 1.13 ===
--- Zope3/src/zope/fssync/fssync.py:1.12	Tue May 13 16:28:01 2003
+++ Zope3/src/zope/fssync/fssync.py	Tue May 13 16:56:44 2003
@@ -398,14 +398,35 @@
 
     def diff(self, target, mode=1, diffopts=""):
         assert mode == 1, "modes 2 and 3 are not yet supported"
+        entry = self.metadata.getentry(target)
+        if not entry:
+            raise Error("diff target '%s' doesn't exist", target)
+        if entry.get("flag"):
+            raise Error("diff target '%s' is added or deleted", target)
         if isdir(target):
-            raise Error("recursive diff not yet supported")
+            self.dirdiff(target, mode, diffopts)
+            return
+        if not isfile(target):
+            raise Error("diff target '%s' is file nor directory", target)
         head, tail = self.split(target)
         orig = join(head, "@@Zope", "Original", tail)
+        if not isfile(orig):
+            raise Error("can't find original for diff target '%s'", target)
+        if self.cmp(target, orig):
+            return
         print "Index:", target
         sys.stdout.flush()
         os.system("diff %s %s %s" %
                   (diffopts, commands.mkarg(orig), commands.mkarg(target)))
+
+    def dirdiff(self, target, mode=1, diffopts=""):
+        assert isdir(target)
+        names = self.metadata.getnames(target)
+        for name in names:
+            t = join(target, name)
+            e = self.metadata.getentry(t)
+            if e and not e.get("flag"):
+                self.diff(t, mode, diffopts)
 
     def add(self, path):
         if not exists(path):