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

Side by Side Diff: packagerSafari.py

Issue 29326188: Issue 3039 - Generate qunit/index.html based on metadata (Closed)
Patch Set: Avoid hardcoding "Adblock Plus", instead use basename Created Sept. 9, 2015, 4:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packagerChrome.py ('k') | testIndex.html.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import os 7 import os
8 import re 8 import re
9 import json 9 import json
10 import ConfigParser 10 import ConfigParser
11 from urlparse import urlparse 11 from urlparse import urlparse
12 12
13 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files 13 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files
14 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa ckageFiles, defaultLocale 14 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa ckageFiles, defaultLocale, createScriptPage
15 15
16 def processFile(path, data, params): 16 def processFile(path, data, params):
17 return data 17 return data
18 18
19 def createManifest(params, files): 19 def createManifest(params, files):
20 template = getTemplate('Info.plist.tmpl', autoEscape=True) 20 template = getTemplate('Info.plist.tmpl', autoEscape=True)
21 metadata = params['metadata'] 21 metadata = params['metadata']
22 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale]) 22 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale])
23 23
24 def parse_section(section, depth=1): 24 def parse_section(section, depth=1):
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 allowAllDomains=allowAllDomains, 86 allowAllDomains=allowAllDomains,
87 allowSecurePages=allowSecurePages, 87 allowSecurePages=allowSecurePages,
88 startScripts=(get_optional('contentScripts', 'document_start') or '').split( ), 88 startScripts=(get_optional('contentScripts', 'document_start') or '').split( ),
89 endScripts=(get_optional('contentScripts', 'document_end') or '').split(), 89 endScripts=(get_optional('contentScripts', 'document_end') or '').split(),
90 menus=parse_section('menus', 2), 90 menus=parse_section('menus', 2),
91 toolbarItems=parse_section('toolbar_items'), 91 toolbarItems=parse_section('toolbar_items'),
92 popovers=parse_section('popovers'), 92 popovers=parse_section('popovers'),
93 developerIdentifier=params.get('developerIdentifier') 93 developerIdentifier=params.get('developerIdentifier')
94 ).encode('utf-8') 94 ).encode('utf-8')
95 95
96 def createBackgroundPage(params):
97 template = getTemplate('background.html.tmpl', autoEscape=True)
98 return template.render(
99 backgroundScripts=params['metadata'].get(
100 'general', 'backgroundScripts'
101 ).split()
102 ).encode('utf-8')
103
104 def createInfoModule(params): 96 def createInfoModule(params):
105 template = getTemplate('safariInfo.js.tmpl') 97 template = getTemplate('safariInfo.js.tmpl')
106 return template.render(params).encode('utf-8') 98 return template.render(params).encode('utf-8')
107 99
108 def fixAbsoluteUrls(files): 100 def fixAbsoluteUrls(files):
109 for filename, content in files.iteritems(): 101 for filename, content in files.iteritems():
110 if os.path.splitext(filename)[1].lower() == '.html': 102 if os.path.splitext(filename)[1].lower() == '.html':
111 files[filename] = re.sub( 103 files[filename] = re.sub(
112 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', 104 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+',
113 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), 105 r'\1' + '/'.join(['..'] * filename.count('/') + ['']),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 243
252 if metadata.has_section('preprocess'): 244 if metadata.has_section('preprocess'):
253 files.preprocess( 245 files.preprocess(
254 [f for f, _ in metadata.items('preprocess')], 246 [f for f, _ in metadata.items('preprocess')],
255 {'needsExt': True} 247 {'needsExt': True}
256 ) 248 )
257 249
258 if metadata.has_section('import_locales'): 250 if metadata.has_section('import_locales'):
259 importGeckoLocales(params, files) 251 importGeckoLocales(params, files)
260 252
253 if metadata.has_option('general', 'testScripts'):
254 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmpl',
255 ('general', 'testScripts'))
256
261 if keyFile: 257 if keyFile:
262 certs, key = get_certificates_and_key(keyFile) 258 certs, key = get_certificates_and_key(keyFile)
263 params['developerIdentifier'] = get_developer_identifier(certs) 259 params['developerIdentifier'] = get_developer_identifier(certs)
264 260
265 files['lib/info.js'] = createInfoModule(params) 261 files['lib/info.js'] = createInfoModule(params)
266 files['background.html'] = createBackgroundPage(params) 262 files['background.html'] = createScriptPage(params, 'background.html.tmpl',
263 ('general', 'backgroundScripts'))
267 files['Info.plist'] = createManifest(params, files) 264 files['Info.plist'] = createManifest(params, files)
268 265
269 fixAbsoluteUrls(files) 266 fixAbsoluteUrls(files)
270 267
271 dirname = metadata.get('general', 'basename') + '.safariextension' 268 dirname = metadata.get('general', 'basename') + '.safariextension'
272 for filename in files.keys(): 269 for filename in files.keys():
273 files[os.path.join(dirname, filename)] = files.pop(filename) 270 files[os.path.join(dirname, filename)] = files.pop(filename)
274 271
275 if not devenv and keyFile: 272 if not devenv and keyFile:
276 createSignedXarArchive(outFile, files, certs, key) 273 createSignedXarArchive(outFile, files, certs, key)
277 else: 274 else:
278 files.zip(outFile) 275 files.zip(outFile)
OLDNEW
« no previous file with comments | « packagerChrome.py ('k') | testIndex.html.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld