OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Takes the output of the build step and zips the distributable package. | 6 """Takes the output of the build step and zips the distributable package. |
7 | 7 |
8 This script assumes the build script has been run to compile the add-in. | 8 This script assumes the build script has been run to compile the add-in. |
9 It zips up all files required for the add-in installation and places the | 9 It zips up all files required for the add-in installation and places the |
10 result in out/NativeClientVSAddin.zip | 10 result in out/NativeClientVSAddin.zip |
11 """ | 11 """ |
12 | 12 |
13 import os | 13 import os |
14 import zipfile | 14 import zipfile |
15 | 15 |
16 # Root output directory | 16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
17 BUILD_OUTPUT_DIRECTORY = "../../out/NativeClientVSAddIn/" | |
18 | 17 |
19 # Directory containing static installer resources | 18 # Root output directory. |
20 RESOURCE_DIRECTORY = "./InstallerResources" | 19 BUILD_OUTPUT_DIRECTORY = os.path.join( |
20 SCRIPT_DIR, | |
21 "../../out/NativeClientVSAddIn/") | |
21 | 22 |
22 # Directory that contains the build assemblies | 23 # Directory containing static installer resources. |
24 RESOURCE_DIRECTORY = os.path.join(SCRIPT_DIR, "InstallerResources/") | |
25 | |
26 # Directory that contains the build assemblies. | |
23 ASSEMBLY_DIRECTORY = os.path.join(BUILD_OUTPUT_DIRECTORY, "Debug") | 27 ASSEMBLY_DIRECTORY = os.path.join(BUILD_OUTPUT_DIRECTORY, "Debug") |
24 | 28 |
25 # Base name of the final zip file | 29 # Base name of the final zip file. |
26 OUTPUT_NAME = os.path.join(BUILD_OUTPUT_DIRECTORY, "NativeClientVSAddIn.zip") | 30 OUTPUT_NAME = os.path.join(BUILD_OUTPUT_DIRECTORY, "NativeClientVSAddIn.zip") |
27 | 31 |
28 # List of paths to files to include in the zip file | 32 # List of source/destination pairs to include in zip file. |
29 FILE_LIST = [ | 33 FILE_LIST = [ |
30 os.path.join(RESOURCE_DIRECTORY, 'NativeClientVSAddIn.AddIn'), | 34 (os.path.join(ASSEMBLY_DIRECTORY, 'NativeClientVSAddIn.dll'), |
31 os.path.join(RESOURCE_DIRECTORY, 'install.py'), | 35 'NativeClientVSAddIn.dll'), |
binji
2012/07/26 23:32:17
Maybe change to (path, zip_dir) to remove duplicat
tysand
2012/07/28 01:13:11
I assume you mean have the source be the path to t
| |
32 os.path.join(ASSEMBLY_DIRECTORY, 'NativeClientVSAddIn.dll')] | 36 (os.path.join(ASSEMBLY_DIRECTORY, 'NaCl.Build.CPPTasks.dll'), |
37 'NaCl\\NaCl.Build.CPPTasks.dll')] | |
38 | |
39 | |
40 def AddFolderToZip(path, zip_file): | |
41 """Adds an entire folder and sub folders to an open zipfile object. | |
42 | |
43 The zip_file must already be open and it is not closed by this function. | |
44 | |
45 Args: | |
46 path: Folder to add. | |
47 zipfile: Already open zip file. | |
48 | |
49 Returns: | |
50 Nothing. | |
51 """ | |
52 # Ensure the path ends in trailing slash. | |
53 path = path.rstrip("/\\") + "\\" | |
54 for dir_path, dir_names, files in os.walk(path): | |
55 for file in files: | |
56 read_path = os.path.join(dir_path, file) | |
57 zip_based_dir = dir_path[len(path):] | |
58 write_path = os.path.join(zip_based_dir, file) | |
59 zip_file.write(read_path, write_path, zipfile.ZIP_DEFLATED) | |
60 | |
33 | 61 |
34 def main(): | 62 def main(): |
35 # Zip the package | 63 # Zip the package. |
36 out_file = zipfile.ZipFile(OUTPUT_NAME, 'w') | 64 out_file = zipfile.ZipFile(OUTPUT_NAME, 'w') |
37 for file_path in FILE_LIST: | 65 for source_dest in FILE_LIST: |
38 out_file.write(file_path, os.path.basename(file_path), zipfile.ZIP_DEFLATED) | 66 out_file.write(source_dest[0], source_dest[1], zipfile.ZIP_DEFLATED) |
67 AddFolderToZip(RESOURCE_DIRECTORY, out_file) | |
39 out_file.close() | 68 out_file.close() |
40 | 69 |
70 | |
41 if __name__ == '__main__': | 71 if __name__ == '__main__': |
42 main() | 72 main() |
OLD | NEW |