OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__) | 1163 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__) |
1164 usage = getattr(obj, 'usage', '') | 1164 usage = getattr(obj, 'usage', '') |
1165 parser.set_usage('%%prog %s [options] %s' % (command, usage)) | 1165 parser.set_usage('%%prog %s [options] %s' % (command, usage)) |
1166 parser.epilog = getattr(obj, 'epilog', None) | 1166 parser.epilog = getattr(obj, 'epilog', None) |
1167 | 1167 |
1168 | 1168 |
1169 def Main(argv): | 1169 def Main(argv): |
1170 """Doesn't parse the arguments here, just find the right subcommand to | 1170 """Doesn't parse the arguments here, just find the right subcommand to |
1171 execute.""" | 1171 execute.""" |
1172 try: | 1172 try: |
| 1173 # Make stdout auto-flush so buildbot doesn't kill us during lengthy |
| 1174 # operations. Python as a strong tendency to buffer sys.stdout. |
| 1175 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 1176 |
1173 # Do it late so all commands are listed. | 1177 # Do it late so all commands are listed. |
1174 CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([ | 1178 CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([ |
1175 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) | 1179 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) |
1176 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) | 1180 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) |
1177 parser = optparse.OptionParser(version='%prog ' + __version__) | 1181 parser = optparse.OptionParser(version='%prog ' + __version__) |
1178 parser.add_option('-j', '--jobs', default=1, type='int', | 1182 parser.add_option('-j', '--jobs', default=1, type='int', |
1179 help='Specify how many SCM commands can run in parallel; ' | 1183 help='Specify how many SCM commands can run in parallel; ' |
1180 'default=%default') | 1184 'default=%default') |
1181 parser.add_option('-v', '--verbose', action='count', default=0, | 1185 parser.add_option('-v', '--verbose', action='count', default=0, |
1182 help='Produces additional output for diagnostics. Can be ' | 1186 help='Produces additional output for diagnostics. Can be ' |
1183 'used up to three times for more logging info.') | 1187 'used up to three times for more logging info.') |
1184 parser.add_option('--gclientfile', dest='config_filename', | 1188 parser.add_option('--gclientfile', dest='config_filename', |
1185 default=os.environ.get('GCLIENT_FILE', '.gclient'), | 1189 default=os.environ.get('GCLIENT_FILE', '.gclient'), |
1186 help='Specify an alternate %default file') | 1190 help='Specify an alternate %default file') |
1187 # Integrate standard options processing. | 1191 # Integrate standard options processing. |
1188 old_parser = parser.parse_args | 1192 old_parser = parser.parse_args |
1189 def Parse(args): | 1193 def Parse(args): |
1190 (options, args) = old_parser(args) | 1194 (options, args) = old_parser(args) |
1191 level = None | 1195 level = None |
1192 if options.verbose == 2: | 1196 if options.verbose == 2: |
1193 level = logging.INFO | 1197 level = logging.INFO |
1194 elif options.verbose > 2: | 1198 elif options.verbose > 2: |
1195 level = logging.DEBUG | 1199 level = logging.DEBUG |
1196 logging.basicConfig(level=level, | 1200 logging.basicConfig(level=level, |
1197 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') | 1201 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') |
1198 options.entries_filename = options.config_filename + '_entries' | 1202 options.entries_filename = options.config_filename + '_entries' |
1199 if options.jobs < 1: | 1203 if options.jobs < 1: |
1200 parser.error('--jobs must be 1 or higher') | 1204 parser.error('--jobs must be 1 or higher') |
1201 # Always autoflush so buildbot doesn't kill us during lengthy operations. | 1205 # TODO(maruel): Temporary, to be removed. |
1202 options.stdout = gclient_utils.StdoutAutoFlush(sys.stdout) | 1206 options.stdout = sys.stdout |
1203 | 1207 |
1204 # These hacks need to die. | 1208 # These hacks need to die. |
1205 if not hasattr(options, 'revisions'): | 1209 if not hasattr(options, 'revisions'): |
1206 # GClient.RunOnDeps expects it even if not applicable. | 1210 # GClient.RunOnDeps expects it even if not applicable. |
1207 options.revisions = [] | 1211 options.revisions = [] |
1208 if not hasattr(options, 'head'): | 1212 if not hasattr(options, 'head'): |
1209 options.head = None | 1213 options.head = None |
1210 if not hasattr(options, 'nohooks'): | 1214 if not hasattr(options, 'nohooks'): |
1211 options.nohooks = True | 1215 options.nohooks = True |
1212 if not hasattr(options, 'deps_os'): | 1216 if not hasattr(options, 'deps_os'): |
(...skipping 17 matching lines...) Expand all Loading... |
1230 return CMDhelp(parser, argv) | 1234 return CMDhelp(parser, argv) |
1231 except gclient_utils.Error, e: | 1235 except gclient_utils.Error, e: |
1232 print >> sys.stderr, 'Error: %s' % str(e) | 1236 print >> sys.stderr, 'Error: %s' % str(e) |
1233 return 1 | 1237 return 1 |
1234 | 1238 |
1235 | 1239 |
1236 if '__main__' == __name__: | 1240 if '__main__' == __name__: |
1237 sys.exit(Main(sys.argv[1:])) | 1241 sys.exit(Main(sys.argv[1:])) |
1238 | 1242 |
1239 # vim: ts=2:sw=2:tw=80:et: | 1243 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |