| 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 os | 5 import os | 
| 6 import shutil | 6 import shutil | 
|  | 7 import json | 
|  | 8 import re | 
| 7 from StringIO import StringIO | 9 from StringIO import StringIO | 
|  | 10 from glob import glob | 
| 8 import subprocess | 11 import subprocess | 
| 9 import tempfile | 12 import tempfile | 
| 10 from xml.etree import ElementTree | 13 from xml.etree import ElementTree | 
| 11 from zipfile import ZipFile | 14 from zipfile import ZipFile | 
| 12 | 15 | 
| 13 import packager | 16 import packager | 
| 14 import packagerChrome | 17 import packagerChrome | 
| 15 | 18 | 
| 16 MANIFEST = 'appxmanifest.xml' | 19 MANIFEST = 'appxmanifest.xml' | 
| 17 ASSETS_DIR = 'Assets' | 20 ASSETS_DIR = 'Assets' | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 133     if metadata.has_section('bundles'): | 136     if metadata.has_section('bundles'): | 
| 134         bundle_tests = devenv and metadata.has_option('general', 'testScripts') | 137         bundle_tests = devenv and metadata.has_option('general', 'testScripts') | 
| 135         packagerChrome.create_bundles(params, files, bundle_tests) | 138         packagerChrome.create_bundles(params, files, bundle_tests) | 
| 136 | 139 | 
| 137     if metadata.has_section('preprocess'): | 140     if metadata.has_section('preprocess'): | 
| 138         files.preprocess(metadata.options('preprocess'), {'needsExt': True}) | 141         files.preprocess(metadata.options('preprocess'), {'needsExt': True}) | 
| 139 | 142 | 
| 140     if metadata.has_section('import_locales'): | 143     if metadata.has_section('import_locales'): | 
| 141         packagerChrome.import_locales(params, files) | 144         packagerChrome.import_locales(params, files) | 
| 142 | 145 | 
| 143     # For some mysterious reasons manifoldjs fails with a server error | 146     # The Windows Store will reject the build unless every translation of the | 
| 144     # when building the development build and there is any translation | 147     # product name has been reserved. This is hard till impossible to manage | 
| 145     # in az/messages.json for "name_devbuild", however, it works fine | 148     # with community translations, so we don't translate the product name for | 
| 146     # if we use the more specific language code az-latn. | 149     # Microsoft Edge. Furthermore, manifoldjs fails with a server error if the | 
| 147     az_translation = files.pop('_locales/az/messages.json', None) | 150     # product name is tranlated into Azerbajani. | 
| 148     if az_translation is not None: | 151     data = json.loads(files['_locales/{}/messages.json'.format(defaultLocale)]) | 
| 149         files['_locales/az-latn/messages.json'] = az_translation | 152     files['manifest.json'] = re.sub( | 
| 150 | 153         r'__MSG_(name(?:_devbuild)?)__', | 
| 151     files['manifest.json'] = packagerChrome.createManifest(params, files) | 154         lambda m: data[m.group(1)]['message'], | 
|  | 155         packagerChrome.createManifest(params, files), | 
|  | 156     ) | 
| 152 | 157 | 
| 153     if devenv: | 158     if devenv: | 
| 154         packagerChrome.add_devenv_requirements(files, metadata, params) | 159         packagerChrome.add_devenv_requirements(files, metadata, params) | 
| 155 | 160 | 
| 156     zipped = StringIO() | 161     zipped = StringIO() | 
| 157     files.zip(zipped) | 162     files.zip(zipped) | 
| 158 | 163 | 
| 159     zipped.seek(0) | 164     zipped.seek(0) | 
| 160 | 165 | 
| 161     if devenv: | 166     if devenv: | 
| 162         shutil.copyfileobj(zipped, outfile) | 167         shutil.copyfileobj(zipped, outfile) | 
| 163         return | 168         return | 
| 164 | 169 | 
| 165     tmp_dir = tempfile.mkdtemp('adblockplus_package') | 170     tmp_dir = tempfile.mkdtemp('adblockplus_package') | 
| 166     try: | 171     try: | 
| 167         src_dir = os.path.join(tmp_dir, 'src') | 172         src_dir = os.path.join(tmp_dir, 'src') | 
| 168         ext_dir = os.path.join(tmp_dir, 'ext') | 173         ext_dir = os.path.join(tmp_dir, 'ext') | 
| 169 | 174 | 
| 170         with ZipFile(zipped, 'r') as zip_file: | 175         with ZipFile(zipped, 'r') as zip_file: | 
| 171             zip_file.extractall(src_dir) | 176             zip_file.extractall(src_dir) | 
| 172 | 177 | 
| 173         cmd_env = os.environ.copy() | 178         cmd_env = os.environ.copy() | 
| 174         cmd_env['SRC_FOLDER'] = src_dir | 179         cmd_env['SRC_FOLDER'] = src_dir | 
| 175         cmd_env['EXT_FOLDER'] = ext_dir | 180         cmd_env['EXT_FOLDER'] = ext_dir | 
| 176 | 181 | 
| 177         manifold_folder = os.path.join(ext_dir, 'MSGname', 'edgeextension') |  | 
| 178         manifest_folder = os.path.join(manifold_folder, 'manifest') |  | 
| 179         asset_folder = os.path.join(manifest_folder, ASSETS_DIR) |  | 
| 180 |  | 
| 181         # prepare the extension with manifoldjs | 182         # prepare the extension with manifoldjs | 
| 182         cmd = ['npm', 'run', '--silent', 'build-edge'] | 183         cmd = ['npm', 'run', '--silent', 'build-edge'] | 
| 183         subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 184         subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 
| 184 | 185 | 
|  | 186         manifold_folder = glob(os.path.join(ext_dir, '*', 'edgeextension'))[0] | 
|  | 187         manifest_folder = os.path.join(manifold_folder, 'manifest') | 
|  | 188         asset_folder = os.path.join(manifest_folder, ASSETS_DIR) | 
|  | 189 | 
| 185         # update incomplete appxmanifest | 190         # update incomplete appxmanifest | 
| 186         intermediate_manifest = os.path.join(manifest_folder, MANIFEST) | 191         intermediate_manifest = os.path.join(manifest_folder, MANIFEST) | 
| 187         update_appx_manifest(intermediate_manifest, baseDir, files, metadata, | 192         update_appx_manifest(intermediate_manifest, baseDir, files, metadata, | 
| 188                              releaseBuild, buildNum) | 193                              releaseBuild, buildNum) | 
| 189 | 194 | 
| 190         # cleanup placeholders, copy actual images | 195         # cleanup placeholders, copy actual images | 
| 191         shutil.rmtree(asset_folder) | 196         shutil.rmtree(asset_folder) | 
| 192         os.mkdir(asset_folder) | 197         os.mkdir(asset_folder) | 
| 193         if metadata.has_section('appx_assets'): | 198         if metadata.has_section('appx_assets'): | 
| 194             for name, path in metadata.items('appx_assets'): | 199             for name, path in metadata.items('appx_assets'): | 
| 195                 path = os.path.join(baseDir, path) | 200                 path = os.path.join(baseDir, path) | 
| 196                 target = os.path.join(asset_folder, name) | 201                 target = os.path.join(asset_folder, name) | 
| 197                 shutil.copyfile(path, target) | 202                 shutil.copyfile(path, target) | 
| 198 | 203 | 
| 199         # package app with manifoldjs | 204         # package app with manifoldjs | 
| 200         cmd = ['npm', 'run', '--silent', 'package-edge'] | 205         cmd = ['npm', 'run', '--silent', 'package-edge'] | 
| 201 | 206 | 
| 202         subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 207         subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 
| 203 | 208 | 
| 204         package = os.path.join(manifold_folder, 'package', | 209         package = os.path.join(manifold_folder, 'package', | 
| 205                                'edgeExtension.appx') | 210                                'edgeExtension.appx') | 
| 206 | 211 | 
| 207         shutil.copyfile(package, outfile) | 212         shutil.copyfile(package, outfile) | 
| 208     finally: | 213     finally: | 
| 209         shutil.rmtree(tmp_dir, ignore_errors=True) | 214         shutil.rmtree(tmp_dir, ignore_errors=True) | 
| OLD | NEW | 
|---|