Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: lib/naclports/util.py

Issue 839083003: Add initial support for color output in the build system (Closed) Base URL: https://chromium.googlesource.com/external/naclports.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/naclports/util.py
diff --git a/lib/naclports/util.py b/lib/naclports/util.py
index 0aae54584175aa067d3c6259be940b546126c615..6573b75693b88aeb2297ff3dddcddfacecc18201 100644
--- a/lib/naclports/util.py
+++ b/lib/naclports/util.py
@@ -8,6 +8,7 @@ import os
import shutil
import subprocess
import sys
+import termcolor
from naclports import error, paths
@@ -28,6 +29,18 @@ pkgarch_to_arch = {v:k for k, v in arch_to_pkgarch.items()}
verbose = False
+def Color(message, color):
+ if Color.enabled:
+ return termcolor.colored(message, color)
+ else:
+ return message
+
+
+def CheckForColorSupport():
+ Color.enabled = sys.stdout.isatty()
binji 2015/01/09 18:24:59 Is there a better check here? Not all ttys support
Sam Clegg 2015/01/09 22:14:54 This is the same change that "ls --color=auto" doe
+CheckForColorSupport()
+
+
def Memoize(f):
"""Memoization decorator for functions taking one or more arguments."""
class Memo(dict):
@@ -56,6 +69,16 @@ def Log(message):
sys.stdout.flush()
+def LogHeading(message, suffix=''):
+ """Log a colored message with optional suffix."""
+ if Color.enabled:
+ Log(Color(message, 'green') + suffix)
+ else:
+ Log('#####################################################################')
+ Log(message + suffix)
+ Log('#####################################################################')
+
+
def Warn(message):
Log('warning: ' + message)
@@ -244,7 +267,6 @@ def IsInstalled(package_name, config, stamp_content=None):
"""Returns True if the given package is installed."""
stamp = GetInstallStamp(package_name, config)
result = CheckStamp(stamp, stamp_content)
- Trace("IsInstalled: %s -> %s" % (package_name, result))
return result

Powered by Google App Engine
This is Rietveld 408576698