From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A45E713800E for ; Mon, 23 Jul 2012 07:52:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 36F34E077A; Mon, 23 Jul 2012 07:52:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0372BE077A for ; Mon, 23 Jul 2012 07:52:24 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 203F41B400B for ; Mon, 23 Jul 2012 07:52:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 8F9DBE5436 for ; Mon, 23 Jul 2012 07:52:21 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1343029811.679747aba189dfc0b24bc37ebb23268f799c8a41.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/output.py X-VCS-Directories: pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 679747aba189dfc0b24bc37ebb23268f799c8a41 X-VCS-Branch: master Date: Mon, 23 Jul 2012 07:52:21 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2c9c8f60-4024-45fb-b2e7-45f3f677977d X-Archives-Hash: 032c099af5a9c0b67bef72321c4ee7c6 commit: 679747aba189dfc0b24bc37ebb23268f799c8a41 Author: Corentin Chary iksaif net> AuthorDate: Mon Jul 23 07:46:26 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Jul 23 07:50:11 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=679747ab output: allow to use stderr in TermProgressBar --- pym/portage/output.py | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pym/portage/output.py b/pym/portage/output.py index 07e25af..b813a39 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -425,16 +425,16 @@ class StyleWriter(formatter.DumbWriter): if self.style_listener: self.style_listener(styles) -def get_term_size(): +def get_term_size(fd=sys.stdout): """ Get the number of lines and columns of the tty that is connected to - stdout. Returns a tuple of (lines, columns) or (0, 0) if an error + fd. Returns a tuple of (lines, columns) or (0, 0) if an error occurs. The curses module is used if available, otherwise the output of `stty size` is parsed. The lines and columns values are guaranteed to be greater than or equal to zero, since a negative COLUMNS variable is known to prevent some commands from working (see bug #394091). """ - if not (sys.stdout.isatty() or sys.stderr.isatty()): + if not hasattr(fd, 'isatty') or not fd.isatty(): return (0, 0) try: import curses @@ -707,10 +707,10 @@ class ProgressBar(object): class TermProgressBar(ProgressBar): """A tty progress bar similar to wget's.""" - def __init__(self, **kwargs): + def __init__(self, fd=sys.stdout, **kwargs): ProgressBar.__init__(self, **kwargs) - lines, self.term_columns = get_term_size() - self.file = sys.stdout + lines, self.term_columns = get_term_size(fd) + self.file = fd self._min_columns = 11 self._max_columns = 80 # for indeterminate mode, ranges from 0.0 to 1.0