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 """Creates a directory with with the unpacked contents of the remoting webapp. | 6 """Creates a directory with with the unpacked contents of the remoting webapp. |
7 | 7 |
8 The directory will contain a copy-of or a link-to to all remoting webapp | 8 The directory will contain a copy-of or a link-to to all remoting webapp |
9 resources. This includes HTML/JS and any plugin binaries. The script also | 9 resources. This includes HTML/JS and any plugin binaries. The script also |
10 massages resulting files appropriately with host plugin data. Finally, | 10 massages resulting files appropriately with host plugin data. Finally, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) | 49 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) |
50 for (root, dirs, files) in os.walk(directory): | 50 for (root, dirs, files) in os.walk(directory): |
51 for f in files: | 51 for f in files: |
52 full_path = os.path.join(root, f) | 52 full_path = os.path.join(root, f) |
53 rel_path = os.path.relpath(full_path, directory) | 53 rel_path = os.path.relpath(full_path, directory) |
54 zip.write(full_path, os.path.join(zipfile_base, rel_path)) | 54 zip.write(full_path, os.path.join(zipfile_base, rel_path)) |
55 zip.close() | 55 zip.close() |
56 | 56 |
57 | 57 |
58 def buildWebApp(buildtype, version, mimetype, destination, zip_path, plugin, | 58 def buildWebApp(buildtype, version, mimetype, destination, zip_path, plugin, |
59 files, locales): | 59 patchfile, files, locales): |
60 """Does the main work of building the webapp directory and zipfile. | 60 """Does the main work of building the webapp directory and zipfile. |
61 | 61 |
62 Args: | 62 Args: |
63 buildtype: the type of build ("Official" or "Dev") | 63 buildtype: the type of build ("Official" or "Dev") |
64 mimetype: A string with mimetype of plugin. | 64 mimetype: A string with mimetype of plugin. |
65 destination: A string with path to directory where the webapp will be | 65 destination: A string with path to directory where the webapp will be |
66 written. | 66 written. |
67 zipfile: A string with path to the zipfile to create containing the | 67 zipfile: A string with path to the zipfile to create containing the |
68 contents of |destination|. | 68 contents of |destination|. |
69 plugin: A string with path to the binary plugin for this webapp. | 69 plugin: A string with path to the binary plugin for this webapp. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 if os.path.isdir(plugin): | 152 if os.path.isdir(plugin): |
153 # On Mac we have a directory. | 153 # On Mac we have a directory. |
154 shutil.copytree(plugin, newPluginPath) | 154 shutil.copytree(plugin, newPluginPath) |
155 else: | 155 else: |
156 shutil.copy2(plugin, newPluginPath) | 156 shutil.copy2(plugin, newPluginPath) |
157 | 157 |
158 # Strip the linux build. | 158 # Strip the linux build. |
159 if ((platform.system() == 'Linux') and (buildtype == 'Official')): | 159 if ((platform.system() == 'Linux') and (buildtype == 'Official')): |
160 subprocess.call(["strip", newPluginPath]) | 160 subprocess.call(["strip", newPluginPath]) |
161 | 161 |
162 # Patch the files, if necessary. Do this before updating any placeholders | |
163 # in case any of the diff contexts refer to the placeholders. | |
164 if (patchfile != ''): | |
165 patchfile = os.path.join(os.getcwd(), patchfile) | |
166 if subprocess.call(['patch', '-d', destination, '-i', patchfile, | |
167 '-p1']) != 0: | |
168 return 1 | |
169 | |
162 # Set the version number in the manifest version. | 170 # Set the version number in the manifest version. |
163 findAndReplace(os.path.join(destination, 'manifest.json'), | 171 findAndReplace(os.path.join(destination, 'manifest.json'), |
164 'FULL_APP_VERSION', | 172 'FULL_APP_VERSION', |
165 version) | 173 version) |
166 | 174 |
167 # Set the correct mimetype. | 175 # Set the correct mimetype. |
168 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 176 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
169 'HOST_PLUGIN_MIMETYPE', | 177 'HOST_PLUGIN_MIMETYPE', |
170 mimetype) | 178 mimetype) |
171 | 179 |
(...skipping 23 matching lines...) Expand all Loading... | |
195 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 203 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
196 "'API_CLIENT_ID'", | 204 "'API_CLIENT_ID'", |
197 "'" + apiClientId + "'") | 205 "'" + apiClientId + "'") |
198 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 206 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
199 "'API_CLIENT_SECRET'", | 207 "'API_CLIENT_SECRET'", |
200 "'" + apiClientSecret + "'") | 208 "'" + apiClientSecret + "'") |
201 | 209 |
202 # Make the zipfile. | 210 # Make the zipfile. |
203 createZip(zip_path, destination) | 211 createZip(zip_path, destination) |
204 | 212 |
213 return 0 | |
214 | |
205 | 215 |
206 def main(): | 216 def main(): |
207 if len(sys.argv) < 7: | 217 if len(sys.argv) < 7: |
208 print ('Usage: build-webapp.py ' | 218 print ('Usage: build-webapp.py ' |
209 '<build-type> <version> <mime-type> <dst> <zip-path> <plugin> ' | 219 '<build-type> <version> <mime-type> <dst> <zip-path> <plugin> ' |
210 '<other files...> --locales <locales...>') | 220 '<patch> <other files...> --locales <locales...>') |
Wez
2013/01/15 02:24:31
nit: Would be cleaner to add --patches akin to --l
Jamie
2013/01/15 21:57:01
Much cleaner, thanks. Done.
| |
211 return 1 | 221 return 1 |
212 | 222 |
213 reading_locales = False | 223 reading_locales = False |
214 files = [] | 224 files = [] |
215 locales = [] | 225 locales = [] |
216 for arg in sys.argv[7:]: | 226 for arg in sys.argv[8:]: |
217 if arg == "--locales": | 227 if arg == "--locales": |
218 reading_locales = True; | 228 reading_locales = True; |
219 elif reading_locales: | 229 elif reading_locales: |
220 locales.append(arg) | 230 locales.append(arg) |
221 else: | 231 else: |
222 files.append(arg) | 232 files.append(arg) |
223 | 233 |
224 buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], | 234 return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], |
225 sys.argv[6], files, locales) | 235 sys.argv[5], sys.argv[6], sys.argv[7], files, locales) |
226 return 0 | |
227 | 236 |
228 | 237 |
229 if __name__ == '__main__': | 238 if __name__ == '__main__': |
230 sys.exit(main()) | 239 sys.exit(main()) |
OLD | NEW |