[Zope3-checkins] CVS: Zope3/src/zope/app/browser/content - configure.zcml:1.34 fssync.py:1.23

Fred L. Drake, Jr. fred at zope.com
Thu Aug 7 14:04:53 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/content
In directory cvs.zope.org:/tmp/cvs-serv21269

Modified Files:
	configure.zcml fssync.py 
Log Message:
Re-factor SnarfCommit into three classes:
- SnarfSubmission, which has all the common code used for both checkin
  and commit
- SnarfCheckin, for checking in new subtrees
- SnarfCommit, for committing changes to existing tree


=== Zope3/src/zope/app/browser/content/configure.zcml 1.33 => 1.34 ===
--- Zope3/src/zope/app/browser/content/configure.zcml:1.33	Wed Aug  6 10:41:41 2003
+++ Zope3/src/zope/app/browser/content/configure.zcml	Thu Aug  7 13:04:48 2003
@@ -372,14 +372,14 @@
       name="fromFS.snarf"
       permission="zope.ManageServices"
       class="zope.app.browser.content.fssync.SnarfCommit"
-      attribute="commit" />
+      attribute="run" />
 
   <!-- fssync checkin -->
   <page
       for="zope.interface.Interface"
       name="checkin.snarf"
       permission="zope.ManageServices"
-      class="zope.app.browser.content.fssync.SnarfCommit"
-      attribute="checkin" />
+      class="zope.app.browser.content.fssync.SnarfCheckin"
+      attribute="run" />
 
 </configure>


=== Zope3/src/zope/app/browser/content/fssync.py 1.22 => 1.23 ===
--- Zope3/src/zope/app/browser/content/fssync.py:1.22	Wed Aug  6 10:41:41 2003
+++ Zope3/src/zope/app/browser/content/fssync.py	Thu Aug  7 13:04:48 2003
@@ -66,52 +66,21 @@
             entry["flag"] = "added"
         return entry
 
-class SnarfCommit(BrowserView):
-    """View for committing and checking in changes.
 
-    The input to commit() should be a POST request whose data is a
-    snarf archive.  It returns an updated snarf archive, or a text
-    document with errors.
-
-    The alternate entry point checkin() is for checking in a new
-    archive.  It is similar to commit() but creates a brand new tree
-    and doesn't return anything.
-    """
-
-    # XXX Maybe split into two classes with a common base instead?
-
-    def commit(self):
-        self.check_content_type()
-        self.set_transaction()
-        self.parse_args()
-        self.set_note()
-        try:
-            self.make_tempdir()
-            self.set_commit_arguments()
-            self.make_commit_metadata()
-            self.unsnarf_body()
-            self.call_checker()
-            if self.errors:
-                return self.send_errors()
-            else:
-                self.call_committer()
-                self.write_to_filesystem()
-                return self.send_archive()
-        finally:
-            self.remove_tempdir()
+class SnarfSubmission(BrowserView):
+    """Base class for the commit and checkin views."""
 
-    def checkin(self):
+    def run(self):
         self.check_content_type()
         self.set_transaction()
         self.parse_args()
         self.set_note()
         try:
             self.make_tempdir()
-            self.set_checkin_arguments()
-            self.make_checkin_metadata()
+            self.set_arguments()
+            self.make_metadata()
             self.unsnarf_body()
-            self.call_committer()
-            return ""
+            return self.run_submission()
         finally:
             self.remove_tempdir()
 
@@ -144,18 +113,41 @@
         if note:
             self.txn.note(note)
 
-    def set_commit_arguments(self):
-        # Compute self.{name, container, fspath} for commit()
-        self.name = getName(self.context)
-        self.container = getParent(self.context)
-        if self.container is None and self.name == "":
-            # Hack to get loading the root to work
-            self.container = getRoot(self.context)
-            self.fspath = os.path.join(self.tempdir, "root")
-        else:
-            self.fspath = os.path.join(self.tempdir, self.name)
+    tempdir = None
+
+    def make_tempdir(self):
+        self.tempdir = tempfile.mktemp()
+        os.mkdir(self.tempdir)
+
+    def remove_tempdir(self):
+        if self.tempdir and os.path.exists(self.tempdir):
+            shutil.rmtree(self.tempdir)
+
+    def unsnarf_body(self):
+        fp = self.request.bodyFile
+        fp.seek(0)
+        uns = Unsnarfer(fp)
+        uns.unsnarf(self.tempdir)
 
-    def set_checkin_arguments(self):
+    def call_committer(self):
+        c = Committer(self.metadata)
+        c.synch(self.container, self.name, self.fspath)
+
+
+class SnarfCheckin(SnarfSubmission):
+    """View for checking a new sub-tree into Zope.
+
+    The input should be a POST request whose data is a snarf archive.
+    This creates a brand new tree and doesn't return anything.
+    """
+
+    def run_submission(self):
+        # XXX need to make sure the top-level name doesn't already
+        # exist, or existing site data can get screwed
+        self.call_committer()
+        return ""
+
+    def set_arguments(self):
         # Compute self.{name, container, fspath} for checkin()
         name = self.get_arg("name")
         if not name:
@@ -167,27 +159,40 @@
         self.name = name
         self.fspath = os.path.join(self.tempdir, src)
 
-    def make_commit_metadata(self):
-        self.metadata = Metadata()
-
-    def make_checkin_metadata(self):
+    def make_metadata(self):
         self.metadata = NewMetadata()
 
-    tempdir = None
 
-    def make_tempdir(self):
-        self.tempdir = tempfile.mktemp()
-        os.mkdir(self.tempdir)
+class SnarfCommit(SnarfSubmission):
+    """View for committing changes to an existing tree.
 
-    def remove_tempdir(self):
-        if self.tempdir and os.path.exists(self.tempdir):
-            shutil.rmtree(self.tempdir)
+    The input should be a POST request whose data is a snarf archive.
+    It returns an updated snarf archive, or a text document with
+    errors.
+    """
 
-    def unsnarf_body(self):
-        fp = self.request.bodyFile
-        fp.seek(0)
-        uns = Unsnarfer(fp)
-        uns.unsnarf(self.tempdir)
+    def run_submission(self):
+        self.call_checker()
+        if self.errors:
+            return self.send_errors()
+        else:
+            self.call_committer()
+            self.write_to_filesystem()
+            return self.send_archive()
+
+    def set_arguments(self):
+        # Compute self.{name, container, fspath} for commit()
+        self.name = getName(self.context)
+        self.container = getParent(self.context)
+        if self.container is None and self.name == "":
+            # Hack to get loading the root to work
+            self.container = getRoot(self.context)
+            self.fspath = os.path.join(self.tempdir, "root")
+        else:
+            self.fspath = os.path.join(self.tempdir, self.name)
+
+    def make_metadata(self):
+        self.metadata = Metadata()
 
     def call_checker(self):
         if self.get_arg("raise"):
@@ -206,10 +211,6 @@
         lines.append("")
         self.request.response.setHeader("Content-Type", "text/plain")
         return "\n".join(lines)
-
-    def call_committer(self):
-        c = Committer(self.metadata)
-        c.synch(self.container, self.name, self.fspath)
 
     def write_to_filesystem(self):
         shutil.rmtree(self.tempdir) # Start with clean slate




More information about the Zope3-Checkins mailing list