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

Guido van Rossum guido@python.org
Sat, 10 May 2003 20:16:07 -0400


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

Modified Files:
	fssync.py main.py 
Log Message:
Add a primitive 'add' facility to fssync.

=== Zope3/src/zope/fssync/fssync.py 1.1 => 1.2 ===
--- Zope3/src/zope/fssync/fssync.py:1.1	Fri May  9 16:54:15 2003
+++ Zope3/src/zope/fssync/fssync.py	Sat May 10 20:16:06 2003
@@ -126,6 +126,8 @@
             raise Error("zip command failed")
         zipdata = self.readfile(zipfile, "rb")
         os.unlink(zipfile)
+        # XXX Use urllib2 and then set Content-type header.
+        # That should take care of proxies and https.
         h = httplib.HTTP(host_port)
         h.putrequest("POST", url + "/@@fromFS.zip")
         h.putheader("Content-Type", "application/zip")
@@ -182,6 +184,36 @@
         finally:
             os.unlink(filename)
 
+    def add(self, path):
+        path = realpath(path)
+        if not exists(path):
+            raise Error("nothing known about '%s'", path)
+        dir, name = split(path)
+        if name in ("", os.curdir, os.pardir):
+            raise Error("can't add path '%s'", path)
+        entries = self.loadentries(dir)
+        if name in entries:
+            raise Error("path '%s' is already registered", name)
+        pdir = self.parent(dir)
+        dname = basename(dir)
+        pentries = self.loadentries(pdir)
+        if dname not in pentries:
+            raise Error("directory '%s' unknown", dname)
+        dpath = pentries[dname]['path']
+        if dpath == "/":
+            ourpath = "/" + name
+        else:
+            ourpath = dpath + "/" + name
+        entries[name] = d = {"path": ourpath, "flag": "added"}
+        if isdir(path):
+            d["type"] = "zope.app.content.folder.Folder"
+        else:
+            # XXX Need to guess better based on extension
+            d["type"] = "zope.app.content.file.File"
+        if "factory" not in d:
+            d["factory"] = str(unicode(d["type"]))
+        self.dumpentries(entries, dir)
+
     def merge(self, ours, server):
         # XXX This method is way too long, and still not complete :-(
         for (left, right, common, lentries, rentries, ldirs, lnondirs,
@@ -230,7 +262,6 @@
                             print "U", lx
                         elif self.cmp(lx, rx):
                             # Only the original is out of date
-                            print "file '%s' already contains changes" % lx
                             self.copyfile(rx, origx)
                             print "U", lx
                         else:


=== Zope3/src/zope/fssync/main.py 1.1 => 1.2 ===
--- Zope3/src/zope/fssync/main.py:1.1	Fri May  9 16:54:15 2003
+++ Zope3/src/zope/fssync/main.py	Sat May 10 20:16:06 2003
@@ -82,6 +82,8 @@
             args = args or [os.curdir]
             [fspath] = args
             commit(fspath)
+        elif command == "add":
+            add(args)
         else:
             raise Usage("command %r not recognized" % command)
     except Usage, msg:
@@ -106,6 +108,11 @@
 def update(fspath):
     fs = FSSync(fspath)
     fs.update()
+
+def add(args):
+    fs = FSSync(os.curdir)
+    for a in args:
+        fs.add(a)
 
 if __name__ == "__main__":
     sys.exit(main(sys.argv))