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

Side by Side Diff: gclient.py

Issue 20131006: Revert "Improve description layout. Improve coloring and add legend in help." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 4 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 | « commit_queue.py ('k') | git_cl.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Meta checkout manager supporting both Subversion and GIT. 6 """Meta checkout manager supporting both Subversion and GIT.
7 7
8 Files 8 Files
9 .gclient : Current client configuration, written by 'config' command. 9 .gclient : Current client configuration, written by 'config' command.
10 Format is a Python script defining 'solutions', a list whose 10 Format is a Python script defining 'solutions', a list whose
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 progress=not options.no_progress) 1372 progress=not options.no_progress)
1373 1373
1374 1374
1375 @attr('usage', '[args ...]') 1375 @attr('usage', '[args ...]')
1376 def CMDfetch(parser, args): 1376 def CMDfetch(parser, args):
1377 """Fetches upstream commits for all modules. 1377 """Fetches upstream commits for all modules.
1378 1378
1379 Completely git-specific. Simply runs 'git fetch [args ...]' for each module. 1379 Completely git-specific. Simply runs 'git fetch [args ...]' for each module.
1380 """ 1380 """
1381 (options, args) = parser.parse_args(args) 1381 (options, args) = parser.parse_args(args)
1382 return CMDrecurse(OptionParser(), [ 1382 return CMDrecurse(Parser(), [
1383 '--jobs=%d' % options.jobs, '--scm=git', 'git', 'fetch'] + args) 1383 '--jobs=%d' % options.jobs, '--scm=git', 'git', 'fetch'] + args)
1384 1384
1385 1385
1386 def CMDgrep(parser, args): 1386 def CMDgrep(parser, args):
1387 """Greps through git repos managed by gclient. 1387 """Greps through git repos managed by gclient.
1388 1388
1389 Runs 'git grep [args...]' for each module. 1389 Runs 'git grep [args...]' for each module.
1390 """ 1390 """
1391 1391
1392 # We can't use optparse because it will try to parse arguments sent 1392 # We can't use optparse because it will try to parse arguments sent
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 obj = Command(command) 1728 obj = Command(command)
1729 if command == 'help': 1729 if command == 'help':
1730 command = '<command>' 1730 command = '<command>'
1731 # OptParser.description prefer nicely non-formatted strings. 1731 # OptParser.description prefer nicely non-formatted strings.
1732 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__) 1732 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__)
1733 usage = getattr(obj, 'usage', '') 1733 usage = getattr(obj, 'usage', '')
1734 parser.set_usage('%%prog %s [options] %s' % (command, usage)) 1734 parser.set_usage('%%prog %s [options] %s' % (command, usage))
1735 parser.epilog = getattr(obj, 'epilog', None) 1735 parser.epilog = getattr(obj, 'epilog', None)
1736 1736
1737 1737
1738 class OptionParser(optparse.OptionParser): 1738 def Parser():
1739 """Returns the default parser."""
1740 parser = optparse.OptionParser(version='%prog ' + __version__)
1741 # some arm boards have issues with parallel sync.
1742 if platform.machine().startswith('arm'):
1743 jobs = 1
1744 else:
1745 jobs = max(8, gclient_utils.NumLocalCpus())
1746 # cmp: 2013/06/19
1747 # Temporary workaround to lower bot-load on SVN server.
1748 if os.environ.get('CHROME_HEADLESS') == '1':
1749 jobs = 4
1739 gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient') 1750 gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient')
1740 1751 parser.add_option('-j', '--jobs', default=jobs, type='int',
1741 def __init__(self, **kwargs): 1752 help='Specify how many SCM commands can run in parallel; '
1742 optparse.OptionParser.__init__( 1753 'defaults to number of cpu cores (%default)')
1743 self, version='%prog ' + __version__, **kwargs) 1754 parser.add_option('-v', '--verbose', action='count', default=0,
1744 1755 help='Produces additional output for diagnostics. Can be '
1745 # Some arm boards have issues with parallel sync. 1756 'used up to three times for more logging info.')
1746 if platform.machine().startswith('arm'): 1757 parser.add_option('--gclientfile', dest='config_filename',
1747 jobs = 1 1758 default=None,
1748 else: 1759 help='Specify an alternate %s file' % gclientfile_default)
1749 jobs = max(8, gclient_utils.NumLocalCpus()) 1760 parser.add_option('--spec',
1750 # cmp: 2013/06/19 1761 default=None,
1751 # Temporary workaround to lower bot-load on SVN server. 1762 help='create a gclient file containing the provided '
1752 if os.environ.get('CHROME_HEADLESS') == '1': 1763 'string. Due to Cygwin/Python brokenness, it '
1753 jobs = 4 1764 'probably can\'t contain any newlines.')
1754 1765 parser.add_option('--no-nag-max', default=False, action='store_true',
1755 self.add_option( 1766 help='If a subprocess runs for too long without generating'
1756 '-j', '--jobs', default=jobs, type='int', 1767 ' terminal output, generate warnings, but do not kill'
1757 help='Specify how many SCM commands can run in parallel; defaults to ' 1768 ' the process.')
1758 'number of cpu cores (%default)') 1769 # Integrate standard options processing.
1759 self.add_option( 1770 old_parser = parser.parse_args
1760 '-v', '--verbose', action='count', default=0, 1771 def Parse(args):
1761 help='Produces additional output for diagnostics. Can be used up to ' 1772 (options, args) = old_parser(args)
1762 'three times for more logging info.') 1773 level = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
1763 self.add_option( 1774 min(options.verbose, 3)]
1764 '--gclientfile', dest='config_filename', 1775 logging.basicConfig(level=level,
1765 help='Specify an alternate %s file' % self.gclientfile_default)
1766 self.add_option(
1767 '--spec',
1768 help='create a gclient file containing the provided string. Due to '
1769 'Cygwin/Python brokenness, it can\'t contain any newlines.')
1770 self.add_option(
1771 '--no-nag-max', default=False, action='store_true',
1772 help='If a subprocess runs for too long without generating terminal '
1773 'output, generate warnings, but do not kill the process.')
1774
1775 def parse_args(self, args=None, values=None):
1776 """Integrates standard options processing."""
1777 options, args = optparse.OptionParser.parse_args(self, args, values)
1778 levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
1779 logging.basicConfig(
1780 level=levels[min(options.verbose, len(levels) - 1)],
1781 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') 1776 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s')
1782 if options.config_filename and options.spec: 1777 if options.config_filename and options.spec:
1783 self.error('Cannot specifiy both --gclientfile and --spec') 1778 parser.error('Cannot specifiy both --gclientfile and --spec')
1784 if not options.config_filename: 1779 if not options.config_filename:
1785 options.config_filename = self.gclientfile_default 1780 options.config_filename = gclientfile_default
1786 options.entries_filename = options.config_filename + '_entries' 1781 options.entries_filename = options.config_filename + '_entries'
1787 if options.jobs < 1: 1782 if options.jobs < 1:
1788 self.error('--jobs must be 1 or higher') 1783 parser.error('--jobs must be 1 or higher')
1789 1784
1790 # These hacks need to die. 1785 # These hacks need to die.
1791 if not hasattr(options, 'revisions'): 1786 if not hasattr(options, 'revisions'):
1792 # GClient.RunOnDeps expects it even if not applicable. 1787 # GClient.RunOnDeps expects it even if not applicable.
1793 options.revisions = [] 1788 options.revisions = []
1794 if not hasattr(options, 'head'): 1789 if not hasattr(options, 'head'):
1795 options.head = None 1790 options.head = None
1796 if not hasattr(options, 'nohooks'): 1791 if not hasattr(options, 'nohooks'):
1797 options.nohooks = True 1792 options.nohooks = True
1798 if not hasattr(options, 'deps_os'): 1793 if not hasattr(options, 'deps_os'):
1799 options.deps_os = None 1794 options.deps_os = None
1800 if not hasattr(options, 'manually_grab_svn_rev'): 1795 if not hasattr(options, 'manually_grab_svn_rev'):
1801 options.manually_grab_svn_rev = None 1796 options.manually_grab_svn_rev = None
1802 if not hasattr(options, 'force'): 1797 if not hasattr(options, 'force'):
1803 options.force = None 1798 options.force = None
1804 if options.no_nag_max: 1799 if options.no_nag_max:
1805 gclient_scm.SCMWrapper.nag_max = None 1800 gclient_scm.SCMWrapper.nag_max = None
1806 return (options, args) 1801 return (options, args)
1807 1802 parser.parse_args = Parse
1808 def format_epilog(self, _): 1803 # We don't want wordwrapping in epilog (usually examples)
1809 """Disables wordwrapping in epilog (usually examples).""" 1804 parser.format_epilog = lambda _: parser.epilog or ''
1810 return self.epilog or '' 1805 return parser
1811 1806
1812 1807
1813 def Main(argv): 1808 def Main(argv):
1814 """Doesn't parse the arguments here, just find the right subcommand to 1809 """Doesn't parse the arguments here, just find the right subcommand to
1815 execute.""" 1810 execute."""
1816 if sys.hexversion < 0x02060000: 1811 if sys.hexversion < 0x02060000:
1817 print >> sys.stderr, ( 1812 print >> sys.stderr, (
1818 '\nYour python version %s is unsupported, please upgrade.\n' % 1813 '\nYour python version %s is unsupported, please upgrade.\n' %
1819 sys.version.split(' ', 1)[0]) 1814 sys.version.split(' ', 1)[0])
1820 return 2 1815 return 2
(...skipping 12 matching lines...) Expand all
1833 # Unused variable 'usage' 1828 # Unused variable 'usage'
1834 # pylint: disable=W0612 1829 # pylint: disable=W0612
1835 def to_str(fn): 1830 def to_str(fn):
1836 return ( 1831 return (
1837 ' %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) + 1832 ' %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) +
1838 ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip()) 1833 ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip())
1839 cmds = ( 1834 cmds = (
1840 to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD') 1835 to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')
1841 ) 1836 )
1842 CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds) 1837 CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds)
1843 parser = OptionParser() 1838 parser = Parser()
1844 if argv: 1839 if argv:
1845 command = Command(argv[0]) 1840 command = Command(argv[0])
1846 if command: 1841 if command:
1847 # 'fix' the usage and the description now that we know the subcommand. 1842 # 'fix' the usage and the description now that we know the subcommand.
1848 GenUsage(parser, argv[0]) 1843 GenUsage(parser, argv[0])
1849 return command(parser, argv[1:]) 1844 return command(parser, argv[1:])
1850 # Not a known command. Default to help. 1845 # Not a known command. Default to help.
1851 GenUsage(parser, 'help') 1846 GenUsage(parser, 'help')
1852 return CMDhelp(parser, argv) 1847 return CMDhelp(parser, argv)
1853 except KeyboardInterrupt: 1848 except KeyboardInterrupt:
1854 gclient_utils.GClientChildren.KillAllRemainingChildren() 1849 gclient_utils.GClientChildren.KillAllRemainingChildren()
1855 raise 1850 raise
1856 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1851 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1857 print >> sys.stderr, 'Error: %s' % str(e) 1852 print >> sys.stderr, 'Error: %s' % str(e)
1858 return 1 1853 return 1
1859 1854
1860 1855
1861 if '__main__' == __name__: 1856 if '__main__' == __name__:
1862 fix_encoding.fix_encoding() 1857 fix_encoding.fix_encoding()
1863 sys.exit(Main(sys.argv[1:])) 1858 sys.exit(Main(sys.argv[1:]))
1864 1859
1865 # vim: ts=2:sw=2:tw=80:et: 1860 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « commit_queue.py ('k') | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698