[Zope3-checkins] CVS: Zope3/src/zope/fssync - fsmerger.py:1.2 fssync.py:1.19 fsutil.py:1.2 main.py:1.14

Guido van Rossum guido@python.org
Thu, 15 May 2003 11:32:24 -0400


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

Modified Files:
	fsmerger.py fssync.py fsutil.py main.py 
Log Message:
Add 'status' command which shows local status.
Move 'nczope' variable to fsutil.py.


=== Zope3/src/zope/fssync/fsmerger.py 1.1 => 1.2 ===
--- Zope3/src/zope/fssync/fsmerger.py:1.1	Wed May 14 18:16:09 2003
+++ Zope3/src/zope/fssync/fsmerger.py	Thu May 15 11:32:23 2003
@@ -138,9 +138,8 @@
         names = {}
         names.update(lnames)
         names.update(rnames)
-        nczope = normcase("@@Zope")
-        if nczope in names:
-            del names[nczope]
+        if fsutil.nczope in names:
+            del names[fsutil.nczope]
 
         ncnames = names.keys()
         ncnames.sort()


=== Zope3/src/zope/fssync/fssync.py 1.18 => 1.19 ===
--- Zope3/src/zope/fssync/fssync.py:1.18	Wed May 14 21:58:01 2003
+++ Zope3/src/zope/fssync/fssync.py	Thu May 15 11:32:23 2003
@@ -11,7 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-"""Support classes for fssync.
+"""Highest-level classes to support filesystem synchronization:
+
+class Network -- handle network connection
+class FSSync  -- implement various commands (checkout, commit etc.)
 
 $Id$
 """
@@ -436,3 +439,70 @@
         else:
             entry["flag"] = "removed"
         self.metadata.flush()
+
+    def status(self, target, descend_only=False):
+        entry = self.metadata.getentry(target)
+        flag = entry.get("flag")
+        if isfile(target):
+            if not entry:
+                print "?", target
+            elif flag == "added":
+                print "A", target
+            elif flag == "removed":
+                print "R(reborn)", target
+            else:
+                original = fsutil.getoriginal(target)
+                if isfile(original):
+                    if filecmp.cmp(target, original):
+                        print "=", target
+                    else:
+                        print "M", target
+                else:
+                    print "M(lost-original)", target
+        elif isdir(target):
+            pname = join(target, "")
+            if not entry:
+                if not descend_only:
+                    print "?", pname
+            elif flag == "added":
+                print "A", pname
+            elif flag == "removed":
+                print "R(reborn)", pname
+            else:
+                print "/", pname
+            if entry:
+                # Recurse down the directory
+                namesdir = {}
+                for name in os.listdir(target):
+                    ncname = normcase(name)
+                    if ncname != fsutil.nczope:
+                        namesdir[ncname] = name
+                for name in self.metadata.getnames(target):
+                    ncname = normcase(name)
+                    namesdir[ncname] = name
+                ncnames = namesdir.keys()
+                ncnames.sort()
+                for ncname in ncnames:
+                    self.status(join(target, namesdir[ncname]))
+        elif exists(target):
+            if not entry:
+                print "?", target
+            elif flag:
+                print flag[0].upper() + "(unrecognized)", target
+            else:
+                print "M(unrecognized)", target
+        else:
+            if not entry:
+                print "nonexistent", target
+            elif flag == "removed":
+                print "R", target
+            elif flag == "added":
+                print "A(lost)", target
+            else:
+                print "lost", target
+        annotations = fsutil.getannotations(target)
+        if isdir(annotations):
+            self.status(annotations, True)
+        extra = fsutil.getextra(target)
+        if isdir(extra):
+            self.status(extra, True)


=== Zope3/src/zope/fssync/fsutil.py 1.1 => 1.2 ===
--- Zope3/src/zope/fssync/fsutil.py:1.1	Wed May 14 18:16:09 2003
+++ Zope3/src/zope/fssync/fsutil.py	Thu May 15 11:32:23 2003
@@ -25,7 +25,8 @@
 - ensuredir(dir)
 
 Variables:
-- unwanted -- a sequence containing the pseudo path components "", ".", ".."
+- unwanted -- the tuple ("", os.curdir, os.pardir)
+- nczope   -- the string os.path.normcase("@@Zope")
 
 $Id$
 """
@@ -74,6 +75,8 @@
         return "%s%r" % (self.__class__.__name__, (self.msg,)+self.args)
 
 unwanted = ("", os.curdir, os.pardir)
+
+nczope = os.path.normcase("@@Zope")
 
 def getoriginal(path):
     """Return the path of the Original file corresponding to path."""


=== Zope3/src/zope/fssync/main.py 1.13 => 1.14 ===
--- Zope3/src/zope/fssync/main.py:1.13	Wed May 14 21:13:49 2003
+++ Zope3/src/zope/fssync/main.py	Thu May 15 11:32:23 2003
@@ -20,6 +20,7 @@
 fssync [global_options] update [local_options] [TARGET ...]
 fssync [global_options] commit [local_options] [TARGET ...]
 fssync [global_options] diff [local_options] [TARGET ...]
+fssync [global_options] status [local_options] [TARGET ...]
 fssync [global_options] add [local_options] TARGET ...
 fssync [global_options] remove [local_options] TARGET ...
 
@@ -29,7 +30,8 @@
 
 ``fssync -h'' prints the global help (this message)
 ``fssync command -h'' prints the local help for the command
-
+"""
+"""
 $Id$
 """
 
@@ -243,6 +245,14 @@
         fs.diff(arg, mode, diffopts)
     fs.multiple(args, calldiff)
 
+def status(opts, args):
+    """fssync status [TARGET ...]
+
+    Print brief (local) status for each target, without changing any files.
+    """
+    fs = FSSync()
+    fs.multiple(args, fs.status)
+
 command_table = {
     "checkout": ("", [], checkout),
     "co":       ("", [], checkout),
@@ -253,6 +263,7 @@
     "rm":       ("", [], remove),
     "r":        ("", [], remove),
     "diff":     ("bBcC:iuU:", ["brief", "context=", "unified="], diff),
+    "status":   ("", [], status),
     }
 
 if __name__ == "__main__":