blob: 932046267fdec8ffc79aa0b996dd781203875ae8 [file] [log] [blame]
apatrick@chromium.org1218a882010-07-29 08:02:22 +09001#!/usr/bin/env python
maruel@chromium.org1f144a32011-11-24 04:13:44 +09002# Copyright (c) 2011 The Chromium Authors. All rights reserved.
apatrick@chromium.org1218a882010-07-29 08:02:22 +09003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
maruel@chromium.org1f144a32011-11-24 04:13:44 +09006"""Extracts a single file from a CAB archive."""
apatrick@chromium.org1218a882010-07-29 08:02:22 +09007
8import os
9import subprocess
10import sys
11
apatrick@chromium.org1218a882010-07-29 08:02:22 +090012
maruel@chromium.org1f144a32011-11-24 04:13:44 +090013def main():
14 if len(sys.argv) != 4:
15 print 'Usage: extract_from_cab.py cab_path archived_file output_dir'
16 return 1
apatrick@chromium.org1218a882010-07-29 08:02:22 +090017
maruel@chromium.org1f144a32011-11-24 04:13:44 +090018 [cab_path, archived_file, output_dir] = sys.argv[1:]
apatrick@chromium.org1218a882010-07-29 08:02:22 +090019
maruel@chromium.org1f144a32011-11-24 04:13:44 +090020 # 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:
24 return level
25
26 # The expand utility preserves the modification date and time of the archived
27 # file. Touch the extracted file. This helps build systems that compare the
28 # modification times of input and output files to determine whether to do an
29 # action.
30 os.utime(os.path.join(output_dir, archived_file), None)
31 return 0
32
33
34if __name__ == '__main__':
35 sys.exit(main())