diff options
author | qyearsley <qyearsley@chromium.org> | 2014-10-15 18:57:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-16 01:57:27 +0000 |
commit | 902242f397508c4617f8cdbb2034b3d896b467cc (patch) | |
tree | eaac22f273552188a8f75c04a0a99c07eb930c4f /tools/auto_bisect | |
parent | de09561ee432f01c1ae3449a9bc44b3b7cfd4d51 (diff) | |
download | chromium_src-902242f397508c4617f8cdbb2034b3d896b467cc.zip chromium_src-902242f397508c4617f8cdbb2034b3d896b467cc.tar.gz chromium_src-902242f397508c4617f8cdbb2034b3d896b467cc.tar.bz2 |
Split RmTreeAndMkDir into two separate functions (refactoring).
The function RmTreeAndMkDir did two different things depending on a boolean flag that was passed to it.
This CL splits it into two functions so that each function only takes one argument and does one thing.
BUG=
Review URL: https://codereview.chromium.org/645383002
Cr-Commit-Position: refs/heads/master@{#299815}
Diffstat (limited to 'tools/auto_bisect')
-rwxr-xr-x | tools/auto_bisect/bisect_perf_regression.py | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/tools/auto_bisect/bisect_perf_regression.py b/tools/auto_bisect/bisect_perf_regression.py index fab182e..0d24ea61 100755 --- a/tools/auto_bisect/bisect_perf_regression.py +++ b/tools/auto_bisect/bisect_perf_regression.py @@ -167,7 +167,7 @@ MAX_MAC_BUILD_TIME = 14400 MAX_WIN_BUILD_TIME = 14400 MAX_LINUX_BUILD_TIME = 14400 -# The confidence percentage at which confidence can be consider "high". +# The percentage at which confidence is considered high. HIGH_CONFIDENCE = 95 # Patch template to add a new file, DEPS.sha under src folder. @@ -1249,7 +1249,7 @@ class BisectPerformanceMetrics(object): if restore: source_dir, destination_dir = destination_dir, source_dir if os.path.exists(source_dir): - RmTreeAndMkDir(destination_dir, skip_makedir=True) + RemoveDirectoryTree(destination_dir) shutil.move(source_dir, destination_dir) return destination_dir return None @@ -1289,9 +1289,9 @@ class BisectPerformanceMetrics(object): """Downloads the build archive for the given revision. Args: - revision: The Git revision to download or build. - build_type: Target build type ('Release', 'Debug', 'Release_x64' etc.) - patch: A DEPS patch (used while bisecting 3rd party repositories). + revision: The git revision to download or build. + depot: The name of a dependency repository. Should be in DEPOT_NAMES. + build_type: Target build type, e.g. Release', 'Debug', 'Release_x64' etc. Returns: True if download succeeds, otherwise False. @@ -1310,9 +1310,9 @@ class BisectPerformanceMetrics(object): # 'DEPS.sha' and add patch_sha evaluated above to it. patch = '%s\n%s' % (patch, DEPS_SHA_PATCH % {'deps_sha': patch_sha}) - # Get Build output directory - abs_build_dir = os.path.abspath( - builder.GetBuildOutputDirectory(self.opts, self.src_cwd)) + # Get build output directory. + build_dir = builder.GetBuildOutputDirectory(self.opts, self.src_cwd) + abs_build_dir = os.path.abspath(build_dir) fetch_build_func = lambda: self.GetBuildArchiveForRevision( revision, self.opts.gs_bucket, self.opts.target_arch, @@ -1332,9 +1332,10 @@ class BisectPerformanceMetrics(object): # Generic name for the archive, created when archive file is extracted. output_dir = os.path.join( abs_build_dir, GetZipFileName(target_arch=self.opts.target_arch)) + # Unzip build archive directory. try: - RmTreeAndMkDir(output_dir, skip_makedir=True) + RemoveDirectoryTree(output_dir) self.BackupOrRestoreOutputDirectory(restore=False) # Build output directory based on target(e.g. out/Release, out/Debug). target_build_output_dir = os.path.join(abs_build_dir, build_type) @@ -1356,7 +1357,7 @@ class BisectPerformanceMetrics(object): self.BackupOrRestoreOutputDirectory(restore=True) # Cleanup any leftovers from unzipping. if os.path.exists(output_dir): - RmTreeAndMkDir(output_dir, skip_makedir=True) + RemoveDirectoryTree(output_dir) finally: # Delete downloaded archive if os.path.exists(downloaded_file): @@ -2889,36 +2890,32 @@ def _IsPlatformSupported(): return os.name in supported -def RmTreeAndMkDir(path_to_dir, skip_makedir=False): - """Removes the directory tree specified, and then creates an empty - directory in the same location (if not specified to skip). +def RemakeDirectoryTree(path_to_dir): + """Removes a directory tree and replaces it with an empty one. - Args: - path_to_dir: Path to the directory tree. - skip_makedir: Whether to skip creating empty directory, default is False. - - Returns: - True if successful, False if an error occurred. + Returns True if successful, False otherwise. """ + if not RemoveDirectoryTree(path_to_dir): + return False + return MaybeMakeDirectory(path_to_dir) + + +def RemoveDirectoryTree(path_to_dir): + """Removes a directory tree. Returns True if successful or False otherwise.""" try: if os.path.exists(path_to_dir): shutil.rmtree(path_to_dir) except OSError, e: if e.errno != errno.ENOENT: return False - - if not skip_makedir: - return MaybeMakeDirectory(path_to_dir) - return True def RemoveBuildFiles(build_type): """Removes build files from previous runs.""" - if RmTreeAndMkDir(os.path.join('out', build_type)): - if RmTreeAndMkDir(os.path.join('build', build_type)): - return True - return False + out_dir = os.path.join('out', build_type) + build_dir = os.path.join('build', build_type) + return RemakeDirectoryTree(out_dir) and RemakeDirectoryTree(build_dir) class BisectOptions(object): |