| Index: packagerEdge.py |
| diff --git a/packagerEdge.py b/packagerEdge.py |
| index a86ffc45d44c532a24319eb809530a4f956f644d..a9d50b61615bd9dc85b971ae072b01b4c1e0b48d 100644 |
| --- a/packagerEdge.py |
| +++ b/packagerEdge.py |
| @@ -2,20 +2,20 @@ |
| # License, v. 2.0. If a copy of the MPL was not distributed with this |
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| -import base64 |
| -import hashlib |
| +import datetime |
| import json |
| -import mimetypes |
| import os |
| -import zipfile |
| +import shutil |
| +from StringIO import StringIO |
| +import subprocess |
| +import tempfile |
| +from zipfile import ZipFile |
| import packager |
| import packagerChrome |
| # Files and directories expected inside of the .APPX archive. |
| -MANIFEST = 'AppxManifest.xml' |
| -CONTENT_TYPES = '[Content_Types].xml' |
| -BLOCKMAP = 'AppxBlockMap.xml' |
| +MANIFEST = 'appxmanifest.xml' |
| EXTENSION_DIR = 'Extension' |
| ASSETS_DIR = 'Assets' |
| @@ -29,41 +29,6 @@ def _get_template_for(filename): |
| return packager.getTemplate('edge/{}.tmpl'.format(filename)) |
| -def _lfh_size(filename): |
| - """Compute the size of zip local file header for `filename`.""" |
| - try: |
| - filename = filename.encode('utf-8') |
| - except UnicodeDecodeError: |
| - pass # filename is already a byte string. |
| - return zipfile.sizeFileHeader + len(filename) |
| - |
| - |
| -def _make_blockmap_entry(filename, data): |
| - blocks = [data[i:i + BLOCKSIZE] for i in range(0, len(data), BLOCKSIZE)] |
| - return { |
| - 'name': filename.replace('/', '\\'), |
| - 'size': len(data), |
| - 'lfh_size': _lfh_size(filename), |
| - 'blocks': [ |
| - {'hash': base64.b64encode(hashlib.sha256(block).digest())} |
| - for block in blocks |
| - ], |
| - } |
| - |
| - |
| -def create_appx_blockmap(files): |
| - """Create APPX blockmap for the list of files.""" |
| - # We don't support AppxBlockmap.xml generation for compressed zip files at |
| - # the moment. The only way to reliably calculate the compressed size of |
| - # each 64k chunk in the zip file is to override the relevant parts of |
| - # `zipfile` library. We have chosen to not do it so we produce an |
| - # uncompressed zip file that is later repackaged by Windows Store with |
| - # compression. |
| - template = _get_template_for(BLOCKMAP) |
| - files = [_make_blockmap_entry(n, d) for n, d in files.items()] |
| - return template.render(files=files).encode('utf-8') |
| - |
| - |
| def load_translation(files, locale): |
| """Load translation strings for locale from files.""" |
| path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) |
| @@ -126,27 +91,6 @@ def move_files_to_extension(files): |
| files['{}/{}'.format(EXTENSION_DIR, filename)] = files.pop(filename) |
| -def create_content_types_map(filenames): |
| - """Create [Content_Types].xml -- a mime type map.""" |
| - params = {'defaults': {}, 'overrides': {}} |
| - overrides = { |
| - BLOCKMAP: 'application/vnd.ms-appx.blockmap+xml', |
| - MANIFEST: 'application/vnd.ms-appx.manifest+xml', |
| - } |
| - types = mimetypes.MimeTypes() |
| - types.add_type('application/octet-stream', '.otf') |
| - for filename in filenames: |
| - ext = os.path.splitext(filename)[1] |
| - if ext: |
| - content_type = types.guess_type(filename, strict=False)[0] |
| - if content_type is not None: |
| - params['defaults'][ext[1:]] = content_type |
| - if filename in overrides: |
| - params['overrides']['/' + filename] = overrides[filename] |
| - content_types_template = _get_template_for(CONTENT_TYPES) |
| - return content_types_template.render(params).encode('utf-8') |
| - |
| - |
| def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. |
| buildNum=None, releaseBuild=False, keyFile=None, |
| devenv=False): |
| @@ -200,7 +144,40 @@ def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. |
| files[MANIFEST] = create_appx_manifest(params, files, |
|
Sebastian Noack
2018/07/09 14:30:55
How does that even work, since you removed templat
tlucas
2018/07/09 14:56:07
I merely renamed it to the lower-case version - an
Sebastian Noack
2018/07/09 15:36:57
Gotya. Though, I wonder whether generating a compl
|
| buildNum, releaseBuild) |
| - files[BLOCKMAP] = create_appx_blockmap(files) |
| - files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) |
| - files.zip(outfile, compression=zipfile.ZIP_STORED) |
| + zipped = StringIO() |
| + files.zip(zipped) |
| + |
| + tmp_dir = tempfile.mkdtemp('adblockplus_package') |
| + cwtd = os.path.join(tmp_dir, 'edgeextension/manifest') |
| + |
| + zipped.seek(0) |
| + with ZipFile(zipped, 'r') as zip_file: |
| + zip_file.extractall(cwtd) |
| + |
| + try: |
| + # mock a generationInfo.json, as it would be created by manifoldjs |
| + generation_info = packager.getTemplate('generationInfo.json.tmpl') |
| + with open(os.path.join(tmp_dir, 'edgeextension', |
| + 'generationInfo.json'), |
| + 'w') as fp: |
| + fp.write(generation_info.render( |
| + {'generation_time': datetime.datetime.now()})) |
| + |
| + # package app with manifoldjs |
| + cmd = ['npm', 'run', '--silent', 'package-edge'] |
| + |
| + cmd_env = os.environ.copy() |
| + cmd_env['SRC_FOLDER'] = tmp_dir |
| + subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) |
| + |
| + package = os.path.join(tmp_dir, 'edgeextension', 'package', |
| + 'edgeExtension.appx') |
| + |
| + if isinstance(outfile, basestring): |
| + shutil.copyfile(package, outfile) |
| + else: |
| + with open(package, 'rb') as fp: |
| + outfile.write(fp.read()) |
|
Sebastian Noack
2018/07/09 14:30:55
Since you already use shutil, you might want to us
tlucas
2018/07/09 14:56:07
Done.
|
| + finally: |
| + shutil.rmtree(tmp_dir, ignore_errors=True) |