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 os | 5 import os |
6 import shutil | 6 import shutil |
7 from StringIO import StringIO | 7 from StringIO import StringIO |
8 import subprocess | 8 import subprocess |
9 import tempfile | 9 import tempfile |
10 from xml.etree import ElementTree | 10 from xml.etree import ElementTree |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 | 25 |
26 def register_xml_namespaces(manifest_path): | 26 def register_xml_namespaces(manifest_path): |
27 """Register namespaces of the given file, in order to preserve defaults.""" | 27 """Register namespaces of the given file, in order to preserve defaults.""" |
28 with open(manifest_path, 'r') as fp: | 28 with open(manifest_path, 'r') as fp: |
29 ns = dict([node for _, node in ElementTree.iterparse( | 29 ns = dict([node for _, node in ElementTree.iterparse( |
30 fp, events=['start-ns'])]) | 30 fp, events=['start-ns'])]) |
31 for prefix, uri in ns.items(): | 31 for prefix, uri in ns.items(): |
32 ElementTree.register_namespace(prefix, uri) | 32 ElementTree.register_namespace(prefix, uri) |
33 | 33 |
34 # Make the default namespace available in an xpath expression | |
35 ns['_d'] = ns[''] | |
36 | |
34 return ns | 37 return ns |
35 | 38 |
36 | 39 |
37 def update_appx_manifest(manifest_path, base_dir, files, metadata, | 40 def update_appx_manifest(manifest_path, base_dir, files, metadata, |
38 release_build): | 41 release_build): |
39 namespaces = register_xml_namespaces(manifest_path) | 42 namespaces = register_xml_namespaces(manifest_path) |
40 | 43 |
41 def traverse(current_elem, overwrite): | |
42 if isinstance(overwrite, dict): | |
43 for key, value in overwrite.items(): | |
44 if isinstance(key, tuple): | |
45 prefix, element = key | |
46 next_elem = current_elem.find( | |
47 '{{{}}}{}'.format(namespaces[prefix], element)) | |
48 traverse(next_elem, value) | |
49 else: | |
50 current_elem.attrib.update(overwrite) | |
51 else: | |
52 current_elem.text = overwrite | |
53 | |
54 v_min, v_max = metadata.get('compat', 'windows').split('/') | 44 v_min, v_max = metadata.get('compat', 'windows').split('/') |
55 | 45 |
56 filenames = [] | 46 filenames = [] |
57 if metadata.has_section('appx_assets'): | |
Sebastian Noack
2018/07/25 19:18:41
This check seems redundant as we fail anyway below
tlucas
2018/08/08 09:35:55
Done.
| |
58 for name, path in metadata.items('appx_assets'): | |
59 path = os.path.join(base_dir, path) | |
60 icon_path = '{}/{}'.format(ASSETS_DIR, name) | |
61 | 47 |
62 files.read(path, icon_path) | 48 for name, path in metadata.items('appx_assets'): |
63 filenames.append(icon_path) | 49 path = os.path.join(base_dir, path) |
50 icon_path = '{}/{}'.format(ASSETS_DIR, name) | |
51 | |
52 files.read(path, icon_path) | |
53 filenames.append(icon_path) | |
64 | 54 |
65 assets = packagerChrome.makeIcons(files, filenames) | 55 assets = packagerChrome.makeIcons(files, filenames) |
66 | 56 |
67 overwrite = { | 57 author = metadata.get('general', 'author') |
68 ('', 'Identity'): { | 58 |
69 'Name': packager.get_app_id(release_build, metadata), | 59 overrides = [ |
70 'Publisher': metadata.get('general', 'publisher_id'), | 60 ('_d:Identity', None, [ |
71 }, | 61 ('Name', packager.get_app_id(release_build, metadata)), |
72 ('', 'Properties'): { | 62 ('Publisher', metadata.get('general', 'publisher_id')), |
73 ('', 'PublisherDisplayName'): metadata.get('general', 'author'), | 63 ]), |
74 ('', 'Logo'): assets[50], | 64 ('_d:Properties/_d:PublisherDisplayName', author, []), |
75 }, | 65 ('_d:Properties/_d:Logo', assets[50], []), |
76 ('', 'Dependencies'): { | 66 ('_d:Dependencies/_d:TargetDeviceFamily', None, [ |
77 ('', 'TargetDeviceFamily'): { | 67 ('MaxVersionTested', v_max), |
78 'MaxVersionTested': v_max, | 68 ('MinVersion', v_min), |
79 'MinVersion': v_min, | 69 ]), |
80 }, | 70 ('_d:Applications/_d:Application/uap:VisualElements', None, [ |
81 }, | 71 ('Square150x150Logo', assets[150]), |
82 ('', 'Applications'): { | 72 ('Square44x44Logo', assets[44]), |
83 ('', 'Application'): { | 73 ]), |
84 ('uap', 'VisualElements'): { | 74 ] |
85 'Square150x150Logo': assets[150], | |
86 'Square44x44Logo': assets[44], | |
87 }, | |
88 }, | |
89 }, | |
90 } | |
91 | 75 |
92 tree = ElementTree.parse(manifest_path) | 76 tree = ElementTree.parse(manifest_path) |
93 root = tree.getroot() | 77 root = tree.getroot() |
94 | 78 |
95 traverse(root, overwrite) | 79 for xpath, text, attributes in overrides: |
80 element = root.find(xpath, namespaces) | |
81 if text: | |
82 element.text = text | |
83 for attr, value in attributes: | |
84 element.set(attr, value) | |
96 | 85 |
97 tree.write(manifest_path, encoding='utf-8', xml_declaration=True) | 86 tree.write(manifest_path, encoding='utf-8', xml_declaration=True) |
98 | 87 |
99 | 88 |
100 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. | 89 def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. |
101 buildNum=None, releaseBuild=False, keyFile=None, | 90 buildNum=None, releaseBuild=False, keyFile=None, |
102 devenv=False): | 91 devenv=False): |
103 | 92 |
104 metadata = packager.readMetadata(baseDir, type) | 93 metadata = packager.readMetadata(baseDir, type) |
105 version = packager.getBuildVersion(baseDir, metadata, releaseBuild, | 94 version = packager.getBuildVersion(baseDir, metadata, releaseBuild, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 cmd = ['npm', 'run', '--silent', 'package-edge'] | 177 cmd = ['npm', 'run', '--silent', 'package-edge'] |
189 | 178 |
190 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) | 179 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) |
191 | 180 |
192 package = os.path.join(manifold_folder, 'package', | 181 package = os.path.join(manifold_folder, 'package', |
193 'edgeExtension.appx') | 182 'edgeExtension.appx') |
194 | 183 |
195 shutil.copyfile(package, outfile) | 184 shutil.copyfile(package, outfile) |
196 finally: | 185 finally: |
197 shutil.rmtree(tmp_dir, ignore_errors=True) | 186 shutil.rmtree(tmp_dir, ignore_errors=True) |
LEFT | RIGHT |