| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 import urlparse | 62 import urlparse |
| 63 import urllib | 63 import urllib |
| 64 | 64 |
| 65 import breakpad # pylint: disable=W0611 | 65 import breakpad # pylint: disable=W0611 |
| 66 | 66 |
| 67 import fix_encoding | 67 import fix_encoding |
| 68 import gclient_scm | 68 import gclient_scm |
| 69 import gclient_utils | 69 import gclient_utils |
| 70 from third_party.repo.progress import Progress | 70 from third_party.repo.progress import Progress |
| 71 import subprocess2 | 71 import subprocess2 |
| 72 from third_party import colorama |
| 73 # Import shortcut. |
| 74 from third_party.colorama import Fore |
| 72 | 75 |
| 73 | 76 |
| 74 def attr(attribute, data): | 77 def attr(attribute, data): |
| 75 """Sets an attribute on a function.""" | 78 """Sets an attribute on a function.""" |
| 76 def hook(fn): | 79 def hook(fn): |
| 77 setattr(fn, attribute, data) | 80 setattr(fn, attribute, data) |
| 78 return fn | 81 return fn |
| 79 return hook | 82 return hook |
| 80 | 83 |
| 81 | 84 |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 parser.format_epilog = lambda _: parser.epilog or '' | 1479 parser.format_epilog = lambda _: parser.epilog or '' |
| 1477 return parser | 1480 return parser |
| 1478 | 1481 |
| 1479 | 1482 |
| 1480 def Main(argv): | 1483 def Main(argv): |
| 1481 """Doesn't parse the arguments here, just find the right subcommand to | 1484 """Doesn't parse the arguments here, just find the right subcommand to |
| 1482 execute.""" | 1485 execute.""" |
| 1483 if sys.hexversion < 0x02050000: | 1486 if sys.hexversion < 0x02050000: |
| 1484 print >> sys.stderr, ( | 1487 print >> sys.stderr, ( |
| 1485 '\nYour python version is unsupported, please upgrade.\n') | 1488 '\nYour python version is unsupported, please upgrade.\n') |
| 1489 colorama.init() |
| 1486 try: | 1490 try: |
| 1487 # Make stdout auto-flush so buildbot doesn't kill us during lengthy | 1491 # Make stdout auto-flush so buildbot doesn't kill us during lengthy |
| 1488 # operations. Python as a strong tendency to buffer sys.stdout. | 1492 # operations. Python as a strong tendency to buffer sys.stdout. |
| 1489 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 1493 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 1490 # Make stdout annotated with the thread ids. | 1494 # Make stdout annotated with the thread ids. |
| 1491 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout) | 1495 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout) |
| 1492 # Do it late so all commands are listed. | 1496 # Do it late so all commands are listed. |
| 1493 # Unused variable 'usage' | 1497 # Unused variable 'usage' |
| 1494 # pylint: disable=W0612 | 1498 # pylint: disable=W0612 |
| 1495 CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([ | 1499 def to_str(fn): |
| 1496 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) | 1500 return ( |
| 1497 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) | 1501 ' %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) + |
| 1502 ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip()) |
| 1503 cmds = ( |
| 1504 to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD') |
| 1505 ) |
| 1506 CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds) |
| 1498 parser = Parser() | 1507 parser = Parser() |
| 1499 if argv: | 1508 if argv: |
| 1500 command = Command(argv[0]) | 1509 command = Command(argv[0]) |
| 1501 if command: | 1510 if command: |
| 1502 # 'fix' the usage and the description now that we know the subcommand. | 1511 # 'fix' the usage and the description now that we know the subcommand. |
| 1503 GenUsage(parser, argv[0]) | 1512 GenUsage(parser, argv[0]) |
| 1504 return command(parser, argv[1:]) | 1513 return command(parser, argv[1:]) |
| 1505 # Not a known command. Default to help. | 1514 # Not a known command. Default to help. |
| 1506 GenUsage(parser, 'help') | 1515 GenUsage(parser, 'help') |
| 1507 return CMDhelp(parser, argv) | 1516 return CMDhelp(parser, argv) |
| 1508 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1517 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1509 print >> sys.stderr, 'Error: %s' % str(e) | 1518 print >> sys.stderr, 'Error: %s' % str(e) |
| 1510 return 1 | 1519 return 1 |
| 1511 | 1520 |
| 1512 | 1521 |
| 1513 if '__main__' == __name__: | 1522 if '__main__' == __name__: |
| 1514 fix_encoding.fix_encoding() | 1523 fix_encoding.fix_encoding() |
| 1515 sys.exit(Main(sys.argv[1:])) | 1524 sys.exit(Main(sys.argv[1:])) |
| 1516 | 1525 |
| 1517 # vim: ts=2:sw=2:tw=80:et: | 1526 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |