From 518fba727a978e1bc883d179924f535ed7323b33 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 4 Nov 2010 18:42:58 -0700 Subject: binarytree: handle binhost port for sftp/ssh --- pym/portage/dbapi/bintree.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 03cfdb178..ee3721806 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -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 -- cgit v1.2.3-1-g7c22