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

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
« no previous file with comments | « lib/naclports/source_package.py ('k') | requirements.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/naclports/util.py
diff --git a/lib/naclports/util.py b/lib/naclports/util.py
index 0aae54584175aa067d3c6259be940b546126c615..4d81ab9f3bacfe482bba969ceb7868a958aeeb94 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
@@ -26,6 +27,18 @@ arch_to_pkgarch = {
pkgarch_to_arch = {v:k for k, v in arch_to_pkgarch.items()}
verbose = False
+color_mode = 'auto'
+
+def Color(message, color):
+ if Color.enabled:
+ return termcolor.colored(message, color)
+ else:
+ return message
+
+
+def CheckStdoutForColorSupport():
+ if color_mode == 'auto':
+ Color.enabled = sys.stdout.isatty()
def Memoize(f):
@@ -56,6 +69,20 @@ def Log(message):
sys.stdout.flush()
+def LogHeading(message, suffix=''):
+ """Log a colored/highlighted message with optional suffix."""
+ if Color.enabled:
+ Log(Color(message, 'green') + suffix)
+ else:
+ if verbose:
+ # When running in verbose mode make sure heading standout
+ Log('###################################################################')
+ Log(message + suffix)
+ Log('###################################################################')
+ else:
+ Log(message + suffix)
+
+
def Warn(message):
Log('warning: ' + message)
@@ -244,7 +271,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
@@ -351,3 +377,6 @@ class InstallLock(Lock):
def __init__(self, config):
root = GetInstallRoot(config)
super(InstallLock, self).__init__(root)
+
+
+CheckStdoutForColorSupport()
« no previous file with comments | « lib/naclports/source_package.py ('k') | requirements.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698