| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 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 | 12 |
| 13 def main(): | 13 def main(): |
| 14 if len(sys.argv) != 4: | 14 if len(sys.argv) != 4: |
| 15 print 'Usage: extract_from_cab.py cab_path archived_file output_dir' | 15 print 'Usage: extract_from_cab.py cab_path archived_file output_dir' |
| 16 return 1 | 16 return 1 |
| 17 | 17 |
| 18 [cab_path, archived_file, output_dir] = sys.argv[1:] | 18 [cab_path, archived_file, output_dir] = sys.argv[1:] |
| 19 | 19 |
| 20 # Invoke the Windows expand utility to extract the file. | 20 # Invoke the Windows expand utility to extract the file. |
| 21 level = subprocess.call( | 21 level = subprocess.call( |
| 22 ['expand', cab_path, '-F:' + archived_file, output_dir]) | 22 ['expand', cab_path, '-F:' + archived_file, output_dir]) |
| 23 if level != 0: | 23 if level != 0: |
| 24 return level | 24 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 |
| 25 | 31 |
| 26 # The expand utility preserves the modification date and time of the archived | 32 # 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 | 33 # 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 | 34 # modification times of input and output files to determine whether to do an |
| 29 # action. | 35 # action. |
| 30 os.utime(os.path.join(output_dir, archived_file), None) | 36 os.utime(os.path.join(output_dir, archived_file), None) |
| 31 return 0 | 37 return 0 |
| 32 | 38 |
| 33 | 39 |
| 34 if __name__ == '__main__': | 40 if __name__ == '__main__': |
| 35 sys.exit(main()) | 41 sys.exit(main()) |
| OLD | NEW |