diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-06-08 19:18:59 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-06-08 19:18:59 +0000 |
commit | 5c67d1d66030fb5e21661155aa01c8b03ea311ac (patch) | |
tree | 456f27ca633d5c222cecfb58b6d228f27d3d50c4 /pym | |
parent | 170795b32a1eb830e519472dc4cca4cc0101865f (diff) | |
download | portage-5c67d1d66030fb5e21661155aa01c8b03ea311ac.tar.gz portage-5c67d1d66030fb5e21661155aa01c8b03ea311ac.tar.bz2 portage-5c67d1d66030fb5e21661155aa01c8b03ea311ac.zip |
For bug #164655, port quickpkg to python and use the tarfile module for proper handling of symlinks to directories. Thanks to Martin Parm <parmus@diku.dk> for the initial port. (trunk r6728)
svn path=/main/branches/2.1.2/; revision=6753
Diffstat (limited to 'pym')
-rw-r--r-- | pym/output.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/pym/output.py b/pym/output.py index 8c8813e42..314674135 100644 --- a/pym/output.py +++ b/pym/output.py @@ -237,6 +237,29 @@ def create_color_func(color_key): for c in compat_functions_colors: setattr(sys.modules[__name__], c, create_color_func(c)) +def get_term_size(): + """ + Get the number of lines and columns of the tty that is connected to + stdout. Returns a tuple of (lines, columns) or (-1, -1) if an error + occurs. The curses module is used if available, otherwise the output of + `stty size` is parsed. + """ + try: + import curses + curses.setupterm() + return curses.tigetnum('lines'), curses.tigetnum('cols') + except ImportError: + pass + st, out = commands.getstatusoutput('stty size') + if st == os.EX_OK: + out = out.split() + if len(out) == 2: + try: + return int(out[0]), int(out[1]) + except ValueError: + pass + return -1, -1 + class EOutput: """ Performs fancy terminal formatting for status and informational messages. @@ -264,17 +287,7 @@ class EOutput: self.__last_e_cmd = "" self.__last_e_len = 0 self.quiet = False - columns = 0 - try: - columns = int(os.getenv("COLUMNS", 0)) - except ValueError: - pass - if columns <= 0: - try: - columns = int(commands.getoutput( - 'set -- `stty size 2>/dev/null` ; echo "$2"')) - except ValueError: - pass + lines, columns = get_term_size() if columns <= 0: columns = 80 # Adjust columns so that eend works properly on a standard BSD console. |