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: Made first run page always generated, fix absolute URLs for Safari during build, introduced browser… Created Oct. 31, 2013, 10:48 a.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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 118
119 def fixAbsoluteUrls(files): 119 def fixAbsoluteUrls(files):
120 for filename, content in files.iteritems(): 120 for filename, content in files.iteritems():
121 if os.path.splitext(filename)[1].lower() == '.html': 121 if os.path.splitext(filename)[1].lower() == '.html':
122 prefix = '/'.join(['..'] * filename.count('/') + [''])
123 files[filename] = re.sub( 122 files[filename] = re.sub(
124 r'(<.*?\b(?:href|src)\s*=\s*(["\']))(\/.*?)(?=\2.*?>)', 123 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+',
125 lambda m: '%s%s%s' % (m.group(1), prefix, m.group(3).lstrip('/')), 124 r'\1' + '/'.join(['..'] * filename.count('/') + ['']),
Wladimir Palant 2013/10/31 13:58:19 Why look for the entire tag if all you need is the
126 content, re.S | re.I 125 content, re.S | re.I
127 ) 126 )
128 127
129 def createSignedXarArchive(outFile, files, keyFile): 128 def createSignedXarArchive(outFile, files, keyFile):
130 import subprocess 129 import subprocess
131 import tempfile 130 import tempfile
132 import shutil 131 import shutil
133 import M2Crypto 132 import M2Crypto
134 133
135 # write files to temporary directory and create a xar archive 134 # write files to temporary directory and create a xar archive
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 fixAbsoluteUrls(files) 260 fixAbsoluteUrls(files)
262 261
263 dirname = metadata.get('general', 'basename') + '.safariextension' 262 dirname = metadata.get('general', 'basename') + '.safariextension'
264 for filename in files.keys(): 263 for filename in files.keys():
265 files[os.path.join(dirname, filename)] = files.pop(filename) 264 files[os.path.join(dirname, filename)] = files.pop(filename)
266 265
267 if keyFile: 266 if keyFile:
268 createSignedXarArchive(outFile, files, keyFile) 267 createSignedXarArchive(outFile, files, keyFile)
269 else: 268 else:
270 files.zip(outFile) 269 files.zip(outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld