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

Guido van Rossum guido@python.org
Thu, 5 Jun 2003 17:05:50 -0400


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

Modified Files:
	fssync.py main.py 
Log Message:
First attempt at implementing a "checkin" command.  This is the
inverse of "checkout": it pushes a set of filesystem representations
to Zope.  It's still a bit of a hack, but it appears to work.



=== Zope3/src/zope/fssync/fssync.py 1.30 => 1.31 ===
--- Zope3/src/zope/fssync/fssync.py:1.30	Wed Jun  4 17:48:28 2003
+++ Zope3/src/zope/fssync/fssync.py	Thu Jun  5 17:05:49 2003
@@ -160,7 +160,8 @@
             f.close()
 
     def httpreq(self, path, view, datasource=None,
-                content_type="application/x-snarf"):
+                content_type="application/x-snarf",
+                expected_type="application/x-snarf"):
         """Issue an HTTP or HTTPS request.
 
         The request parameters are taken from the root url, except
@@ -221,7 +222,7 @@
             raise Error("HTTP error %s (%s); error document:\n%s",
                         response.status, response.reason,
                         self.slurptext(response.fp, response.msg))
-        elif response.msg["Content-type"] != "application/x-snarf":
+        elif expected_type and response.msg["Content-type"] != expected_type:
             raise Error(self.slurptext(response.fp, response.msg))
         else:
             return response.fp, response.msg
@@ -315,7 +316,7 @@
                     for name in names:
                         method(join(target, name), *more)
 
-    def commit(self, target, note="fssync"):
+    def commit(self, target, note="fssync_commit"):
         entry = self.metadata.getentry(target)
         if not entry:
             raise Error("nothing known about", target)
@@ -329,6 +330,33 @@
             self.merge_snarffile(fp, head, tail)
         finally:
             fp.close()
+
+    def checkin(self, target, note="fssync_checkin"):
+        rootpath = self.network.rootpath
+        if not rootpath:
+            raise Error("root url not set")
+        if rootpath == "/":
+            raise Error("root url should name an inferior object")
+        i = rootpath.rfind("/")
+        path, name = rootpath[:i], rootpath[i+1:]
+        if not path:
+            path = "/"
+        if not name:
+            raise Error("root url should not end in '/'")
+        entry = self.metadata.getentry(target)
+        if not entry:
+            raise Error("nothing known about", target)
+        qnote = urllib.quote(note)
+        qname = urllib.quote(name)
+        head, tail = split(realpath(target))
+        qsrc = urllib.quote(tail)
+        view = "@@checkin.snarf?note=%s&name=%s&src=%s" % (qnote, qname, qsrc)
+        data = DataSource(head, tail)
+        fp, headers = self.network.httpreq(path, view, data,
+                                           expected_type=None)
+        message = self.network.slurptext(fp, headers)
+        if message:
+            print message
 
     def update(self, target):
         entry = self.metadata.getentry(target)


=== Zope3/src/zope/fssync/main.py 1.16 => 1.17 ===
--- Zope3/src/zope/fssync/main.py:1.16	Thu May 29 14:23:34 2003
+++ Zope3/src/zope/fssync/main.py	Thu Jun  5 17:05:49 2003
@@ -23,6 +23,7 @@
 fssync [global_options] status [local_options] [TARGET ...]
 fssync [global_options] add [local_options] TARGET ...
 fssync [global_options] remove [local_options] TARGET ...
+fssync [global_options] checkin [local_options] URL [TARGETDIR]
 
 ``fssync -h'' prints the global help (this message)
 ``fssync command -h'' prints the local help for the command
@@ -38,7 +39,7 @@
 from os.path import dirname, join, realpath
 
 # Find the zope root directory.
-# XXX This assumes this script is <root>/src/zope/fssync/sync.py
+# XXX This assumes this script is <root>/src/zope/fssync/main.py
 scriptfile = sys.argv[0]
 scriptdir = realpath(dirname(scriptfile))
 rootdir = dirname(dirname(dirname(scriptdir)))
@@ -171,7 +172,7 @@
     The -m option specifies a message to label the transaction.
     The default message is 'fssync'.
     """
-    message = "fssync"
+    message = "fssync_commit"
     for o, a in opts:
         if o in ("-m", "--message"):
             message = a
@@ -258,6 +259,37 @@
     fs = FSSync()
     fs.multiple(args, fs.status)
 
+def checkin(opts, args):
+    """checkin [-m message] URL [TARGETDIR]
+
+    URL should be of the form ``http://user:password@host:port/path''.
+    Only http and https are supported (and https only where Python has
+    been built to support SSL).  This should identify a Zope 3 server;
+    user:password should have management privileges; /path should be
+    the traversal path to a non-existing object, not including views
+    or skins.
+
+    TARGETDIR should be a directory; it defaults to the current
+    directory.  The object tree rooted at TARGETDIR is copied to
+    /path.  subdirectory of TARGETDIR whose name is the last component
+    of /path.
+    """
+    message = "fssync_checkin"
+    for o, a in opts:
+        if o in ("-m", "--message"):
+            message = a
+    if not args:
+        raise Usage("checkin requires a URL argument")
+    rooturl = args[0]
+    if len(args) > 1:
+        target = args[1]
+        if len(args) > 2:
+            raise Usage("checkin requires at most one TARGETDIR argument")
+    else:
+        target = os.curdir
+    fs = FSSync(rooturl=rooturl)
+    fs.checkin(target, message)
+
 command_table = {
     "checkout": ("", [], checkout),
     "co":       ("", [], checkout),
@@ -269,6 +301,8 @@
     "r":        ("", [], remove),
     "diff":     ("bBcC:iuU:", ["brief", "context=", "unified="], diff),
     "status":   ("", [], status),
+    "checkin":  ("m:", ["message="], checkin),
+    "ci":       ("m:", ["message="], checkin),
     }
 
 if __name__ == "__main__":