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

Delta Between Two Patch Sets: packagerSafari.py

Issue 11544056: Prepared buildtools for Safari (Closed)
Left Patch Set: Created Sept. 20, 2013, 4:05 p.m.
Right Patch Set: Created Oct. 31, 2013, 3:40 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 | « packagerGecko.py ('k') | safariInfo.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 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import os 18 import os
19 import re 19 import re
20 import json 20 import json
21 import ConfigParser 21 import ConfigParser
22 from urlparse import urlparse 22 from urlparse import urlparse
23 23
24 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files 24 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files
25 from packagerChrome import convertJS, convertFirstRunPage, importGeckoLocales, g etIgnoredFiles, getPackageFiles, defaultLocale 25 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa ckageFiles, defaultLocale
26 26
27 def processFile(path, data, params): 27 def processFile(path, data, params):
28 return data 28 return data
29 29
30 def createManifest(params, files): 30 def createManifest(params, files):
31 template = getTemplate('Info.plist.tmpl', autoEscape=True) 31 template = getTemplate('Info.plist.tmpl', autoEscape=True)
32 metadata = params['metadata'] 32 metadata = params['metadata']
33 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale]) 33 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale])
34 34
35 def parse_section(section, depth=1): 35 def parse_section(section, depth=1):
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 continue 83 continue
84 84
85 allowedDomains.add(url.hostname) 85 allowedDomains.add(url.hostname)
86 86
87 return template.render( 87 return template.render(
88 basename=metadata.get('general', 'basename'), 88 basename=metadata.get('general', 'basename'),
89 version=params['version'], 89 version=params['version'],
90 shortVersion=metadata.get('general', 'version'), 90 shortVersion=metadata.get('general', 'version'),
91 releaseBuild=params['releaseBuild'], 91 releaseBuild=params['releaseBuild'],
92 name=catalog['name']['message'], 92 name=catalog['name']['message'],
93 description=catalog['description']['message'], 93 description=catalog['description_safari']['message'],
94 author=get_optional('general', 'author'), 94 author=get_optional('general', 'author'),
95 homepage=get_optional('general', 'homepage'), 95 homepage=get_optional('general', 'homepage'),
96 updateURL=get_optional('general', 'updateURL'), 96 updateURL=get_optional('general', 'updateURL'),
97 allowedDomains=allowedDomains, 97 allowedDomains=allowedDomains,
98 allowAllDomains=allowAllDomains, 98 allowAllDomains=allowAllDomains,
99 allowSecurePages=allowSecurePages, 99 allowSecurePages=allowSecurePages,
100 startScripts=(get_optional('contentScripts', 'document_start') or '').split( ), 100 startScripts=(get_optional('contentScripts', 'document_start') or '').split( ),
101 endScripts= (get_optional('contentScripts', 'document_end' ) or '').split( ), 101 endScripts=(get_optional('contentScripts', 'document_end') or '').split(),
Felix Dahlke 2013/10/15 22:46:11 I'd prefer to have no whitespace after endScripts=
Sebastian Noack 2013/10/16 08:52:23 I found it more readable when the identical parts
102 menus=parse_section('menus', 2), 102 menus=parse_section('menus', 2),
103 toolbarItems=parse_section('toolbar_items'), 103 toolbarItems=parse_section('toolbar_items'),
104 popovers=parse_section('popovers') 104 popovers=parse_section('popovers')
105 ).encode('utf-8') 105 ).encode('utf-8')
106 106
107 def createBackgroundPage(params): 107 def createBackgroundPage(params):
108 template = getTemplate('background.html.tmpl') 108 template = getTemplate('background.html.tmpl', autoEscape=True)
Felix Dahlke 2013/10/15 22:46:11 Wladimir suggested to use autoEscape=True here, di
Sebastian Noack 2013/10/16 08:52:23 I added autoescaping for Info.plist.tmpl and just
109 return template.render( 109 return template.render(
110 backgroundScripts=params['metadata'].get( 110 backgroundScripts=params['metadata'].get(
111 'general', 'backgroundScripts' 111 'general', 'backgroundScripts'
112 ).split() 112 ).split()
113 ).encode('utf-8') 113 ).encode('utf-8')
114 114
115 def createInfoModule(params): 115 def createInfoModule(params):
116 template = getTemplate('safariInfo.js.tmpl') 116 template = getTemplate('safariInfo.js.tmpl')
117 return template.render(params).encode('utf-8'); 117 return template.render(params).encode('utf-8')
118
119 def fixAbsoluteUrls(files):
120 for filename, content in files.iteritems():
121 if os.path.splitext(filename)[1].lower() == '.html':
122 files[filename] = re.sub(
123 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+',
124 r'\1' + '/'.join(['..'] * filename.count('/') + ['']),
125 content, re.S | re.I
126 )
118 127
119 def createSignedXarArchive(outFile, files, keyFile): 128 def createSignedXarArchive(outFile, files, keyFile):
120 import subprocess 129 import subprocess
121 import tempfile 130 import tempfile
122 import shutil 131 import shutil
123 import M2Crypto 132 import M2Crypto
124 133
125 # write files to temporary directory and create a xar archive 134 # write files to temporary directory and create a xar archive
126 dirname = tempfile.mkdtemp() 135 dirname = tempfile.mkdtemp()
127 try: 136 try:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 files.readMappedFiles(metadata.items('mapping')) 237 files.readMappedFiles(metadata.items('mapping'))
229 files.read(baseDir) 238 files.read(baseDir)
230 239
231 if metadata.has_section('convert_js'): 240 if metadata.has_section('convert_js'):
232 convertJS(params, files) 241 convertJS(params, files)
233 242
234 if metadata.has_section('convert_img'): 243 if metadata.has_section('convert_img'):
235 from imageConversion import convertImages 244 from imageConversion import convertImages
236 convertImages(params, files) 245 convertImages(params, files)
237 246
238 if 'firstRun.html' in files: 247 if metadata.has_section('preprocess'):
239 convertFirstRunPage(params, files) 248 files.preprocess(
249 [f for f, _ in metadata.items('preprocess')],
250 {'needsExt': True}
251 )
240 252
241 if metadata.has_section('import_locales'): 253 if metadata.has_section('import_locales'):
242 importGeckoLocales(params, files) 254 importGeckoLocales(params, files)
243 255
244 files['lib/info.js'] = createInfoModule(params) 256 files['lib/info.js'] = createInfoModule(params)
245 files['background.html'] = createBackgroundPage(params) 257 files['background.html'] = createBackgroundPage(params)
246 files['Info.plist'] = createManifest(params, files) 258 files['Info.plist'] = createManifest(params, files)
259
260 fixAbsoluteUrls(files)
247 261
248 dirname = metadata.get('general', 'basename') + '.safariextension' 262 dirname = metadata.get('general', 'basename') + '.safariextension'
249 for filename in files.keys(): 263 for filename in files.keys():
250 files[os.path.join(dirname, filename)] = files.pop(filename) 264 files[os.path.join(dirname, filename)] = files.pop(filename)
251 265
252 if keyFile: 266 if keyFile:
253 createSignedXarArchive(outFile, files, keyFile) 267 createSignedXarArchive(outFile, files, keyFile)
254 else: 268 else:
255 files.zip(outFile) 269 files.zip(outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld