| OLD | NEW |
| 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 Loading... |
| 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(Parser(), [ | 1382 return CMDrecurse(OptionParser(), [ |
| 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 Loading... |
| 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 def Parser(): | 1738 class OptionParser(optparse.OptionParser): |
| 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 | |
| 1750 gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient') | 1739 gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient') |
| 1751 parser.add_option('-j', '--jobs', default=jobs, type='int', | 1740 |
| 1752 help='Specify how many SCM commands can run in parallel; ' | 1741 def __init__(self, **kwargs): |
| 1753 'defaults to number of cpu cores (%default)') | 1742 optparse.OptionParser.__init__( |
| 1754 parser.add_option('-v', '--verbose', action='count', default=0, | 1743 self, version='%prog ' + __version__, **kwargs) |
| 1755 help='Produces additional output for diagnostics. Can be ' | 1744 |
| 1756 'used up to three times for more logging info.') | 1745 # Some arm boards have issues with parallel sync. |
| 1757 parser.add_option('--gclientfile', dest='config_filename', | 1746 if platform.machine().startswith('arm'): |
| 1758 default=None, | 1747 jobs = 1 |
| 1759 help='Specify an alternate %s file' % gclientfile_default) | 1748 else: |
| 1760 parser.add_option('--spec', | 1749 jobs = max(8, gclient_utils.NumLocalCpus()) |
| 1761 default=None, | 1750 # cmp: 2013/06/19 |
| 1762 help='create a gclient file containing the provided ' | 1751 # Temporary workaround to lower bot-load on SVN server. |
| 1763 'string. Due to Cygwin/Python brokenness, it ' | 1752 if os.environ.get('CHROME_HEADLESS') == '1': |
| 1764 'probably can\'t contain any newlines.') | 1753 jobs = 4 |
| 1765 parser.add_option('--no-nag-max', default=False, action='store_true', | 1754 |
| 1766 help='If a subprocess runs for too long without generating' | 1755 self.add_option( |
| 1767 ' terminal output, generate warnings, but do not kill' | 1756 '-j', '--jobs', default=jobs, type='int', |
| 1768 ' the process.') | 1757 help='Specify how many SCM commands can run in parallel; defaults to ' |
| 1769 # Integrate standard options processing. | 1758 'number of cpu cores (%default)') |
| 1770 old_parser = parser.parse_args | 1759 self.add_option( |
| 1771 def Parse(args): | 1760 '-v', '--verbose', action='count', default=0, |
| 1772 (options, args) = old_parser(args) | 1761 help='Produces additional output for diagnostics. Can be used up to ' |
| 1773 level = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 1762 'three times for more logging info.') |
| 1774 min(options.verbose, 3)] | 1763 self.add_option( |
| 1775 logging.basicConfig(level=level, | 1764 '--gclientfile', dest='config_filename', |
| 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)], |
| 1776 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') | 1781 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') |
| 1777 if options.config_filename and options.spec: | 1782 if options.config_filename and options.spec: |
| 1778 parser.error('Cannot specifiy both --gclientfile and --spec') | 1783 self.error('Cannot specifiy both --gclientfile and --spec') |
| 1779 if not options.config_filename: | 1784 if not options.config_filename: |
| 1780 options.config_filename = gclientfile_default | 1785 options.config_filename = self.gclientfile_default |
| 1781 options.entries_filename = options.config_filename + '_entries' | 1786 options.entries_filename = options.config_filename + '_entries' |
| 1782 if options.jobs < 1: | 1787 if options.jobs < 1: |
| 1783 parser.error('--jobs must be 1 or higher') | 1788 self.error('--jobs must be 1 or higher') |
| 1784 | 1789 |
| 1785 # These hacks need to die. | 1790 # These hacks need to die. |
| 1786 if not hasattr(options, 'revisions'): | 1791 if not hasattr(options, 'revisions'): |
| 1787 # GClient.RunOnDeps expects it even if not applicable. | 1792 # GClient.RunOnDeps expects it even if not applicable. |
| 1788 options.revisions = [] | 1793 options.revisions = [] |
| 1789 if not hasattr(options, 'head'): | 1794 if not hasattr(options, 'head'): |
| 1790 options.head = None | 1795 options.head = None |
| 1791 if not hasattr(options, 'nohooks'): | 1796 if not hasattr(options, 'nohooks'): |
| 1792 options.nohooks = True | 1797 options.nohooks = True |
| 1793 if not hasattr(options, 'deps_os'): | 1798 if not hasattr(options, 'deps_os'): |
| 1794 options.deps_os = None | 1799 options.deps_os = None |
| 1795 if not hasattr(options, 'manually_grab_svn_rev'): | 1800 if not hasattr(options, 'manually_grab_svn_rev'): |
| 1796 options.manually_grab_svn_rev = None | 1801 options.manually_grab_svn_rev = None |
| 1797 if not hasattr(options, 'force'): | 1802 if not hasattr(options, 'force'): |
| 1798 options.force = None | 1803 options.force = None |
| 1799 if options.no_nag_max: | 1804 if options.no_nag_max: |
| 1800 gclient_scm.SCMWrapper.nag_max = None | 1805 gclient_scm.SCMWrapper.nag_max = None |
| 1801 return (options, args) | 1806 return (options, args) |
| 1802 parser.parse_args = Parse | 1807 |
| 1803 # We don't want wordwrapping in epilog (usually examples) | 1808 def format_epilog(self, _): |
| 1804 parser.format_epilog = lambda _: parser.epilog or '' | 1809 """Disables wordwrapping in epilog (usually examples).""" |
| 1805 return parser | 1810 return self.epilog or '' |
| 1806 | 1811 |
| 1807 | 1812 |
| 1808 def Main(argv): | 1813 def Main(argv): |
| 1809 """Doesn't parse the arguments here, just find the right subcommand to | 1814 """Doesn't parse the arguments here, just find the right subcommand to |
| 1810 execute.""" | 1815 execute.""" |
| 1811 if sys.hexversion < 0x02060000: | 1816 if sys.hexversion < 0x02060000: |
| 1812 print >> sys.stderr, ( | 1817 print >> sys.stderr, ( |
| 1813 '\nYour python version %s is unsupported, please upgrade.\n' % | 1818 '\nYour python version %s is unsupported, please upgrade.\n' % |
| 1814 sys.version.split(' ', 1)[0]) | 1819 sys.version.split(' ', 1)[0]) |
| 1815 return 2 | 1820 return 2 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1828 # Unused variable 'usage' | 1833 # Unused variable 'usage' |
| 1829 # pylint: disable=W0612 | 1834 # pylint: disable=W0612 |
| 1830 def to_str(fn): | 1835 def to_str(fn): |
| 1831 return ( | 1836 return ( |
| 1832 ' %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) + | 1837 ' %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) + |
| 1833 ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip()) | 1838 ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip()) |
| 1834 cmds = ( | 1839 cmds = ( |
| 1835 to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD') | 1840 to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD') |
| 1836 ) | 1841 ) |
| 1837 CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds) | 1842 CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds) |
| 1838 parser = Parser() | 1843 parser = OptionParser() |
| 1839 if argv: | 1844 if argv: |
| 1840 command = Command(argv[0]) | 1845 command = Command(argv[0]) |
| 1841 if command: | 1846 if command: |
| 1842 # 'fix' the usage and the description now that we know the subcommand. | 1847 # 'fix' the usage and the description now that we know the subcommand. |
| 1843 GenUsage(parser, argv[0]) | 1848 GenUsage(parser, argv[0]) |
| 1844 return command(parser, argv[1:]) | 1849 return command(parser, argv[1:]) |
| 1845 # Not a known command. Default to help. | 1850 # Not a known command. Default to help. |
| 1846 GenUsage(parser, 'help') | 1851 GenUsage(parser, 'help') |
| 1847 return CMDhelp(parser, argv) | 1852 return CMDhelp(parser, argv) |
| 1848 except KeyboardInterrupt: | 1853 except KeyboardInterrupt: |
| 1849 gclient_utils.GClientChildren.KillAllRemainingChildren() | 1854 gclient_utils.GClientChildren.KillAllRemainingChildren() |
| 1850 raise | 1855 raise |
| 1851 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1856 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1852 print >> sys.stderr, 'Error: %s' % str(e) | 1857 print >> sys.stderr, 'Error: %s' % str(e) |
| 1853 return 1 | 1858 return 1 |
| 1854 | 1859 |
| 1855 | 1860 |
| 1856 if '__main__' == __name__: | 1861 if '__main__' == __name__: |
| 1857 fix_encoding.fix_encoding() | 1862 fix_encoding.fix_encoding() |
| 1858 sys.exit(Main(sys.argv[1:])) | 1863 sys.exit(Main(sys.argv[1:])) |
| 1859 | 1864 |
| 1860 # vim: ts=2:sw=2:tw=80:et: | 1865 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |