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

Side by Side Diff: lib/naclports/__main__.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/__init__.py ('k') | lib/naclports/binary_package.py » ('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 (c) 2013 The Native Client Authors. All rights reserved. 1 # Copyright (c) 2013 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 """Tool for manipulating naclports packages in python. 5 """Tool for manipulating naclports packages in python.
6 6
7 This tool can be used to for working with naclports packages. 7 This tool can be used to for working with naclports packages.
8 It can also be incorporated into other tools that need to 8 It can also be incorporated into other tools that need to
9 work with packages (e.g. 'update_mirror.py' uses it to iterate 9 work with packages (e.g. 'update_mirror.py' uses it to iterate
10 through all packages and mirror them on Google Cloud Storage). 10 through all packages and mirror them on Google Cloud Storage).
(...skipping 10 matching lines...) Expand all
21 sys.exit(1) 21 sys.exit(1)
22 22
23 import argparse 23 import argparse
24 24
25 sys.path.append(os.path.dirname(os.path.dirname(__file__))) 25 sys.path.append(os.path.dirname(os.path.dirname(__file__)))
26 26
27 from naclports import configuration, error, source_package, util, paths 27 from naclports import configuration, error, source_package, util, paths
28 import naclports.package 28 import naclports.package
29 29
30 30
31 def PrintStatus(msg): 31 def PrintError(msg):
32 sys.stderr.write('naclports: %s\n' % msg) 32 sys.stderr.write('naclports: %s\n' % util.Color(str(msg), 'red'))
33 33
34 34
35 def CmdList(config, options, args): 35 def CmdList(config, options, args):
36 """List installed packages""" 36 """List installed packages"""
37 if len(args): 37 if len(args):
38 raise error.Error('list command takes no arguments') 38 raise error.Error('list command takes no arguments')
39 if options.all: 39 if options.all:
40 iterator = source_package.SourcePackageIterator() 40 iterator = source_package.SourcePackageIterator()
41 else: 41 else:
42 iterator = naclports.package.InstalledPackageIterator(config) 42 iterator = naclports.package.InstalledPackageIterator(config)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 sys.stdout.write(filename + '\n') 77 sys.stdout.write(filename + '\n')
78 78
79 79
80 def CmdPkgDownload(package, options): 80 def CmdPkgDownload(package, options):
81 """Download sources for given package(s)""" 81 """Download sources for given package(s)"""
82 package.Download() 82 package.Download()
83 83
84 84
85 def CmdPkgUscan(package, options): 85 def CmdPkgUscan(package, options):
86 """Use Debian's 'uscan' to check for upstream versions.""" 86 """Use Debian's 'uscan' to check for upstream versions."""
87 if not package.URL:
88 return 0
89
87 if package.VERSION not in package.URL: 90 if package.VERSION not in package.URL:
88 PrintStatus('%s: uscan only works if VERSION is embedded in URL' % 91 PrintError('%s: uscan only works if VERSION is embedded in URL' %
89 package.NAME) 92 package.NAME)
90 return 0 93 return 0
91 94
92 temp_fd, temp_file = tempfile.mkstemp('naclports_watchfile') 95 temp_fd, temp_file = tempfile.mkstemp('naclports_watchfile')
93 try: 96 try:
94 with os.fdopen(temp_fd, 'w') as f: 97 with os.fdopen(temp_fd, 'w') as f:
95 uscan_url = package.URL.replace(package.VERSION, '(.+)') 98 uscan_url = package.URL.replace(package.VERSION, '(.+)')
96 uscan_url = uscan_url.replace('download.sf.net', 'sf.net') 99 uscan_url = uscan_url.replace('download.sf.net', 'sf.net')
97 util.Trace('uscan pattern: %s' % uscan_url) 100 util.Trace('uscan pattern: %s' % uscan_url)
98 f.write("version = 3\n") 101 f.write("version = 3\n")
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 epilog += ' %-12s - %s\n' % (name, function.__doc__) 213 epilog += ' %-12s - %s\n' % (name, function.__doc__)
211 214
212 parser = argparse.ArgumentParser(prog='naclports', description=__doc__, 215 parser = argparse.ArgumentParser(prog='naclports', description=__doc__,
213 formatter_class=argparse.RawDescriptionHelpFormatter, epilog=epilog) 216 formatter_class=argparse.RawDescriptionHelpFormatter, epilog=epilog)
214 parser.add_argument('-v', '--verbose', action='store_true', 217 parser.add_argument('-v', '--verbose', action='store_true',
215 help='Output extra information.') 218 help='Output extra information.')
216 parser.add_argument('-V', '--verbose-build', action='store_true', 219 parser.add_argument('-V', '--verbose-build', action='store_true',
217 help='Make builds verbose (e.g. pass V=1 to make') 220 help='Make builds verbose (e.g. pass V=1 to make')
218 parser.add_argument('--all', action='store_true', 221 parser.add_argument('--all', action='store_true',
219 help='Perform action on all known ports.') 222 help='Perform action on all known ports.')
223 parser.add_argument('--color', choices=('always', 'never', 'auto'),
224 help='Enabled color terminal output', default='auto')
220 parser.add_argument('-f', '--force', action='store_const', const='build', 225 parser.add_argument('-f', '--force', action='store_const', const='build',
221 help='Force building specified targets, ' 226 help='Force building specified targets, '
222 'even if timestamps would otherwise skip it.') 227 'even if timestamps would otherwise skip it.')
223 parser.add_argument('--from-source', action='store_true', 228 parser.add_argument('--from-source', action='store_true',
224 help='Always build from source rather than downloading ' 229 help='Always build from source rather than downloading '
225 'prebuilt packages.') 230 'prebuilt packages.')
226 parser.add_argument('-F', '--force-all', action='store_const', const='all', 231 parser.add_argument('-F', '--force-all', action='store_const', const='all',
227 dest='force', help='Force building target and all ' 232 dest='force', help='Force building target and all '
228 'dependencies, even if timestamps would otherwise skip ' 233 'dependencies, even if timestamps would otherwise skip '
229 'them.') 234 'them.')
(...skipping 20 matching lines...) Expand all
250 if args.verbose_build: 255 if args.verbose_build:
251 os.environ['VERBOSE'] = '1' 256 os.environ['VERBOSE'] = '1'
252 else: 257 else:
253 if 'VERBOSE' in os.environ: 258 if 'VERBOSE' in os.environ:
254 del os.environ['VERBOSE'] 259 del os.environ['VERBOSE']
255 if 'V' in os.environ: 260 if 'V' in os.environ:
256 del os.environ['V'] 261 del os.environ['V']
257 262
258 util.CheckSDKRoot() 263 util.CheckSDKRoot()
259 config = configuration.Configuration(args.arch, args.toolchain, args.debug) 264 config = configuration.Configuration(args.arch, args.toolchain, args.debug)
265 util.color_mode = args.color
266 if args.color == 'never':
267 util.Color.enabled = False
268 elif args.color == 'always':
269 util.Color.enabled = True
260 270
261 if args.command in base_commands: 271 if args.command in base_commands:
262 base_commands[args.command](config, args, args.pkg) 272 base_commands[args.command](config, args, args.pkg)
263 return 0 273 return 0
264 274
265 if args.command not in pkg_commands: 275 if args.command not in pkg_commands:
266 parser.error("Unknown subcommand: '%s'\n" 276 parser.error("Unknown subcommand: '%s'\n"
267 'See --help for available commands.' % args.command) 277 'See --help for available commands.' % args.command)
268 278
269 if len(args.pkg) and args.all: 279 if len(args.pkg) and args.all:
(...skipping 29 matching lines...) Expand all
299 if args.command in installed_pkg_commands: 309 if args.command in installed_pkg_commands:
300 p = naclports.package.CreateInstalledPackage(package_name, config) 310 p = naclports.package.CreateInstalledPackage(package_name, config)
301 else: 311 else:
302 p = source_package.CreatePackage(package_name, config) 312 p = source_package.CreatePackage(package_name, config)
303 DoCmd(p) 313 DoCmd(p)
304 314
305 def main(args): 315 def main(args):
306 try: 316 try:
307 RunMain(args) 317 RunMain(args)
308 except KeyboardInterrupt: 318 except KeyboardInterrupt:
309 PrintStatus('interrupted') 319 PrintError('interrupted')
310 return 1 320 return 1
311 except error.Error as e: 321 except error.Error as e:
312 PrintStatus(str(e)) 322 PrintError(str(e))
313 return 1 323 return 1
314 324
315 return 0 325 return 0
316 326
317 if __name__ == '__main__': 327 if __name__ == '__main__':
318 sys.exit(main(sys.argv[1:])) 328 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « lib/naclports/__init__.py ('k') | lib/naclports/binary_package.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698