OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Extracts a single file from a CAB archive. | 6 """Extracts a single file from a CAB archive.""" |
7 | 7 |
8 import os | 8 import os |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 | 11 |
12 if len(sys.argv) != 4: | |
13 print 'Usage: extract_from_cab.py cab_path archived_file output_dir' | |
14 sys.exit(1) | |
15 | 12 |
16 [cab_path, archived_file, output_dir] = sys.argv[1:] | 13 def main(): |
| 14 if len(sys.argv) != 4: |
| 15 print 'Usage: extract_from_cab.py cab_path archived_file output_dir' |
| 16 return 1 |
17 | 17 |
18 # Invoke the Windows expand utility to extract the file. | 18 [cab_path, archived_file, output_dir] = sys.argv[1:] |
19 level = subprocess.call(['expand', cab_path, '-F:' + archived_file, output_dir]) | |
20 if level != 0: | |
21 sys.exit(level) | |
22 | 19 |
23 # The expand utility preserves the modification date and time of the archived | 20 # Invoke the Windows expand utility to extract the file. |
24 # file. Touch the extracted file. This helps build systems that compare the | 21 level = subprocess.call( |
25 # modification times of input and output files to determine whether to do an | 22 ['expand', cab_path, '-F:' + archived_file, output_dir]) |
26 # action. | 23 if level != 0: |
27 os.utime(os.path.join(output_dir, archived_file), None) | 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 |
| 34 if __name__ == '__main__': |
| 35 sys.exit(main()) |
OLD | NEW |