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

Side by Side Diff: git_cache.py

Issue 299163002: Add --quiet option. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A git command for managing a local cache of git repositories.""" 6 """A git command for managing a local cache of git repositories."""
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 unlocked_repos)) 489 unlocked_repos))
490 490
491 491
492 class OptionParser(optparse.OptionParser): 492 class OptionParser(optparse.OptionParser):
493 """Wrapper class for OptionParser to handle global options.""" 493 """Wrapper class for OptionParser to handle global options."""
494 494
495 def __init__(self, *args, **kwargs): 495 def __init__(self, *args, **kwargs):
496 optparse.OptionParser.__init__(self, *args, prog='git cache', **kwargs) 496 optparse.OptionParser.__init__(self, *args, prog='git cache', **kwargs)
497 self.add_option('-c', '--cache-dir', 497 self.add_option('-c', '--cache-dir',
498 help='Path to the directory containing the cache') 498 help='Path to the directory containing the cache')
499 self.add_option('-v', '--verbose', action='count', default=0, 499 self.add_option('-v', '--verbose', action='count', default=1,
500 help='Increase verbosity (can be passed multiple times)') 500 help='Increase verbosity (can be passed multiple times)')
501 self.add_option('-q', '--quiet', action='store_true',
502 help='Suppress all extraneous output')
501 503
502 def parse_args(self, args=None, values=None): 504 def parse_args(self, args=None, values=None):
503 options, args = optparse.OptionParser.parse_args(self, args, values) 505 options, args = optparse.OptionParser.parse_args(self, args, values)
506 if options.quiet:
507 options.verbose = 0
508
509 levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
510 logging.basicConfig(level=levels[min(options.verbose, len(levels) - 1)])
504 511
505 try: 512 try:
506 global_cache_dir = Mirror.GetCachePath() 513 global_cache_dir = Mirror.GetCachePath()
507 except RuntimeError: 514 except RuntimeError:
508 global_cache_dir = None 515 global_cache_dir = None
509 if options.cache_dir: 516 if options.cache_dir:
510 if global_cache_dir and ( 517 if global_cache_dir and (
511 os.path.abspath(options.cache_dir) != 518 os.path.abspath(options.cache_dir) !=
512 os.path.abspath(global_cache_dir)): 519 os.path.abspath(global_cache_dir)):
513 logging.warn('Overriding globally-configured cache directory.') 520 logging.warn('Overriding globally-configured cache directory.')
514 Mirror.SetCachePath(options.cache_dir) 521 Mirror.SetCachePath(options.cache_dir)
515 522
516 levels = [logging.WARNING, logging.INFO, logging.DEBUG]
517 logging.basicConfig(level=levels[min(options.verbose, len(levels) - 1)])
518
519 return options, args 523 return options, args
520 524
521 525
522 def main(argv): 526 def main(argv):
523 dispatcher = subcommand.CommandDispatcher(__name__) 527 dispatcher = subcommand.CommandDispatcher(__name__)
524 return dispatcher.execute(OptionParser(), argv) 528 return dispatcher.execute(OptionParser(), argv)
525 529
526 530
527 if __name__ == '__main__': 531 if __name__ == '__main__':
528 sys.exit(main(sys.argv[1:])) 532 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698