blob: 2321d2f7dd6ef5a730957bad5630db702ddd0c61 [file] [log] [blame]
[email protected]dcfc4dd2010-07-28 23:02:221#!/usr/bin/env python
[email protected]3f09d182011-11-23 19:13:442# Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]dcfc4dd2010-07-28 23:02:223# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
[email protected]3f09d182011-11-23 19:13:446"""Extracts a single file from a CAB archive."""
[email protected]dcfc4dd2010-07-28 23:02:227
8import os
9import subprocess
10import sys
11
[email protected]dcfc4dd2010-07-28 23:02:2212
[email protected]3f09d182011-11-23 19:13:4413def main():
14 if len(sys.argv) != 4:
15 print 'Usage: extract_from_cab.py cab_path archived_file output_dir'
16 return 1
[email protected]dcfc4dd2010-07-28 23:02:2217
[email protected]3f09d182011-11-23 19:13:4418 [cab_path, archived_file, output_dir] = sys.argv[1:]
[email protected]dcfc4dd2010-07-28 23:02:2219
[email protected]3f09d182011-11-23 19:13:4420 # Invoke the Windows expand utility to extract the file.
21 level = subprocess.call(
22 ['expand', cab_path, '-F:' + archived_file, output_dir])
23 if level != 0:
[email protected]72ec3082011-12-08 20:47:1524 print 'Cab extraction(%s, %s, %s) failed.' % (
25 cab_path, archived_file, output_dir)
26 print 'Trying a second time.'
27 level = subprocess.call(
28 ['expand', cab_path, '-F:' + archived_file, output_dir])
29 if level != 0:
30 return level
[email protected]3f09d182011-11-23 19:13:4431
32 # The expand utility preserves the modification date and time of the archived
33 # file. Touch the extracted file. This helps build systems that compare the
34 # modification times of input and output files to determine whether to do an
35 # action.
36 os.utime(os.path.join(output_dir, archived_file), None)
37 return 0
38
39
40if __name__ == '__main__':
41 sys.exit(main())