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: Addressed comments Created Oct. 30, 2013, 5:22 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,
(...skipping 72 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(),
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', autoEscape=True) 108 template = getTemplate('background.html.tmpl', autoEscape=True)
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 {'needsExt': True} 250 {'needsExt': True}
242 ) 251 )
243 252
244 if metadata.has_section('import_locales'): 253 if metadata.has_section('import_locales'):
245 importGeckoLocales(params, files) 254 importGeckoLocales(params, files)
246 255
247 files['lib/info.js'] = createInfoModule(params) 256 files['lib/info.js'] = createInfoModule(params)
248 files['background.html'] = createBackgroundPage(params) 257 files['background.html'] = createBackgroundPage(params)
249 files['Info.plist'] = createManifest(params, files) 258 files['Info.plist'] = createManifest(params, files)
250 259
260 fixAbsoluteUrls(files)
261
251 dirname = metadata.get('general', 'basename') + '.safariextension' 262 dirname = metadata.get('general', 'basename') + '.safariextension'
252 for filename in files.keys(): 263 for filename in files.keys():
253 files[os.path.join(dirname, filename)] = files.pop(filename) 264 files[os.path.join(dirname, filename)] = files.pop(filename)
254 265
255 if keyFile: 266 if keyFile:
256 createSignedXarArchive(outFile, files, keyFile) 267 createSignedXarArchive(outFile, files, keyFile)
257 else: 268 else:
258 files.zip(outFile) 269 files.zip(outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld