BinpkgFetcher: ust pty like EbuildFetcher
authorZac Medico <zmedico@gentoo.org>
Wed, 19 Jan 2011 17:57:02 +0000 (09:57 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 19 Jan 2011 17:57:02 +0000 (09:57 -0800)
pym/_emerge/BinpkgFetcher.py

index 9876cf444ae4811f0d21e2b52877d403ff65d410..942bcdf705e7295d3b0fd3e05d17d1ab798f5609 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.AsynchronousLock import AsynchronousLock
@@ -11,6 +11,7 @@ import stat
 import sys
 import portage
 from portage import os
+from portage.util._pty import _create_pty_or_pipe
 
 if sys.hexversion >= 0x3000000:
        long = int
@@ -101,6 +102,20 @@ class BinpkgFetcher(SpawnProcess):
                self.env = fetch_env
                SpawnProcess._start(self)
 
+       def _pipe(self, fd_pipes):
+               """When appropriate, use a pty so that fetcher progress bars,
+               like wget has, will work properly."""
+               if self.background or not sys.stdout.isatty():
+                       # When the output only goes to a log file,
+                       # there's no point in creating a pty.
+                       return os.pipe()
+               stdout_pipe = None
+               if not self.background:
+                       stdout_pipe = fd_pipes.get(1)
+               got_pty, master_fd, slave_fd = \
+                       _create_pty_or_pipe(copy_term_size=stdout_pipe)
+               return (master_fd, slave_fd)
+
        def _set_returncode(self, wait_retval):
                SpawnProcess._set_returncode(self, wait_retval)
                if not self.pretend and self.returncode == os.EX_OK: