binarytree: handle binhost port for sftp/ssh
authorZac Medico <zmedico@gentoo.org>
Fri, 5 Nov 2010 01:42:58 +0000 (18:42 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 5 Nov 2010 01:42:58 +0000 (18:42 -0700)
pym/portage/dbapi/bintree.py

index 03cfdb1788ffed047b9b4b6eab4aaa24b07148df..ee37218066cafaaf1fef5b21d649260c37d65f49 100644 (file)
@@ -769,20 +769,32 @@ class binarytree(object):
                                        f = urllib_request_urlopen(base_url.rstrip("/") + "/Packages")
                                except IOError:
                                        path = parsed_url.path.rstrip("/") + "/Packages"
+                                       host = parsed_url.netloc
+                                       port = parsed_url.port
+                                       port_args = []
+                                       if port is not None:
+                                               port_str = ":%s" % (port,)
+                                               if host.endswith(port_str):
+                                                       host = host[:-len(port_str)]
+
                                        if parsed_url.scheme == 'sftp':
                                                # The sftp command complains about 'Illegal seek' if
                                                # we try to make it write to /dev/stdout, so use a
                                                # temp file instead.
                                                fd, tmp_filename = tempfile.mkstemp()
                                                os.close(fd)
-                                               proc = subprocess.Popen(['sftp',
-                                                       parsed_url.netloc + ":" + path, tmp_filename])
+                                               if port is not None:
+                                                       port_args = ['-P', port]
+                                               proc = subprocess.Popen(['sftp'] + port_args + \
+                                                       [host + ":" + path, tmp_filename])
                                                if proc.wait() != os.EX_OK:
                                                        raise
                                                f = open(tmp_filename, 'rb')
                                        elif parsed_url.scheme == 'ssh':
-                                               proc = subprocess.Popen(['ssh', parsed_url.netloc, '--',
-                                                       'cat', path], stdout=subprocess.PIPE)
+                                               if port is not None:
+                                                       port_args = ['-p', port]
+                                               proc = subprocess.Popen(['ssh'] + port_args + \
+                                                       [host, '--', 'cat', path], stdout=subprocess.PIPE)
                                                f = proc.stdout
                                        else:
                                                raise