
Suppress stdout of 'expand' command unless there's an error. i.e. """ [2294->7960/10271 ~17] ACTION content_common: extract_xinput Microsoft (R) File Expansion Utility Version 6.1.7600.16385 Copyright (c) Microsoft Corporation. All rights reserved. Adding ../out/Debug\tmpamaser\xinput1_3.dll to Extraction Queue Expanding Files .... Expanding Files Complete ... [2164->8090/10271 ~17] ACTION content_gpu: extract_d3dx9 Microsoft (R) File Expansion Utility Version 6.1.7600.16385 Copyright (c) Microsoft Corporation. All rights reserved. Adding ../out/Debug\tmpcxuoz9\d3dx9_43.dll to Extraction Queue Expanding Files .... Expanding Files Complete ... [2163->8091/10271 ~17] ACTION content_gpu: extract_d3dcompiler Microsoft (R) File Expansion Utility Version 6.1.7600.16385 Copyright (c) Microsoft Corporation. All rights reserved. Adding ../out/Debug\tmploys57\D3DCompiler_43.dll to Extraction Queue Expanding Files .... Expanding Files Complete ... """ R=apatrick@chromium.org BUG=126483 Review URL: https://chromiumcodereview.appspot.com/10409086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138442 0039d316-1c4b-4281-b951-d872f2087c98
64 lines
2.0 KiB
Python
Executable File
64 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
"""Extracts a single file from a CAB archive."""
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
def run_quiet(*args):
|
|
"""Run 'expand' supressing noisy output. Returns returncode from process."""
|
|
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
|
|
out, _ = popen.communicate()
|
|
if popen.returncode:
|
|
# expand emits errors to stdout, so if we fail, then print that out.
|
|
print out
|
|
return popen.returncode
|
|
|
|
def main():
|
|
if len(sys.argv) != 4:
|
|
print 'Usage: extract_from_cab.py cab_path archived_file output_dir'
|
|
return 1
|
|
|
|
[cab_path, archived_file, output_dir] = sys.argv[1:]
|
|
|
|
# Expand.exe does its work in a fixed-named temporary directory created within
|
|
# the given output directory. This is a problem for concurrent extractions, so
|
|
# create a unique temp dir within the desired output directory to work around
|
|
# this limitation.
|
|
temp_dir = tempfile.mkdtemp(dir=output_dir)
|
|
|
|
try:
|
|
# Invoke the Windows expand utility to extract the file.
|
|
level = run_quiet('expand', cab_path, '-F:' + archived_file, temp_dir)
|
|
if level == 0:
|
|
# Move the output file into place, preserving expand.exe's behavior of
|
|
# paving over any preexisting file.
|
|
output_file = os.path.join(output_dir, archived_file)
|
|
try:
|
|
os.remove(output_file)
|
|
except OSError:
|
|
pass
|
|
os.rename(os.path.join(temp_dir, archived_file), output_file)
|
|
finally:
|
|
shutil.rmtree(temp_dir, True)
|
|
|
|
if level != 0:
|
|
return level
|
|
|
|
# The expand utility preserves the modification date and time of the archived
|
|
# file. Touch the extracted file. This helps build systems that compare the
|
|
# modification times of input and output files to determine whether to do an
|
|
# action.
|
|
os.utime(os.path.join(output_dir, archived_file), None)
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|