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

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

Issue 418113003: Extract SourceControl to module; extract common methods to bisect_utils. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/auto_bisect/source_control.py » ('j') | tools/auto_bisect/source_control.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 """Set of operations/utilities related to checking out the depot, and 5 """Set of operations/utilities related to checking out the depot, and
6 outputting annotations on the buildbot waterfall. These are intended to be 6 outputting annotations on the buildbot waterfall. These are intended to be
7 used by the bisection scripts.""" 7 used by the bisection scripts."""
8 8
9 import errno 9 import errno
10 import imp 10 import imp
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 Args: 488 Args:
489 opts: The options parsed from the command line through parse_args(). 489 opts: The options parsed from the command line through parse_args().
490 490
491 Returns: 491 Returns:
492 Returns True if it exists. 492 Returns True if it exists.
493 """ 493 """
494 path_to_dir = os.path.join(opts.working_directory, 'bisect', 'src') 494 path_to_dir = os.path.join(opts.working_directory, 'bisect', 'src')
495 return os.path.exists(path_to_dir) 495 return os.path.exists(path_to_dir)
496 496
497 497
498 def CheckRunGit(command, cwd=None):
499 """Run a git subcommand, returning its output and return code. Asserts if
500 the return code of the call is non-zero.
501
502 Args:
503 command: A list containing the args to git.
504
505 Returns:
506 A tuple of the output and return code.
507 """
508 (output, return_code) = RunGit(command, cwd=cwd)
509
510 assert not return_code, 'An error occurred while running'\
511 ' "git %s"' % ' '.join(command)
512 return output
513
514
515 def RunGit(command, cwd=None):
516 """Run a git subcommand, returning its output and return code.
517
518 Args:
519 command: A list containing the args to git.
520 cwd: A directory to change to while running the git command (optional).
521
522 Returns:
523 A tuple of the output and return code.
524 """
525 command = ['git'] + command
526
527 return RunProcessAndRetrieveOutput(command, cwd=cwd)
528
529
498 def CreateBisectDirectoryAndSetupDepot(opts, custom_deps): 530 def CreateBisectDirectoryAndSetupDepot(opts, custom_deps):
499 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot 531 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
500 there using gclient. 532 there using gclient.
501 533
502 Args: 534 Args:
503 opts: The options parsed from the command line through parse_args(). 535 opts: The options parsed from the command line through parse_args().
504 custom_deps: A dictionary of additional dependencies to add to .gclient. 536 custom_deps: A dictionary of additional dependencies to add to .gclient.
505 """ 537 """
506 if not CreateAndChangeToSourceDirectory(opts.working_directory): 538 if not CreateAndChangeToSourceDirectory(opts.working_directory):
507 raise RuntimeError('Could not create bisect directory.') 539 raise RuntimeError('Could not create bisect directory.')
508 540
509 if not SetupGitDepot(opts, custom_deps): 541 if not SetupGitDepot(opts, custom_deps):
510 raise RuntimeError('Failed to grab source.') 542 raise RuntimeError('Failed to grab source.')
543
544
545 def RunProcess(command):
546 """Runs an arbitrary command.
547
548 If output from the call is needed, use RunProcessAndRetrieveOutput instead.
549
550 Args:
551 command: A list containing the command and args to execute.
552
553 Returns:
554 The return code of the call.
555 """
556 # On Windows, use shell=True to get PATH interpretation.
557 shell = IsWindowsHost()
558 return subprocess.call(command, shell=shell)
559
560
561 def RunProcessAndRetrieveOutput(command, cwd=None):
562 """Runs an arbitrary command, returning its output and return code.
563
564 Since output is collected via communicate(), there will be no output until
565 the call terminates. If you need output while the program runs (ie. so
566 that the buildbot doesn't terminate the script), consider RunProcess().
567
568 Args:
569 command: A list containing the command and args to execute.
570 cwd: A directory to change to while running the command. The command can be
571 relative to this directory. If this is None, the command will be run in
572 the current directory.
573
574 Returns:
575 A tuple of the output and return code.
576 """
577 if cwd:
578 original_cwd = os.getcwd()
579 os.chdir(cwd)
580
581 # On Windows, use shell=True to get PATH interpretation.
582 shell = IsWindowsHost()
583 proc = subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE)
584 (output, _) = proc.communicate()
585
586 if cwd:
587 os.chdir(original_cwd)
588
589 return (output, proc.returncode)
590
591
592 def IsStringInt(string_to_check):
593 """Checks whether or not the given string can be converted to a integer.
594
595 Args:
596 string_to_check: Input string to check if it can be converted to an int.
597
598 Returns:
599 True if the string can be converted to an int.
600 """
601 try:
602 int(string_to_check)
603 return True
604 except ValueError:
605 return False
606
607
608 def IsStringFloat(string_to_check):
609 """Checks whether or not the given string can be converted to a floating
610 point number.
611
612 Args:
613 string_to_check: Input string to check if it can be converted to a float.
614
615 Returns:
616 True if the string can be converted to a float.
617 """
618 try:
619 float(string_to_check)
620 return True
621 except ValueError:
622 return False
623
624
625 def IsWindowsHost():
626 """Checks whether or not the script is running on Windows.
627
628 Returns:
629 True if running on Windows.
630 """
631 return sys.platform == 'cygwin' or sys.platform.startswith('win')
632
633
634 def Is64BitWindows():
635 """Returns whether or not Windows is a 64-bit version.
636
637 Returns:
638 True if Windows is 64-bit, False if 32-bit.
639 """
640 platform = os.environ['PROCESSOR_ARCHITECTURE']
641 try:
642 platform = os.environ['PROCESSOR_ARCHITEW6432']
643 except KeyError:
644 # Must not be running in WoW64, so PROCESSOR_ARCHITECTURE is correct
645 pass
646
647 return platform in ['AMD64', 'I64']
648
649
650 def IsLinuxHost():
651 """Checks whether or not the script is running on Linux.
652
653 Returns:
654 True if running on Linux.
655 """
656 return sys.platform.startswith('linux')
657
658
659 def IsMacHost():
660 """Checks whether or not the script is running on Mac.
661
662 Returns:
663 True if running on Mac.
664 """
665 return sys.platform.startswith('darwin')
OLDNEW
« no previous file with comments | « no previous file | tools/auto_bisect/source_control.py » ('j') | tools/auto_bisect/source_control.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698