From f1fcf9f2bd149351f15d83595ad4988fd84e7f0e Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Mon, 11 Jan 2010 19:45:03 +0000 Subject: [PATCH] Merged from trunk -r15189:15192 | 15190 | Tweak TERM usage in xtermTitleReset() to match that in | | zmedico | xtermTitle(). | | 15191 | Bug #300388 - Fix terminal handling code to so term codes | | zmedico | aren't sent when TERM=dumb. | | 15192 | Avoid potential UnicodeDecodeError with Python 3. Reported | | arfrever | by devurandom. | svn path=/main/branches/prefix/; revision=15193 --- bin/check-implicit-pointer-usage.py | 7 ++++++- bin/ebuild | 1 + bin/emaint | 2 +- bin/repoman | 1 + pym/_emerge/JobStatusDisplay.py | 4 +++- pym/_emerge/actions.py | 9 ++++++--- pym/_emerge/main.py | 4 +++- pym/portage/getbinpkg.py | 2 +- pym/portage/output.py | 5 ++++- 9 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bin/check-implicit-pointer-usage.py b/bin/check-implicit-pointer-usage.py index 844ea8184..302939a1f 100755 --- a/bin/check-implicit-pointer-usage.py +++ b/bin/check-implicit-pointer-usage.py @@ -19,6 +19,8 @@ from __future__ import print_function import re import sys +from portage import _unicode_decode + implicit_pattern = re.compile("([^:]*):(\d+): warning: implicit declaration " + "of function [`']([^']*)'") pointer_pattern = re.compile( @@ -37,7 +39,10 @@ last_implicit_linenum = -1 last_implicit_func = "" while True: - line = sys.stdin.readline() + if sys.hexversion >= 0x3000000: + line = _unicode_decode(sys.stdin.buffer.readline()) + else: + line = sys.stdin.readline() if line == '': break # translate unicode open/close quotes to ascii ones diff --git a/bin/ebuild b/bin/ebuild index dee8fe41f..9b64f42cd 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -90,6 +90,7 @@ if debug and "python-trace" in portage.features: if not opts.color == 'y' and \ (opts.color == 'n' or \ portage.settings.get('NOCOLOR') in ('yes', 'true') or \ + portage.settings.get('TERM') == 'dumb' or \ not sys.stdout.isatty()): portage.output.nocolor() portage.settings.unlock() diff --git a/bin/emaint b/bin/emaint index 05a08b623..73c6924bd 100755 --- a/bin/emaint +++ b/bin/emaint @@ -538,7 +538,7 @@ def emaint_main(myargv): status = "Attempting to fix %s" func = "fix" - isatty = sys.stdout.isatty() + isatty = os.environ.get('TERM') != 'dumb' and sys.stdout.isatty() for task in tasks: print(status % task.name()) inst = task() diff --git a/bin/repoman b/bin/repoman index 1eb6ea7d4..c181bf73f 100755 --- a/bin/repoman +++ b/bin/repoman @@ -94,6 +94,7 @@ repoman_settings = portage.config(local_config=False, repoman_settings.lock() if repoman_settings.get("NOCOLOR", "").lower() in ("yes", "true") or \ + repoman_settings.get('TERM') == 'dumb' or \ not sys.stdout.isatty(): nocolor() diff --git a/pym/_emerge/JobStatusDisplay.py b/pym/_emerge/JobStatusDisplay.py index dfc766d26..83603ed87 100644 --- a/pym/_emerge/JobStatusDisplay.py +++ b/pym/_emerge/JobStatusDisplay.py @@ -55,7 +55,9 @@ class JobStatusDisplay(object): object.__setattr__(self, "_jobs_column_width", width - 32) self.reset() - isatty = hasattr(self.out, "isatty") and self.out.isatty() + isatty = os.environ.get('TERM') != 'dumb' and \ + hasattr(self.out, 'isatty') and \ + self.out.isatty() object.__setattr__(self, "_isatty", isatty) if not isatty or not self._init_term(): term_codes = {} diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index bc0dea2ff..c72c8255b 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -1467,8 +1467,10 @@ def action_metadata(settings, portdb, myopts, porttrees=None): porttrees = [tree_data.path for tree_data in porttrees_data] - isatty = sys.stdout.isatty() - quiet = not isatty or '--quiet' in myopts + quiet = settings.get('TERM') == 'dumb' or \ + '--quiet' in myopts or \ + not sys.stdout.isatty() + onProgress = None if not quiet: progressBar = portage.output.TermProgressBar() @@ -2437,7 +2439,8 @@ def adjust_config(myopts, settings): portage.output.havecolor = 0 settings["NOCOLOR"] = "true" settings.backup_changes("NOCOLOR") - elif not sys.stdout.isatty() and settings.get("NOCOLOR") != "no": + elif settings.get('TERM') == 'dumb' or \ + not sys.stdout.isatty(): portage.output.havecolor = 0 settings["NOCOLOR"] = "true" settings.backup_changes("NOCOLOR") diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index bc02874f2..af4ec2e9c 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -1325,7 +1325,9 @@ def emerge_main(): portage.debug.set_trace(True) if not ("--quiet" in myopts): - if not sys.stdout.isatty() or ("--nospinner" in myopts): + if '--nospinner' in myopts or \ + settings.get('TERM') == 'dumb' or \ + not sys.stdout.isatty(): spinner.update = spinner.update_basic if myaction == 'version': diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 8fcb02288..fd89d9b37 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -639,7 +639,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= self.out.flush() cache_stats = CacheStats(out) - have_tty = out.isatty() + have_tty = os.environ.get('TERM') != 'dumb' and out.isatty() if have_tty: cache_stats.display() binpkg_filenames = set() diff --git a/pym/portage/output.py b/pym/portage/output.py index 0d5437f8d..6caf47c19 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -270,7 +270,10 @@ def xtermTitleReset(): if prompt_command == "": default_xterm_title = "" elif prompt_command is not None: - if dotitles and "TERM" in os.environ and sys.stderr.isatty(): + if dotitles and \ + 'TERM' in os.environ and \ + _legal_terms_re.match(os.environ['TERM']) is not None and \ + sys.stderr.isatty(): from portage.process import find_binary, spawn shell = os.environ.get("SHELL") if not shell or not os.access(shell, os.EX_OK): -- 2.26.2