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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/naclports/source_package.py ('k') | requirements.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Native Client Authors. All rights reserved. 1 # Copyright 2014 The Native Client Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import fcntl 5 import fcntl
6 import hashlib 6 import hashlib
7 import os 7 import os
8 import shutil 8 import shutil
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import termcolor
11 12
12 from naclports import error, paths 13 from naclports import error, paths
13 14
14 GS_URL = 'http://storage.googleapis.com/' 15 GS_URL = 'http://storage.googleapis.com/'
15 GS_BUCKET = 'naclports' 16 GS_BUCKET = 'naclports'
16 GS_MIRROR_URL = '%s%s/mirror' % (GS_URL, GS_BUCKET) 17 GS_MIRROR_URL = '%s%s/mirror' % (GS_URL, GS_BUCKET)
17 18
18 arch_to_pkgarch = { 19 arch_to_pkgarch = {
19 'x86_64': 'x86-64', 20 'x86_64': 'x86-64',
20 'i686': 'i686', 21 'i686': 'i686',
21 'arm': 'arm', 22 'arm': 'arm',
22 'pnacl': 'pnacl', 23 'pnacl': 'pnacl',
23 } 24 }
24 25
25 # Inverse of arch_to_pkgarch 26 # Inverse of arch_to_pkgarch
26 pkgarch_to_arch = {v:k for k, v in arch_to_pkgarch.items()} 27 pkgarch_to_arch = {v:k for k, v in arch_to_pkgarch.items()}
27 28
28 verbose = False 29 verbose = False
30 color_mode = 'auto'
31
32 def Color(message, color):
33 if Color.enabled:
34 return termcolor.colored(message, color)
35 else:
36 return message
37
38
39 def CheckStdoutForColorSupport():
40 if color_mode == 'auto':
41 Color.enabled = sys.stdout.isatty()
29 42
30 43
31 def Memoize(f): 44 def Memoize(f):
32 """Memoization decorator for functions taking one or more arguments.""" 45 """Memoization decorator for functions taking one or more arguments."""
33 class Memo(dict): 46 class Memo(dict):
34 def __init__(self, f): 47 def __init__(self, f):
35 super(Memo, self).__init__() 48 super(Memo, self).__init__()
36 self.f = f 49 self.f = f
37 50
38 def __call__(self, *args): 51 def __call__(self, *args):
(...skipping 10 matching lines...) Expand all
49 global verbose 62 global verbose
50 verbose = verbosity 63 verbose = verbosity
51 64
52 65
53 def Log(message): 66 def Log(message):
54 """Log a message to the console (stdout).""" 67 """Log a message to the console (stdout)."""
55 sys.stdout.write(str(message) + '\n') 68 sys.stdout.write(str(message) + '\n')
56 sys.stdout.flush() 69 sys.stdout.flush()
57 70
58 71
72 def LogHeading(message, suffix=''):
73 """Log a colored/highlighted message with optional suffix."""
74 if Color.enabled:
75 Log(Color(message, 'green') + suffix)
76 else:
77 if verbose:
78 # When running in verbose mode make sure heading standout
79 Log('###################################################################')
80 Log(message + suffix)
81 Log('###################################################################')
82 else:
83 Log(message + suffix)
84
85
59 def Warn(message): 86 def Warn(message):
60 Log('warning: ' + message) 87 Log('warning: ' + message)
61 88
62 89
63 def Trace(message): 90 def Trace(message):
64 """Log a message to the console if running in verbose mode (-v).""" 91 """Log a message to the console if running in verbose mode (-v)."""
65 if verbose: 92 if verbose:
66 Log(message) 93 Log(message)
67 94
68 95
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 This file is written at install time. 264 This file is written at install time.
238 """ 265 """
239 root = GetInstallStampRoot(config) 266 root = GetInstallStampRoot(config)
240 return os.path.join(root, package_name + '.list') 267 return os.path.join(root, package_name + '.list')
241 268
242 269
243 def IsInstalled(package_name, config, stamp_content=None): 270 def IsInstalled(package_name, config, stamp_content=None):
244 """Returns True if the given package is installed.""" 271 """Returns True if the given package is installed."""
245 stamp = GetInstallStamp(package_name, config) 272 stamp = GetInstallStamp(package_name, config)
246 result = CheckStamp(stamp, stamp_content) 273 result = CheckStamp(stamp, stamp_content)
247 Trace("IsInstalled: %s -> %s" % (package_name, result))
248 return result 274 return result
249 275
250 276
251 def CheckSDKRoot(): 277 def CheckSDKRoot():
252 """Check validity of NACL_SDK_ROOT.""" 278 """Check validity of NACL_SDK_ROOT."""
253 root = GetSDKRoot() 279 root = GetSDKRoot()
254 if not root: 280 if not root:
255 raise error.Error('$NACL_SDK_ROOT not set') 281 raise error.Error('$NACL_SDK_ROOT not set')
256 282
257 if not os.path.isdir(root): 283 if not os.path.isdir(root):
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 """Lock used when building a package (essentially a lock on OUT_DIR)""" 370 """Lock used when building a package (essentially a lock on OUT_DIR)"""
345 def __init__(self): 371 def __init__(self):
346 super(BuildLock, self).__init__(paths.OUT_DIR) 372 super(BuildLock, self).__init__(paths.OUT_DIR)
347 373
348 374
349 class InstallLock(Lock): 375 class InstallLock(Lock):
350 """Lock used when installing/uninstalling package""" 376 """Lock used when installing/uninstalling package"""
351 def __init__(self, config): 377 def __init__(self, config):
352 root = GetInstallRoot(config) 378 root = GetInstallRoot(config)
353 super(InstallLock, self).__init__(root) 379 super(InstallLock, self).__init__(root)
380
381
382 CheckStdoutForColorSupport()
OLDNEW
« 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