[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - loader.py:1.6 svnloader.py:1.2

Fred L. Drake, Jr. fred at zope.com
Mon Apr 26 13:09:23 EDT 2004


Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv30479/zpkgtools

Modified Files:
	loader.py svnloader.py 
Log Message:
add the option to load from Subversion; this does not re-write URLs to
accomodate tags yet


=== Packages/zpkgtools/zpkgtools/loader.py 1.5 => 1.6 ===
--- Packages/zpkgtools/zpkgtools/loader.py:1.5	Mon Apr 26 11:21:27 2004
+++ Packages/zpkgtools/zpkgtools/loader.py	Mon Apr 26 13:09:22 2004
@@ -47,6 +47,7 @@
         self.tag = tag or None
         self.workdirs = {}  # URL -> (tmp.directory, path, istemporary)
         self.cvsloader = None
+        self.svnloader = None
 
     def add_working_dir(self, url, directory, path, istemporary):
         self.workdirs[url] = (directory, path, istemporary)
@@ -138,7 +139,7 @@
 
     def load_file(self, url):
         if svnloader.is_subversion_url(url):
-            raise NotImplementedError("loading from Subversion isn't done yet")
+            return self.load_svn(url)
         parts = urlparse.urlsplit(url)
         path = urllib.url2pathname(parts[2])
         if not os.path.exists(path):
@@ -149,13 +150,7 @@
     def load_cvs(self, url):
         if self.cvsloader is None:
             self.cvsloader = cvsloader.CvsLoader()
-        # If we've already loaded this, use that copy.  This doesn't
-        # consider fetching something with a different path that's
-        # represented by a previous load():
-        if url in self.workdirs:
-            return self.workdirs[url][1]
-
-        tmp = tempfile.mkdtemp(prefix="loader-")
+        tmp = tempfile.mkdtemp(prefix="cvsloader-")
         parsed_url = cvsloader.parse(url)
         path = self.cvsloader.load(parsed_url, tmp)
         self.add_working_dir(url, tmp, path, True)
@@ -164,6 +159,17 @@
     def load_repository(self, url):
         raise ValueError("repository: URLs must be joined with an"
                          " appropriate revision-control base URL")
+
+    def load_svn(self, url):
+        if self.svnloader is None:
+            self.svnloader = svnloader.SubversionLoader()
+        tmp = tempfile.mkdtemp(prefix="svnloader-")
+        path = self.svnloader.load(url, tmp)
+        self.add_working_dir(url, tmp, path, True)
+        return path
+
+    def load_svn_ssh(self, url):
+        return self.load_svn(url)
 
     def unknown_load(self, url):
         # XXX This could end up being called with an http: or https:


=== Packages/zpkgtools/zpkgtools/svnloader.py 1.1 => 1.2 ===
--- Packages/zpkgtools/zpkgtools/svnloader.py:1.1	Mon Apr 26 11:19:39 2004
+++ Packages/zpkgtools/zpkgtools/svnloader.py	Mon Apr 26 13:09:22 2004
@@ -14,10 +14,29 @@
 """Subversion support functions."""
 
 import os
+import posixpath
 import sys
 import urllib
 import urlparse
 
+from zpkgtools import Error
+
+
+class SubversionLoadingError(Error):
+    """Raised when there was some error loading from Subversion.
+
+    :Ivariables:
+      - `url`: Subversion URL.
+      - `exitcode`: Return code of the Subversion process.
+    """
+
+    def __init__(self, url, exitcode):
+        self.url = cvsurl
+        self.exitcode = exitcode
+        Error.__init__(self, ("could not load from %s (svn exit code %d)"
+                              % (url, exitcode)))
+
+
 if sys.platform[:3].lower() == "win":
     ROOTDIR = "\\"
 else:
@@ -81,3 +100,33 @@
         if not ok:
             return False
     return True
+
+
+class SubversionLoader:
+    # This is really only an object so the API mirrors the CvsLoader.
+    """Simpler loader object that loads from Subversion."""
+
+    def load(self, url, workdir):
+        # do an "svn cat" to get a file, or learn that this is a directory
+        stdin, stdout, stderr = os.popen3("svn cat '%s'" % url)
+        data = stdout.read()
+        if not data:
+            # maybe url referenced a directory
+            err = stderr.readline()
+            if "directory" in err:
+                # it is!
+                target = os.path.join(workdir, "foo")
+                rc = os.system("svn export -q '%s' '%s'" % (url, target))
+                if rc != 0:
+                    raise SubversionLoadingError(url, rc)
+                return target
+            else:
+                # don't know the exit code, so make one up
+                raise SubversionLoadingError(url, 1)
+        else:
+            name = posixpath.basename(url)
+            path = os.path.join(workdir, name)
+            f = open(path, "wb")
+            f.write(data)
+            f.close()
+            return path




More information about the Zope-CVS mailing list