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 os | 5 import os |
6 import shutil | 6 import shutil |
7 import json | 7 import json |
8 import re | 8 import re |
9 import errno | |
10 from StringIO import StringIO | 9 from StringIO import StringIO |
11 from glob import glob | 10 from glob import glob |
12 import subprocess | 11 import subprocess |
13 import tempfile | 12 import tempfile |
14 from xml.etree import ElementTree | 13 from xml.etree import ElementTree |
15 from zipfile import ZipFile | 14 from zipfile import ZipFile |
16 | 15 |
17 import packager | 16 import packager |
18 import packagerChrome | 17 import packagerChrome |
19 | 18 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 tree = ElementTree.parse(manifest_path) | 94 tree = ElementTree.parse(manifest_path) |
96 root = tree.getroot() | 95 root = tree.getroot() |
97 | 96 |
98 for xpath, text, attributes in overrides: | 97 for xpath, text, attributes in overrides: |
99 element = root.find(xpath, namespaces) | 98 element = root.find(xpath, namespaces) |
100 if text: | 99 if text: |
101 element.text = text | 100 element.text = text |
102 for attr, value in attributes: | 101 for attr, value in attributes: |
103 element.set(attr, value) | 102 element.set(attr, value) |
104 | 103 |
105 # Windows rejects to install packages that contain localized resources | 104 # Windows rejects to install the package if it contains localized |
106 # for either 'az' or 'uz'. Both languages have dialects using different | 105 # resources for 'az', or if the manifest lists resources for 'uz' |
107 # scripts. Using the script-sepcific language code instead seems to work. | 106 # but the relevant strings aren't translated. |
108 resources_dir = os.path.join(os.path.dirname(manifest_path), 'Resources') | 107 resources_dir = os.path.join(os.path.dirname(manifest_path), 'Resources') |
109 for element in root.findall('_d:Resources/_d:Resource', namespaces): | 108 resources_element = root.find('_d:Resources', namespaces) |
110 old_code = element.get('Language') | 109 for element in resources_element.findall('_d:Resource', namespaces): |
111 new_code = {'az': 'az-latn', | 110 language = element.get('Language') |
112 'uz': 'uz-cyrl'}.get(old_code) | 111 if language: |
113 if new_code: | 112 folder = os.path.join(resources_dir, language) |
114 element.set('Language', new_code) | 113 if language == 'az': |
115 try: | 114 shutil.rmtree(folder, ignore_errors=True) |
116 os.rename(os.path.join(resources_dir, old_code), | 115 if not os.path.exists(folder): |
117 os.path.join(resources_dir, new_code)) | 116 resources_element.remove(element) |
118 except OSError as e: | |
119 if e.errno != errno.ENOENT: | |
120 raise | |
121 | 117 |
122 tree.write(manifest_path, encoding='utf-8', xml_declaration=True) | 118 tree.write(manifest_path, encoding='utf-8', xml_declaration=True) |
123 | 119 |
124 | 120 |
125 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. | 121 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. |
126 buildNum=None, releaseBuild=False, keyFile=None, | 122 buildNum=None, releaseBuild=False, keyFile=None, |
127 devenv=False): | 123 devenv=False): |
128 | 124 |
129 metadata = packager.readMetadata(baseDir, type) | 125 metadata = packager.readMetadata(baseDir, type) |
130 version = packager.getBuildVersion(baseDir, metadata, releaseBuild, | 126 version = packager.getBuildVersion(baseDir, metadata, releaseBuild, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 cmd = ['npm', 'run', '--silent', 'package-edge'] | 219 cmd = ['npm', 'run', '--silent', 'package-edge'] |
224 | 220 |
225 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 221 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) |
226 | 222 |
227 package = os.path.join(manifold_folder, 'package', | 223 package = os.path.join(manifold_folder, 'package', |
228 'edgeExtension.appx') | 224 'edgeExtension.appx') |
229 | 225 |
230 shutil.copyfile(package, outfile) | 226 shutil.copyfile(package, outfile) |
231 finally: | 227 finally: |
232 shutil.rmtree(tmp_dir, ignore_errors=True) | 228 shutil.rmtree(tmp_dir, ignore_errors=True) |
LEFT | RIGHT |