Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 29 | 30 |
| 30 | 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 CheckForColorSupport(): | |
| 40 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
| |
| 41 CheckForColorSupport() | |
| 42 | |
| 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): |
| 39 return self[args] | 52 return self[args] |
| 40 | 53 |
| 41 def __missing__(self, key): | 54 def __missing__(self, key): |
| 42 ret = self[key] = self.f(*key) | 55 ret = self[key] = self.f(*key) |
| 43 return ret | 56 return ret |
| 44 | 57 |
| 45 return Memo(f) | 58 return Memo(f) |
| 46 | 59 |
| 47 | 60 |
| 48 def SetVerbose(verbosity): | 61 def SetVerbose(verbosity): |
| 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 message with optional suffix.""" | |
| 74 if Color.enabled: | |
| 75 Log(Color(message, 'green') + suffix) | |
| 76 else: | |
| 77 Log('#####################################################################') | |
| 78 Log(message + suffix) | |
| 79 Log('#####################################################################') | |
| 80 | |
| 81 | |
| 59 def Warn(message): | 82 def Warn(message): |
| 60 Log('warning: ' + message) | 83 Log('warning: ' + message) |
| 61 | 84 |
| 62 | 85 |
| 63 def Trace(message): | 86 def Trace(message): |
| 64 """Log a message to the console if running in verbose mode (-v).""" | 87 """Log a message to the console if running in verbose mode (-v).""" |
| 65 if verbose: | 88 if verbose: |
| 66 Log(message) | 89 Log(message) |
| 67 | 90 |
| 68 | 91 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 This file is written at install time. | 260 This file is written at install time. |
| 238 """ | 261 """ |
| 239 root = GetInstallStampRoot(config) | 262 root = GetInstallStampRoot(config) |
| 240 return os.path.join(root, package_name + '.list') | 263 return os.path.join(root, package_name + '.list') |
| 241 | 264 |
| 242 | 265 |
| 243 def IsInstalled(package_name, config, stamp_content=None): | 266 def IsInstalled(package_name, config, stamp_content=None): |
| 244 """Returns True if the given package is installed.""" | 267 """Returns True if the given package is installed.""" |
| 245 stamp = GetInstallStamp(package_name, config) | 268 stamp = GetInstallStamp(package_name, config) |
| 246 result = CheckStamp(stamp, stamp_content) | 269 result = CheckStamp(stamp, stamp_content) |
| 247 Trace("IsInstalled: %s -> %s" % (package_name, result)) | |
| 248 return result | 270 return result |
| 249 | 271 |
| 250 | 272 |
| 251 def CheckSDKRoot(): | 273 def CheckSDKRoot(): |
| 252 """Check validity of NACL_SDK_ROOT.""" | 274 """Check validity of NACL_SDK_ROOT.""" |
| 253 root = GetSDKRoot() | 275 root = GetSDKRoot() |
| 254 if not root: | 276 if not root: |
| 255 raise error.Error('$NACL_SDK_ROOT not set') | 277 raise error.Error('$NACL_SDK_ROOT not set') |
| 256 | 278 |
| 257 if not os.path.isdir(root): | 279 if not os.path.isdir(root): |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 """Lock used when building a package (essentially a lock on OUT_DIR)""" | 366 """Lock used when building a package (essentially a lock on OUT_DIR)""" |
| 345 def __init__(self): | 367 def __init__(self): |
| 346 super(BuildLock, self).__init__(paths.OUT_DIR) | 368 super(BuildLock, self).__init__(paths.OUT_DIR) |
| 347 | 369 |
| 348 | 370 |
| 349 class InstallLock(Lock): | 371 class InstallLock(Lock): |
| 350 """Lock used when installing/uninstalling package""" | 372 """Lock used when installing/uninstalling package""" |
| 351 def __init__(self, config): | 373 def __init__(self, config): |
| 352 root = GetInstallRoot(config) | 374 root = GetInstallRoot(config) |
| 353 super(InstallLock, self).__init__(root) | 375 super(InstallLock, self).__init__(root) |
| OLD | NEW |