Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: packagerEdge.py

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Left Patch Set: Fixed spelling mistake Created Sept. 19, 2017, 2:49 p.m.
Right Patch Set: Addressed final nits Created Oct. 10, 2017, 5:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « packagerChrome.py ('k') | templates/modules.js.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 files = [_make_blockmap_entry(n, d) for n, d in files.items()] 63 files = [_make_blockmap_entry(n, d) for n, d in files.items()]
64 return template.render(files=files).encode('utf-8') 64 return template.render(files=files).encode('utf-8')
65 65
66 66
67 def load_translation(files, locale): 67 def load_translation(files, locale):
68 """Load translation strings for locale from files.""" 68 """Load translation strings for locale from files."""
69 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale) 69 path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale)
70 return json.loads(files[path]) 70 return json.loads(files[path])
71 71
72 72
73 def pad_version(version): 73 def get_appx_version(metadata, build_num):
74 """Make sure version number has 4 groups of digits.""" 74 """Get the version number for usage in AppxManifest.xml.
75 groups = (version.split('.') + ['0', '0', '0'])[:4] 75
76 return '.'.join(groups) 76 As required by the Windows Store, the returned version string has four
77 77 components, where the 3rd component is replaced with the build number
78 78 if available, and the 4th component is always zero (e.g. 1.2.1000.0).
79 def create_appx_manifest(params, files, release_build=False): 79 """
80 components = metadata.get('general', 'version').split('.')[:3]
81 components.extend(['0'] * (4 - len(components)))
82 if build_num:
83 components[2] = build_num
84 return '.'.join(components)
85
86
87 def create_appx_manifest(params, files, build_num, release_build):
80 """Create AppxManifest.xml.""" 88 """Create AppxManifest.xml."""
81 params = dict(params) 89 params = dict(params)
82 metadata = params['metadata'] 90 metadata = params['metadata']
83 w = params['windows_version'] = {} 91 w = params['windows_version'] = {}
84 w['min'], w['max'] = metadata.get('compat', 'windows').split('/') 92 w['min'], w['max'] = metadata.get('compat', 'windows').split('/')
85 params.update(metadata.items('general')) 93 params['version'] = get_appx_version(metadata, build_num)
86 params['version'] = pad_version(params['version'])
87 94
88 metadata_suffix = 'release' if release_build else 'devbuild' 95 metadata_suffix = 'release' if release_build else 'devbuild'
89 app_extension_id = 'extension_id_' + metadata_suffix 96 app_extension_id = 'extension_id_' + metadata_suffix
90 if metadata.has_option('general', app_extension_id): 97 if metadata.has_option('general', app_extension_id):
91 params['app_extension_id'] = metadata.get('general', app_extension_id) 98 params['app_extension_id'] = metadata.get('general', app_extension_id)
92 else: 99 else:
93 params['app_extension_id'] = 'EdgeExtension' 100 params['app_extension_id'] = 'EdgeExtension'
94 101
95 app_id = 'app_id_' + metadata_suffix 102 app_id = 'app_id_' + metadata_suffix
96 params['app_id'] = metadata.get('general', app_id) 103 params['app_id'] = metadata.get('general', app_id)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 188
182 files['manifest.json'] = packagerChrome.createManifest(params, files) 189 files['manifest.json'] = packagerChrome.createManifest(params, files)
183 190
184 move_files_to_extension(files) 191 move_files_to_extension(files)
185 192
186 if metadata.has_section('appx_assets'): 193 if metadata.has_section('appx_assets'):
187 for name, path in metadata.items('appx_assets'): 194 for name, path in metadata.items('appx_assets'):
188 path = os.path.join(baseDir, path) 195 path = os.path.join(baseDir, path)
189 files.read(path, '{}/{}'.format(ASSETS_DIR, name)) 196 files.read(path, '{}/{}'.format(ASSETS_DIR, name))
190 197
191 files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) 198 files[MANIFEST] = create_appx_manifest(params, files,
199 buildNum, releaseBuild)
192 files[BLOCKMAP] = create_appx_blockmap(files) 200 files[BLOCKMAP] = create_appx_blockmap(files)
193 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) 201 files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP])
194 202
195 files.zip(outfile, compression=zipfile.ZIP_STORED) 203 files.zip(outfile, compression=zipfile.ZIP_STORED)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld