[Zope3-checkins] CVS: Zope3/src/zope/fssync - fssync.py:1.11 main.py:1.5

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


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

Modified Files:
	fssync.py main.py 
Log Message:
Some refactoring.  Support for 'remove'.

=== Zope3/src/zope/fssync/fssync.py 1.10 => 1.11 ===
--- Zope3/src/zope/fssync/fssync.py:1.10	Tue May 13 15:28:56 2003
+++ Zope3/src/zope/fssync/fssync.py	Tue May 13 16:05:17 2003
@@ -365,14 +365,7 @@
         if not entry:
             raise Error("nothing known about", target)
         self.network.loadrooturl(target)
-        head, tail = split(target)
-        if tail in unwanted:
-            target = realpath(target)
-            head, tail = split(target)
-            if head == target or tail in unwanted:
-                raise Error("target '%s' is the filesystem root", target)
-        if not head:
-            head = os.curdir
+        head, tail = self.split(target)
         path = entry["path"]
         fp, headers = self.network.httpreq(path, "@@toFS.zip")
         try:
@@ -408,14 +401,7 @@
         entry = self.metadata.getentry(path)
         if entry:
             raise Error("path '%s' is already registered", path)
-        head, tail = split(path)
-        if tail in unwanted:
-            path = realpath(path)
-            head, tail = split(path)
-            if head == path or tail in unwanted:
-                raise Error("can't add '%s': it is the filesystem root", path)
-        if not head:
-            head = os.curdir
+        head, tail = self.split(path)
         pentry = self.metadata.getentry(head)
         if not pentry:
             raise Error("can't add '%s': its parent is not registered", path)
@@ -436,6 +422,21 @@
             entry["factory"] = str(unicode(entry["type"]))
         self.metadata.flush()
 
+    def remove(self, path):
+        if exists(path):
+            raise Error("'%s' still exists", path)
+        entry = self.metadata.getentry(path)
+        if not entry:
+            raise Error("nothing known about '%s'", path)
+        zpath = entry.get("path")
+        if not zpath:
+            raise Error("can't remote '%s': its zope path is unknown", path)
+        if entry.get("flag") == "added":
+            entry.clear()
+        else:
+            entry["flag"] = "removed"
+        self.metadata.flush()
+
     def merge_dirs(self, localdir, remotedir):
         if not isdir(remotedir):
             return
@@ -550,3 +551,14 @@
     def ensuredir(self, dir):
         if not isdir(dir):
             os.makedirs(dir)
+
+    def split(self, path):
+        head, tail = split(path)
+        if tail in unwanted:
+            newpath = realpath(path)
+            head, tail = split(newpath)
+            if head == newpath or tail in unwanted:
+                raise Error("path '%s' is the filesystem root", path)
+        if not head:
+            head = os.curdir
+        return head, tail


=== Zope3/src/zope/fssync/main.py 1.4 => 1.5 ===
--- Zope3/src/zope/fssync/main.py:1.4	Tue May 13 15:16:59 2003
+++ Zope3/src/zope/fssync/main.py	Tue May 13 16:05:17 2003
@@ -117,7 +117,15 @@
         return None
 
 def checkout(opts, args):
-    rooturl, target = args
+    if not args:
+        raise Usage("commit requires a URL argument")
+    rooturl = args[0]
+    if len(args) > 1:
+        target = args[0]
+        if len(args) > 2:
+            raise Usage("commit requires at most one TARGETDIR argument")
+    else:
+        target = os.curdir
     fs = FSSync(rooturl=rooturl)
     fs.checkout(target)
 
@@ -134,11 +142,20 @@
     for a in args:
         fs.add(a)
 
+def remove(opts, args):
+    fs = FSSync()
+    for a in args:
+        fs.remove(a)
+
 command_table = {
     "checkout": ("", [], checkout),
+    "co":       ("", [], checkout),
     "update":   ("", [], update),
     "commit":   ("", [], commit),
     "add":      ("", [], add),
+    "remove":   ("", [], remove),
+    "rm":       ("", [], remove),
+    "r":        ("", [], remove),
     }
 
 if __name__ == "__main__":