OLD | NEW |
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import base64 | 5 import base64 |
6 import hashlib | 6 import hashlib |
7 import json | 7 import json |
8 import mimetypes | 8 import mimetypes |
9 import os | 9 import os |
10 import zipfile | 10 import zipfile |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 files = [_make_blockmap_entry(n, d) for n, d in files.items()] | 63 files = [_make_blockmap_entry(n, d) for n, d in files.items()] |
64 return template.render(files=files).encode('utf-8') | 64 return template.render(files=files).encode('utf-8') |
65 | 65 |
66 | 66 |
67 def load_translation(files, locale): | 67 def load_translation(files, locale): |
68 """Load translation strings for locale from files.""" | 68 """Load translation strings for locale from files.""" |
69 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) | 69 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) |
70 return json.loads(files[path]) | 70 return json.loads(files[path]) |
71 | 71 |
72 | 72 |
73 def fix_version(version): | 73 def get_appx_version(metadata, build_num): |
74 """Prepare a version number for usage in AppxManifest.xml. | 74 """Get the version number for usage in AppxManifest.xml. |
75 | 75 |
76 As required by the Windows Store, the returned version string has | 76 As required by the Windows Store, the returned version string has four |
77 four components with the last component being zero (e.g. 12.34.56.0). | 77 components, where the 3rd component is replaced with the build number |
| 78 if available, and the 4th component is always zero (e.g. 1.2.1000.0). |
78 """ | 79 """ |
79 components = version.split('.')[:3] | 80 components = metadata.get('general', 'version').split('.')[:3] |
80 components.extend(['0'] * (4 - len(components))) | 81 components.extend(['0'] * (4 - len(components))) |
| 82 if build_num: |
| 83 components[2] = build_num |
81 return '.'.join(components) | 84 return '.'.join(components) |
82 | 85 |
83 | 86 |
84 def create_appx_manifest(params, files, release_build=False): | 87 def create_appx_manifest(params, files, build_num, release_build): |
85 """Create AppxManifest.xml.""" | 88 """Create AppxManifest.xml.""" |
86 params = dict(params) | 89 params = dict(params) |
87 metadata = params['metadata'] | 90 metadata = params['metadata'] |
88 w = params['windows_version'] = {} | 91 w = params['windows_version'] = {} |
89 w['min'], w['max'] = metadata.get('compat', 'windows').split('/') | 92 w['min'], w['max'] = metadata.get('compat', 'windows').split('/') |
90 params['version'] = fix_version(params['version']) | 93 params['version'] = get_appx_version(metadata, build_num) |
91 | 94 |
92 metadata_suffix = 'release' if release_build else 'devbuild' | 95 metadata_suffix = 'release' if release_build else 'devbuild' |
93 app_extension_id = 'extension_id_' + metadata_suffix | 96 app_extension_id = 'extension_id_' + metadata_suffix |
94 if metadata.has_option('general', app_extension_id): | 97 if metadata.has_option('general', app_extension_id): |
95 params['app_extension_id'] = metadata.get('general', app_extension_id) | 98 params['app_extension_id'] = metadata.get('general', app_extension_id) |
96 else: | 99 else: |
97 params['app_extension_id'] = 'EdgeExtension' | 100 params['app_extension_id'] = 'EdgeExtension' |
98 | 101 |
99 app_id = 'app_id_' + metadata_suffix | 102 app_id = 'app_id_' + metadata_suffix |
100 params['app_id'] = metadata.get('general', app_id) | 103 params['app_id'] = metadata.get('general', app_id) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 188 |
186 files['manifest.json'] = packagerChrome.createManifest(params, files) | 189 files['manifest.json'] = packagerChrome.createManifest(params, files) |
187 | 190 |
188 move_files_to_extension(files) | 191 move_files_to_extension(files) |
189 | 192 |
190 if metadata.has_section('appx_assets'): | 193 if metadata.has_section('appx_assets'): |
191 for name, path in metadata.items('appx_assets'): | 194 for name, path in metadata.items('appx_assets'): |
192 path = os.path.join(baseDir, path) | 195 path = os.path.join(baseDir, path) |
193 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) | 196 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) |
194 | 197 |
195 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) | 198 files[MANIFEST] = create_appx_manifest(params, files, |
| 199 buildNum, releaseBuild) |
196 files[BLOCKMAP] = create_appx_blockmap(files) | 200 files[BLOCKMAP] = create_appx_blockmap(files) |
197 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) | 201 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) |
198 | 202 |
199 files.zip(outfile, compression=zipfile.ZIP_STORED) | 203 files.zip(outfile, compression=zipfile.ZIP_STORED) |
OLD | NEW |