LEFT | RIGHT |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 'lfh_size': _lfh_size(filename), | 46 'lfh_size': _lfh_size(filename), |
47 'blocks': [ | 47 'blocks': [ |
48 {'hash': base64.b64encode(hashlib.sha256(block).digest())} | 48 {'hash': base64.b64encode(hashlib.sha256(block).digest())} |
49 for block in blocks | 49 for block in blocks |
50 ] | 50 ] |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 def create_appx_blockmap(files): | 54 def create_appx_blockmap(files): |
55 """Create APPX blockmap for the list of files.""" | 55 """Create APPX blockmap for the list of files.""" |
| 56 # We don't support AppxBlockmap.xml generation for compressed zip files at |
| 57 # the moment. The only way to reliably calculate the compressed size of |
| 58 # each 64k chunk in the zip file is to override the relevant parts of |
| 59 # `zipfile` library. We have chosen to not do it so we produce an |
| 60 # uncompressed zip file that is later repackaged by Windows Store with |
| 61 # compression. |
56 template = _get_template_for(BLOCKMAP) | 62 template = _get_template_for(BLOCKMAP) |
57 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()] |
58 return template.render(files=files).encode('utf-8') | 64 return template.render(files=files).encode('utf-8') |
59 | 65 |
60 | 66 |
61 def load_translation(files, locale): | 67 def load_translation(files, locale): |
62 """Load translation strings for locale from files.""" | 68 """Load translation strings for locale from files.""" |
63 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) | 69 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) |
64 return json.loads(files[path]) | 70 return json.loads(files[path]) |
65 | 71 |
66 | 72 |
67 def pad_version(version): | 73 def pad_version(version): |
68 """Make sure version number has 4 groups of digits.""" | 74 """Make sure version number has 4 groups of digits.""" |
69 groups = (version.split('.') + ['0', '0', '0'])[:4] | 75 groups = (version.split('.') + ['0', '0', '0'])[:4] |
70 return '.'.join(groups) | 76 return '.'.join(groups) |
71 | 77 |
72 | 78 |
73 def create_appx_manifest(params, files): | 79 def create_appx_manifest(params, files, release_build=False): |
74 """Create AppxManifest.xml.""" | 80 """Create AppxManifest.xml.""" |
75 params = dict(params) | 81 params = dict(params) |
76 metadata = params['metadata'] | 82 metadata = params['metadata'] |
77 w = params['windows_version'] = {} | 83 w = params['windows_version'] = {} |
78 w['min'], w['max'] = metadata.get('compat', 'windows').split('/') | 84 w['min'], w['max'] = metadata.get('compat', 'windows').split('/') |
79 params.update(metadata.items('general')) | 85 params.update(metadata.items('general')) |
80 params['version'] = pad_version(params['version']) | 86 params['version'] = pad_version(params['version']) |
81 | 87 |
82 translation = load_translation(files, defaultLocale) | 88 translation = load_translation(files, defaultLocale) |
83 params['display_name'] = translation['name'] | 89 name_key = 'name' if release_build else 'name_devbuild' |
84 params['description'] = translation['description'] | 90 params['display_name'] = translation[name_key]['message'] |
| 91 params['description'] = translation['description']['message'] |
85 | 92 |
86 for size in ['44', '50', '150']: | 93 for size in ['44', '50', '150']: |
87 path = '{}/logo_{}.png'.format(ASSETS_DIR, size) | 94 path = '{}/logo_{}.png'.format(ASSETS_DIR, size) |
88 if path not in files: | 95 if path not in files: |
89 raise KeyError(path + 'is not found in files') | 96 raise KeyError(path + 'is not found in files') |
90 params['logo_' + size] = path.replace('/', '\\') | 97 params['logo_' + size] = path.replace('/', '\\') |
91 | 98 |
92 template = _get_template_for(MANIFEST) | 99 template = _get_template_for(MANIFEST) |
93 return template.render(params).encode('utf-8') | 100 return template.render(params).encode('utf-8') |
94 | 101 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 169 |
163 files['manifest.json'] = packagerChrome.createManifest(params, files) | 170 files['manifest.json'] = packagerChrome.createManifest(params, files) |
164 | 171 |
165 move_files_to_extension(files) | 172 move_files_to_extension(files) |
166 | 173 |
167 if metadata.has_section('appx_assets'): | 174 if metadata.has_section('appx_assets'): |
168 for name, path in metadata.items('appx_assets'): | 175 for name, path in metadata.items('appx_assets'): |
169 path = os.path.join(baseDir, path) | 176 path = os.path.join(baseDir, path) |
170 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) | 177 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) |
171 | 178 |
172 files[MANIFEST] = create_appx_manifest(params, files) | 179 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) |
| 180 files[BLOCKMAP] = create_appx_blockmap(files) |
173 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) | 181 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) |
174 | 182 |
175 # We don't support AppxBlockmap.xml generation for compressed zip files at | |
176 # the moment. The only way to reliably calculate the compressed size of | |
177 # each 64k chunk in the zip file is to override the relevant parts of | |
178 # `zipfile` library. We have chosen to not do it so we produce an | |
179 # uncompressed zip file that is later repackaged by Windows Store with | |
180 # compression. | |
181 files[BLOCKMAP] = create_appx_blockmap(files) | |
182 files.zip(outfile, compression=zipfile.ZIP_STORED) | 183 files.zip(outfile, compression=zipfile.ZIP_STORED) |
LEFT | RIGHT |