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

Side by Side Diff: tools/auto_bisect/bisect_utils.py

Issue 1001033004: Fix style in tools/auto_bisect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Utility functions used by the bisect tool. 5 """Utility functions used by the bisect tool.
6 6
7 This includes functions related to checking out the depot and outputting 7 This includes functions related to checking out the depot and outputting
8 annotations for the Buildbot waterfall. 8 annotations for the Buildbot waterfall.
9 """ 9 """
10 10
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 spec = ''.join([l for l in spec.splitlines()]) 311 spec = ''.join([l for l in spec.splitlines()])
312 312
313 if 'android' in opts.target_platform: 313 if 'android' in opts.target_platform:
314 spec += GCLIENT_SPEC_ANDROID 314 spec += GCLIENT_SPEC_ANDROID
315 315
316 return_code = RunGClient( 316 return_code = RunGClient(
317 ['config', '--spec=%s' % spec], cwd=cwd) 317 ['config', '--spec=%s' % spec], cwd=cwd)
318 return return_code 318 return return_code
319 319
320 320
321
322 def OnAccessError(func, path, _): 321 def OnAccessError(func, path, _):
323 """Error handler for shutil.rmtree. 322 """Error handler for shutil.rmtree.
324 323
325 Source: http://goo.gl/DEYNCT 324 Source: http://goo.gl/DEYNCT
326 325
327 If the error is due to an access error (read only file), it attempts to add 326 If the error is due to an access error (read only file), it attempts to add
328 write permissions, then retries. 327 write permissions, then retries.
329 328
330 If the error is for another reason it re-raises the error. 329 If the error is for another reason it re-raises the error.
331 330
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 def CheckRunGit(command, cwd=None): 416 def CheckRunGit(command, cwd=None):
418 """Run a git subcommand, returning its output and return code. Asserts if 417 """Run a git subcommand, returning its output and return code. Asserts if
419 the return code of the call is non-zero. 418 the return code of the call is non-zero.
420 419
421 Args: 420 Args:
422 command: A list containing the args to git. 421 command: A list containing the args to git.
423 422
424 Returns: 423 Returns:
425 A tuple of the output and return code. 424 A tuple of the output and return code.
426 """ 425 """
427 (output, return_code) = RunGit(command, cwd=cwd) 426 output, return_code = RunGit(command, cwd=cwd)
428 427
429 assert not return_code, 'An error occurred while running'\ 428 assert not return_code, 'An error occurred while running'\
430 ' "git %s"' % ' '.join(command) 429 ' "git %s"' % ' '.join(command)
431 return output 430 return output
432 431
433 432
434 def RunGit(command, cwd=None): 433 def RunGit(command, cwd=None):
435 """Run a git subcommand, returning its output and return code. 434 """Run a git subcommand, returning its output and return code.
436 435
437 Args: 436 Args:
(...skipping 11 matching lines...) Expand all
449 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot 448 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
450 there using gclient. 449 there using gclient.
451 450
452 Args: 451 Args:
453 opts: The options parsed from the command line through parse_args(). 452 opts: The options parsed from the command line through parse_args().
454 custom_deps: A dictionary of additional dependencies to add to .gclient. 453 custom_deps: A dictionary of additional dependencies to add to .gclient.
455 """ 454 """
456 if CheckIfBisectDepotExists(opts): 455 if CheckIfBisectDepotExists(opts):
457 path_to_dir = os.path.join(os.path.abspath(opts.working_directory), 456 path_to_dir = os.path.join(os.path.abspath(opts.working_directory),
458 BISECT_DIR, 'src') 457 BISECT_DIR, 'src')
459 (output, _) = RunGit(['rev-parse', '--is-inside-work-tree'], 458 output, _ = RunGit(['rev-parse', '--is-inside-work-tree'], cwd=path_to_dir)
460 cwd=path_to_dir)
461 if output.strip() == 'true': 459 if output.strip() == 'true':
462 # Before checking out master, cleanup up any leftover index.lock files. 460 # Before checking out master, cleanup up any leftover index.lock files.
463 _CleanupPreviousGitRuns(path_to_dir) 461 _CleanupPreviousGitRuns(path_to_dir)
464 # Checks out the master branch, throws an exception if git command fails. 462 # Checks out the master branch, throws an exception if git command fails.
465 CheckRunGit(['checkout', '-f', 'master'], cwd=path_to_dir) 463 CheckRunGit(['checkout', '-f', 'master'], cwd=path_to_dir)
466 if not _CreateAndChangeToSourceDirectory(opts.working_directory): 464 if not _CreateAndChangeToSourceDirectory(opts.working_directory):
467 raise RuntimeError('Could not create bisect directory.') 465 raise RuntimeError('Could not create bisect directory.')
468 466
469 if not SetupGitDepot(opts, custom_deps): 467 if not SetupGitDepot(opts, custom_deps):
470 raise RuntimeError('Failed to grab source.') 468 raise RuntimeError('Failed to grab source.')
(...skipping 30 matching lines...) Expand all
501 499
502 Returns: 500 Returns:
503 A tuple of the output and return code. 501 A tuple of the output and return code.
504 """ 502 """
505 if cwd: 503 if cwd:
506 original_cwd = os.getcwd() 504 original_cwd = os.getcwd()
507 os.chdir(cwd) 505 os.chdir(cwd)
508 506
509 # On Windows, use shell=True to get PATH interpretation. 507 # On Windows, use shell=True to get PATH interpretation.
510 shell = IsWindowsHost() 508 shell = IsWindowsHost()
511 proc = subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE, 509 proc = subprocess.Popen(
510 command, shell=shell, stdout=subprocess.PIPE,
512 stderr=subprocess.STDOUT) 511 stderr=subprocess.STDOUT)
513 (output, _) = proc.communicate() 512 output, _ = proc.communicate()
514 513
515 if cwd: 514 if cwd:
516 os.chdir(original_cwd) 515 os.chdir(original_cwd)
517 516
518 return (output, proc.returncode) 517 return (output, proc.returncode)
519 518
520 519
521 def IsStringInt(string_to_check): 520 def IsStringInt(string_to_check):
522 """Checks whether or not the given string can be converted to an int.""" 521 """Checks whether or not the given string can be converted to an int."""
523 try: 522 try:
(...skipping 24 matching lines...) Expand all
548 platform = os.environ.get('PROCESSOR_ARCHITECTURE') 547 platform = os.environ.get('PROCESSOR_ARCHITECTURE')
549 return platform and platform in ['AMD64', 'I64'] 548 return platform and platform in ['AMD64', 'I64']
550 549
551 550
552 def IsLinuxHost(): 551 def IsLinuxHost():
553 return sys.platform.startswith('linux') 552 return sys.platform.startswith('linux')
554 553
555 554
556 def IsMacHost(): 555 def IsMacHost():
557 return sys.platform.startswith('darwin') 556 return sys.platform.startswith('darwin')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698