Add support for grabbing Packages files using external programs.
authorDavid James <davidjames@google.com>
Fri, 11 Feb 2011 17:25:26 +0000 (09:25 -0800)
committerZac Medico <zmedico@gentoo.org>
Mon, 14 Feb 2011 03:51:39 +0000 (19:51 -0800)
If the user specifies FETCHCOMMAND_*, Portage should honor this when grabbing
Packages files. This allows users to setup support for grabbing Packages files
from other protocols.

BUG=chrome-os-partner:2026
TEST=Try downloading prebuilts from gs:// when FETCHCOMMAND_GS is setup in make.conf

Change-Id: I96b239819351633dd02d608954e81a1c363a4687

Review URL: http://codereview.chromium.org/6458015

pym/portage/dbapi/bintree.py
pym/portage/getbinpkg.py

index 993df7714d069231d4638949d233fa1c360c76ed..78eb4299982a8fe68b2919ba6af2e07859430e49 100644 (file)
@@ -770,8 +770,9 @@ class binarytree(object):
                                # urlparse.urljoin() only works correctly with recognized
                                # protocols and requires the base url to have a trailing
                                # slash, so join manually...
+                               url = base_url.rstrip("/") + "/Packages"
                                try:
-                                       f = urllib_request_urlopen(base_url.rstrip("/") + "/Packages")
+                                       f = urllib_request_urlopen(url)
                                except IOError:
                                        path = parsed_url.path.rstrip("/") + "/Packages"
 
@@ -796,7 +797,18 @@ class binarytree(object):
                                                        stdout=subprocess.PIPE)
                                                f = proc.stdout
                                        else:
-                                               raise
+                                               setting = 'FETCHCOMMAND_' + parsed_url.scheme.upper()
+                                               fcmd = self.settings.get(setting)
+                                               if not fcmd:
+                                                       raise
+                                               fd, tmp_filename = tempfile.mkstemp()
+                                               tmp_dirname, tmp_basename = os.path.split(tmp_filename)
+                                               os.close(fd)
+                                               success = portage.getbinpkg.file_get(url,
+                                                    tmp_dirname, fcmd=fcmd, filename=tmp_basename)
+                                               if not success:
+                                                       raise portage.exception.FileNotFound(url)
+                                               f = open(tmp_filename, 'rb')
 
                                f_dec = codecs.iterdecode(f,
                                        _encodings['repo.content'], errors='replace')
index f85b65c00a5303b103e1ac516fb7c263d6b4d853..43a6bf5f78e15fc00b642924fd44ea4a804e7673 100644 (file)
@@ -431,17 +431,19 @@ def file_get_metadata(baseurl,conn=None, chunk_size=3000):
        return myid
 
 
-def file_get(baseurl,dest,conn=None,fcmd=None):
+def file_get(baseurl,dest,conn=None,fcmd=None,filename=None):
        """(baseurl,dest,fcmd=) -- Takes a base url to connect to and read from.
        URI should be in the form <proto>://[user[:pass]@]<site>[:port]<path>"""
 
        if not fcmd:
                return file_get_lib(baseurl,dest,conn)
+       if not filename:
+               filename = os.path.basename(baseurl)
 
        variables = {
                "DISTDIR": dest,
                "URI":     baseurl,
-               "FILE":    os.path.basename(baseurl)
+               "FILE":    filename
        }
 
        from portage.util import varexpand