Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import os | 6 import os |
| 7 import logging | 7 import logging |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import urllib2 | 10 import urllib2 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 | 237 |
| 238 Returns: | 238 Returns: |
| 239 (result, msg) where result is one of: | 239 (result, msg) where result is one of: |
| 240 SUCCESS if a tryjob was sent | 240 SUCCESS if a tryjob was sent |
| 241 NO_CHANGES if there was nothing to try, | 241 NO_CHANGES if there was nothing to try, |
| 242 ERROR if a tryjob was attempted but an error encountered | 242 ERROR if a tryjob was attempted but an error encountered |
| 243 and msg is an error message if an error was encountered, or rietveld | 243 and msg is an error message if an error was encountered, or rietveld |
| 244 url if success, otherwise throws TrybotError exception. | 244 url if success, otherwise throws TrybotError exception. |
| 245 """ | 245 """ |
| 246 config = self._GetPerfConfig(bot_platform, arguments) | 246 config = self._GetPerfConfig(bot_platform, arguments) |
| 247 config_to_write = 'config = %s' % json.dumps( | |
| 248 config, sort_keys=True, indent=2, separators=(',', ': ')) | |
| 249 | |
| 247 try: | 250 try: |
| 248 config_file = open(cfg_file_path, 'w') | 251 with open(cfg_file_path, 'r') as config_file: |
| 252 if config_to_write == config_file.read(): | |
| 253 return NO_CHANGES, '' | |
| 249 except IOError: | 254 except IOError: |
| 250 msg = 'Cannot find %s. Please run from src dir.' % cfg_file_path | 255 msg = 'Cannot find %s. Please run from src dir.' % cfg_file_path |
| 251 return (ERROR, msg) | 256 return (ERROR, msg) |
| 252 config_file.write('config = %s' % json.dumps( | 257 |
| 253 config, sort_keys=True, indent=2, separators=(',', ': '))) | 258 with open(cfg_file_path, 'w') as config_file: |
| 254 config_file.close() | 259 config_file.write(config_to_write) |
| 255 # Commit the config changes locally. | 260 # Commit the config changes locally. |
| 256 returncode, out, err = _RunProcess( | 261 returncode, out, err = _RunProcess( |
| 257 ['git', 'commit', '-a', '-m', 'bisect config: %s' % bot_platform]) | 262 ['git', 'commit', '-a', '-m', 'bisect config: %s' % bot_platform]) |
| 258 if returncode: | 263 if returncode: |
| 259 raise TrybotError('Could not commit bisect config change for %s,' | 264 raise TrybotError('Could not commit bisect config change for %s,' |
| 260 ' error %s' % (bot_platform, err)) | 265 ' error %s' % (bot_platform, err)) |
| 261 # Upload the CL to rietveld and run a try job. | 266 # Upload the CL to rietveld and run a try job. |
| 262 returncode, out, err = _RunProcess([ | 267 returncode, out, err = _RunProcess([ |
| 263 'git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', | 268 'git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', |
| 264 'CL for perf tryjob on %s' % bot_platform | 269 'CL for perf tryjob on %s' % bot_platform |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 for bot_platform in self._builder_names: | 392 for bot_platform in self._builder_names: |
| 388 if not self._builder_names[bot_platform]: | 393 if not self._builder_names[bot_platform]: |
| 389 logging.warning('No builder is found for %s', bot_platform) | 394 logging.warning('No builder is found for %s', bot_platform) |
| 390 continue | 395 continue |
| 391 try: | 396 try: |
| 392 results, output = self._UpdateConfigAndRunTryjob( | 397 results, output = self._UpdateConfigAndRunTryjob( |
| 393 bot_platform, cfg_file_path, arguments) | 398 bot_platform, cfg_file_path, arguments) |
| 394 if results == ERROR: | 399 if results == ERROR: |
| 395 logging.error(output) | 400 logging.error(output) |
| 396 return ERROR | 401 return ERROR |
| 397 print ('Uploaded %s try job to rietveld for %s platform. ' | 402 elif results == NO_CHANGES: |
| 398 'View progress at %s' % (source_repo, bot_platform, output)) | 403 print ('Skip the try job run on %s because it has been tried in ' |
| 404 'previous try job run. ' % bot_platform) | |
| 405 else: | |
|
sullivan
2016/03/03 06:31:59
Shouldn't this use logging api?
nednguyen
2016/03/03 06:52:23
I am unsure with logging to use, error, warning &
| |
| 406 print ('Uploaded %s try job to rietveld for %s platform. ' | |
| 407 'View progress at %s' % (source_repo, bot_platform, output)) | |
| 399 except TrybotError, err: | 408 except TrybotError, err: |
| 400 print err | 409 print err |
| 401 logging.error(err) | 410 logging.error(err) |
| 402 finally: | 411 finally: |
| 403 # Checkout original branch and delete telemetry-tryjob branch. | 412 # Checkout original branch and delete telemetry-tryjob branch. |
| 404 # TODO(prasadv): This finally block could be extracted out to be a | 413 # TODO(prasadv): This finally block could be extracted out to be a |
| 405 # separate function called _CleanupBranch. | 414 # separate function called _CleanupBranch. |
| 406 returncode, out, err = _RunProcess( | 415 returncode, out, err = _RunProcess( |
| 407 ['git', 'checkout', original_branchname]) | 416 ['git', 'checkout', original_branchname]) |
| 408 if returncode: | 417 if returncode: |
| 409 logging.error('Could not check out %s. Please check it out and ' | 418 logging.error('Could not check out %s. Please check it out and ' |
| 410 'manually delete the telemetry-tryjob branch. ' | 419 'manually delete the telemetry-tryjob branch. ' |
| 411 ': %s', original_branchname, err) | 420 ': %s', original_branchname, err) |
| 412 return ERROR # pylint: disable=lost-exception | 421 return ERROR # pylint: disable=lost-exception |
| 413 logging.info('Checked out original branch: %s', original_branchname) | 422 logging.info('Checked out original branch: %s', original_branchname) |
| 414 returncode, out, err = _RunProcess( | 423 returncode, out, err = _RunProcess( |
| 415 ['git', 'branch', '-D', 'telemetry-tryjob']) | 424 ['git', 'branch', '-D', 'telemetry-tryjob']) |
| 416 if returncode: | 425 if returncode: |
| 417 logging.error('Could not delete telemetry-tryjob branch. ' | 426 logging.error('Could not delete telemetry-tryjob branch. ' |
| 418 'Please delete it manually: %s', err) | 427 'Please delete it manually: %s', err) |
| 419 return ERROR # pylint: disable=lost-exception | 428 return ERROR # pylint: disable=lost-exception |
| 420 logging.info('Deleted temp branch: telemetry-tryjob') | 429 logging.info('Deleted temp branch: telemetry-tryjob') |
| 421 return SUCCESS | 430 return SUCCESS |
| OLD | NEW |