Left: | ||
Right: |
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 # original content would be lost. | 107 # original content would be lost. |
108 names = sorted(files.keys(), key=len, reverse=True) | 108 names = sorted(files.keys(), key=len, reverse=True) |
109 for filename in names: | 109 for filename in names: |
110 files['{}/{}'.format(EXTENSION_DIR, filename)] = files.pop(filename) | 110 files['{}/{}'.format(EXTENSION_DIR, filename)] = files.pop(filename) |
111 | 111 |
112 | 112 |
113 def create_content_types_map(filenames): | 113 def create_content_types_map(filenames): |
114 """Create [Content_Types].xml -- a mime type map.""" | 114 """Create [Content_Types].xml -- a mime type map.""" |
115 params = {'defaults': {}, 'overrides': {}} | 115 params = {'defaults': {}, 'overrides': {}} |
116 overrides = { | 116 overrides = { |
117 '.otf': 'application/octet-stream', | |
Sebastian Noack
2016/10/28 12:43:51
Why not using 'application/font-sfnt' or 'applicat
Vasily Kuznetsov
2016/11/30 15:11:45
'application/octet-stream' is what Microsoft and F
| |
118 BLOCKMAP: 'application/vnd.ms-appx.blockmap+xml', | 117 BLOCKMAP: 'application/vnd.ms-appx.blockmap+xml', |
119 MANIFEST: 'application/vnd.ms-appx.manifest+xml' | 118 MANIFEST: 'application/vnd.ms-appx.manifest+xml' |
120 } | 119 } |
120 types = mimetypes.MimeTypes() | |
121 types.add_type('application/octet-stream', '.otf') | |
121 for filename in filenames: | 122 for filename in filenames: |
122 ext = os.path.splitext(filename)[1] | 123 ext = os.path.splitext(filename)[1] |
123 if ext and ext not in params['defaults']: | 124 if ext: |
Sebastian Noack
2016/10/28 12:43:51
Rather than adding a special case here, note that
Vasily Kuznetsov
2016/11/30 15:11:45
You're right, this is better.
Done.
| |
124 content_type = mimetypes.guess_type(filename, strict=False)[0] | 125 content_type = types.guess_type(filename, strict=False)[0] |
125 if ext in overrides: | |
126 content_type = overrides[ext] | |
127 if content_type is not None: | 126 if content_type is not None: |
128 params['defaults'][ext[1:]] = content_type | 127 params['defaults'][ext[1:]] = content_type |
129 if filename in overrides: | 128 if filename in overrides: |
130 params['overrides']['/' + filename] = overrides[filename] | 129 params['overrides']['/' + filename] = overrides[filename] |
131 content_types_template = _get_template_for(CONTENT_TYPES) | 130 content_types_template = _get_template_for(CONTENT_TYPES) |
132 return content_types_template.render(params).encode('utf-8') | 131 return content_types_template.render(params).encode('utf-8') |
133 | 132 |
134 | 133 |
135 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. | 134 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. |
136 buildNum=None, releaseBuild=False, keyFile=None, | 135 buildNum=None, releaseBuild=False, keyFile=None, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 if metadata.has_section('appx_assets'): | 176 if metadata.has_section('appx_assets'): |
178 for name, path in metadata.items('appx_assets'): | 177 for name, path in metadata.items('appx_assets'): |
179 path = os.path.join(baseDir, path) | 178 path = os.path.join(baseDir, path) |
180 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) | 179 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) |
181 | 180 |
182 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) | 181 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) |
183 files[BLOCKMAP] = create_appx_blockmap(files) | 182 files[BLOCKMAP] = create_appx_blockmap(files) |
184 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) | 183 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) |
185 | 184 |
186 files.zip(outfile, compression=zipfile.ZIP_STORED) | 185 files.zip(outfile, compression=zipfile.ZIP_STORED) |
LEFT | RIGHT |