| 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 |
| 11 | 11 |
| 12 import packager | 12 import packager |
| 13 import packagerChrome | 13 import packagerChrome |
| 14 from packager import (readMetadata, getDefaultFileName) |
| 14 | 15 |
| 15 # Files and directories expected inside of the .APPX archive. | 16 # Files and directories expected inside of the .APPX archive. |
| 16 MANIFEST = 'AppxManifest.xml' | 17 MANIFEST = 'AppxManifest.xml' |
| 17 CONTENT_TYPES = '[Content_Types].xml' | 18 CONTENT_TYPES = '[Content_Types].xml' |
| 18 BLOCKMAP = 'AppxBlockMap.xml' | 19 BLOCKMAP = 'AppxBlockMap.xml' |
| 19 EXTENSION_DIR = 'Extension' | 20 EXTENSION_DIR = 'Extension' |
| 20 ASSETS_DIR = 'Assets' | 21 ASSETS_DIR = 'Assets' |
| 21 | 22 |
| 22 # Size of uncompressed block in the APPX block map. | 23 # Size of uncompressed block in the APPX block map. |
| 23 BLOCKSIZE = 64 * 1024 | 24 BLOCKSIZE = 64 * 1024 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 params['version'] = pad_version(params['version']) | 87 params['version'] = pad_version(params['version']) |
| 87 | 88 |
| 88 translation = load_translation(files, defaultLocale) | 89 translation = load_translation(files, defaultLocale) |
| 89 name_key = 'name' if release_build else 'name_devbuild' | 90 name_key = 'name' if release_build else 'name_devbuild' |
| 90 params['display_name'] = translation[name_key]['message'] | 91 params['display_name'] = translation[name_key]['message'] |
| 91 params['description'] = translation['description']['message'] | 92 params['description'] = translation['description']['message'] |
| 92 | 93 |
| 93 for size in ['44', '50', '150']: | 94 for size in ['44', '50', '150']: |
| 94 path = '{}/logo_{}.png'.format(ASSETS_DIR, size) | 95 path = '{}/logo_{}.png'.format(ASSETS_DIR, size) |
| 95 if path not in files: | 96 if path not in files: |
| 96 raise KeyError(path + 'is not found in files') | 97 raise KeyError(path + ' is not found in files') |
| 97 params['logo_' + size] = path.replace('/', '\\') | 98 params['logo_' + size] = path.replace('/', '\\') |
| 98 | 99 |
| 99 template = _get_template_for(MANIFEST) | 100 template = _get_template_for(MANIFEST) |
| 100 return template.render(params).encode('utf-8') | 101 return template.render(params).encode('utf-8') |
| 101 | 102 |
| 102 | 103 |
| 103 def move_files_to_extension(files): | 104 def move_files_to_extension(files): |
| 104 """Move all files into `Extension` folder for APPX packaging.""" | 105 """Move all files into `Extension` folder for APPX packaging.""" |
| 105 # We sort the files to ensure that 'Extension/xyz' is moved before 'xyz'. | 106 # We sort the files to ensure that 'Extension/xyz' is moved before 'xyz'. |
| 106 # If 'xyz' is moved first, it would overwrite 'Extension/xyz' and its | 107 # If 'xyz' is moved first, it would overwrite 'Extension/xyz' and its |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 if metadata.has_section('appx_assets'): | 175 if metadata.has_section('appx_assets'): |
| 175 for name, path in metadata.items('appx_assets'): | 176 for name, path in metadata.items('appx_assets'): |
| 176 path = os.path.join(baseDir, path) | 177 path = os.path.join(baseDir, path) |
| 177 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) | 178 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) |
| 178 | 179 |
| 179 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) | 180 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) |
| 180 files[BLOCKMAP] = create_appx_blockmap(files) | 181 files[BLOCKMAP] = create_appx_blockmap(files) |
| 181 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) | 182 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) |
| 182 | 183 |
| 183 files.zip(outfile, compression=zipfile.ZIP_STORED) | 184 files.zip(outfile, compression=zipfile.ZIP_STORED) |
| OLD | NEW |