| OLD | NEW |
| 1 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 # | 4 # |
| 5 # This python script creates a tar archive and a C++ source file which contains | 5 # This python script creates a tar archive and a C++ source file which contains |
| 6 # the tar archive as an array of bytes. | 6 # the tar archive as an array of bytes. |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 from os.path import join, splitext | 10 from os.path import join, splitext |
| 11 import time | 11 import time |
| 12 from optparse import OptionParser | 12 from optparse import OptionParser |
| 13 from datetime import date | 13 from datetime import date |
| 14 import tarfile | 14 import tarfile |
| 15 import tempfile | 15 import tempfile |
| 16 | 16 |
| 17 def makeArchive(tar_path, client_root, files): | 17 def makeArchive(tar_path, client_root, files): |
| 18 tar = tarfile.open(tar_path, mode='w') | 18 tar = tarfile.open(tar_path, mode='w') |
| 19 for input_file_name in files: | 19 for input_file_name in files: |
| 20 # Chop off client_root. | 20 # Chop off client_root. |
| 21 archive_file_name = input_file_name[ len(client_root) : ] | 21 archive_file_name = input_file_name[ len(client_root) : ] |
| 22 # Replace back slash with forward slash. So we do not have Windows paths. |
| 23 archive_file_name = archive_file_name.replace("\\", "/") |
| 22 # Open input file and add it to the archive. | 24 # Open input file and add it to the archive. |
| 23 with open(input_file_name, 'rb') as input_file: | 25 with open(input_file_name, 'rb') as input_file: |
| 24 tarInfo = tarfile.TarInfo(name=archive_file_name) | 26 tarInfo = tarfile.TarInfo(name=archive_file_name) |
| 25 input_file.seek(0,2) | 27 input_file.seek(0,2) |
| 26 tarInfo.size = input_file.tell() | 28 tarInfo.size = input_file.tell() |
| 27 input_file.seek(0) | 29 input_file.seek(0) |
| 28 tar.addfile(tarInfo, fileobj=input_file) | 30 tar.addfile(tarInfo, fileobj=input_file) |
| 29 tar.close() | 31 tar.close() |
| 30 | 32 |
| 31 def writeCCFile(output_file, | 33 def writeCCFile(output_file, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return 0 | 144 return 0 |
| 143 | 145 |
| 144 except Exception, inst: | 146 except Exception, inst: |
| 145 sys.stderr.write('create_resources.py exception\n') | 147 sys.stderr.write('create_resources.py exception\n') |
| 146 sys.stderr.write(str(inst)) | 148 sys.stderr.write(str(inst)) |
| 147 sys.stderr.write('\n') | 149 sys.stderr.write('\n') |
| 148 return -1 | 150 return -1 |
| 149 | 151 |
| 150 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 151 sys.exit(main(sys.argv)) | 153 sys.exit(main(sys.argv)) |
| OLD | NEW |