dont break when the binhost url doesn't end with a slash (bug #144440, branches/2...
authorZac Medico <zmedico@gentoo.org>
Mon, 30 Jul 2007 05:03:03 +0000 (05:03 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 30 Jul 2007 05:03:03 +0000 (05:03 -0000)
svn path=/main/branches/2.1.2.9/; revision=7483

pym/getbinpkg.py

index 9484d1d16d0a98cd73e1d148c04d7554c4b4eec9..f57dc859e62928ce475a8bb83e379cca136b1ea1 100644 (file)
@@ -141,15 +141,6 @@ def create_conn(baseurl,conn=None):
                                conn.login(username)
                        conn.set_pasv(passive)
                        conn.set_debuglevel(0)
-               elif protocol == "sftp":
-                       try:
-                               import paramiko
-                       except ImportError:
-                               raise NotImplementedError(
-                                       "paramiko must be installed for sftp support")
-                       t = paramiko.Transport(host)
-                       t.connect(username=username, password=password)
-                       conn = paramiko.SFTPClient.from_transport(t)
                else:
                        raise NotImplementedError, "%s is not a supported protocol." % protocol
 
@@ -316,8 +307,6 @@ def dir_get_list(baseurl,conn=None):
                        del olddir
                else:
                        listing = conn.nlst(address)
-       elif protocol == "sftp":
-               listing = conn.listdir(address)
        else:
                raise TypeError, "Unknown protocol. '%s'" % protocol
 
@@ -343,13 +332,6 @@ def file_get_metadata(baseurl,conn=None, chunk_size=3000):
                data,rc,msg = make_http_request(conn, address, params, headers)
        elif protocol in ["ftp"]:
                data,rc,msg = make_ftp_request(conn, address, -chunk_size)
-       elif protocol == "sftp":
-               f = conn.open(address)
-               try:
-                       f.seek(-chunk_size, 2)
-                       data = f.read()
-               finally:
-                       f.close()
        else:
                raise TypeError, "Unknown protocol. '%s'" % protocol
        
@@ -384,19 +366,28 @@ def file_get(baseurl,dest,conn=None,fcmd=None):
        if not fcmd:
                return file_get_lib(baseurl,dest,conn)
 
-       variables = {
-               "DISTDIR": dest,
-               "URI":     baseurl,
-               "FILE":    os.path.basename(baseurl)
-       }
-       import shlex, StringIO
-       from portage_util import varexpand
-       from portage_exec import spawn
-       lexer = shlex.shlex(StringIO.StringIO(fcmd), posix=True)
-       lexer.whitespace_split = True
-       myfetch = [varexpand(x, mydict=variables) for x in lexer]
-       retval = spawn(myfetch, env=os.environ.copy())
-       if retval != os.EX_OK:
+       fcmd = fcmd.replace("${DISTDIR}",dest)
+       fcmd = fcmd.replace("${URI}", baseurl)
+       fcmd = fcmd.replace("${FILE}", os.path.basename(baseurl))
+       mysplit = fcmd.split()
+       mycmd   = mysplit[0]
+       myargs  = [os.path.basename(mycmd)]+mysplit[1:]
+       mypid=os.fork()
+       if mypid == 0:
+               try:
+                       os.execv(mycmd,myargs)
+               except OSError:
+                       pass
+               sys.stderr.write("!!! Failed to spawn fetcher.\n")
+               sys.stderr.flush()
+               os._exit(1)
+       retval=os.waitpid(mypid,0)[1]
+       if (retval & 0xff) == 0:
+               retval = retval >> 8
+       else:
+               sys.stderr.write("Spawned processes caught a signal.\n")
+               sys.exit(1)
+       if retval != 0:
                sys.stderr.write("Fetcher exited with a failure condition.\n")
                return 0
        return 1
@@ -418,25 +409,6 @@ def file_get_lib(baseurl,dest,conn=None):
                data,rc,msg = make_http_request(conn, address, params, headers, dest=dest)
        elif protocol in ["ftp"]:
                data,rc,msg = make_ftp_request(conn, address, dest=dest)
-       elif protocol == "sftp":
-               rc = 0
-               try:
-                       f = conn.open(address)
-               except SystemExit:
-                       raise
-               except Exception:
-                       rc = 1
-               else:
-                       try:
-                               if dest:
-                                       bufsize = 8192
-                                       while True:
-                                               data = f.read(bufsize)
-                                               if not data:
-                                                       break
-                                               dest.write(data)
-                       finally:
-                               f.close()
        else:
                raise TypeError, "Unknown protocol. '%s'" % protocol
        
@@ -549,7 +521,8 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
        for x in tbz2list:
                x = os.path.basename(x)
                binpkg_filenames.add(x)
-               if x not in metadata[baseurl]["data"]:
+               if ((not metadata[baseurl]["data"].has_key(x)) or \
+                   (x not in metadata[baseurl]["data"].keys())):
                        sys.stderr.write(yellow("x"))
                        metadata[baseurl]["modified"] = 1
                        myid = None