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

Delta Between Two Patch Sets: packagerSafari.py

Issue 29322519: Issue 2796 - Added DeveloperIdentifier to Info.plist for Safari 9 (Closed)
Left Patch Set: Created July 16, 2015, 2:32 p.m.
Right Patch Set: Fixed typo in comment Created July 17, 2015, 11:07 a.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 | « Info.plist.tmpl ('k') | no next file » | 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 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
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 def fixAbsoluteUrls(files): 108 def fixAbsoluteUrls(files):
109 for filename, content in files.iteritems(): 109 for filename, content in files.iteritems():
110 if os.path.splitext(filename)[1].lower() == '.html': 110 if os.path.splitext(filename)[1].lower() == '.html':
111 files[filename] = re.sub( 111 files[filename] = re.sub(
112 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', 112 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+',
113 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), 113 r'\1' + '/'.join(['..'] * filename.count('/') + ['']),
114 content, re.S | re.I 114 content, re.S | re.I
115 ) 115 )
116 116
117 def get_certificates_and_key(keyfile): 117 def get_certificates_and_key(keyfile):
kzar 2015/07/16 15:39:53 Nit: Use camel case to match the other function na
Sebastian Noack 2015/07/16 15:50:48 I think we should move to PEP-8 for new code.
kzar 2015/07/16 15:56:35 From PEP-8: "A style guide is about consistency.
Wladimir Palant 2015/07/16 19:16:23 I agree with Sebastian - we are never going to tak
kzar 2015/07/17 08:51:18 Acknowledged.
118 import M2Crypto 118 import M2Crypto
119 119
120 certs = [] 120 certs = []
121 bio = M2Crypto.BIO.openfile(keyfile) 121 bio = M2Crypto.BIO.openfile(keyfile)
122 122
123 try: 123 try:
124 key = M2Crypto.RSA.load_key_bio(bio) 124 key = M2Crypto.RSA.load_key_bio(bio)
125 bio.reset() 125 bio.reset()
126 while True: 126 while True:
127 try: 127 try:
128 certs.append(M2Crypto.X509.load_cert_bio(bio)) 128 certs.append(M2Crypto.X509.load_cert_bio(bio))
129 except M2Crypto.X509.X509Error: 129 except M2Crypto.X509.X509Error:
130 break 130 break
131 finally: 131 finally:
132 bio.close() 132 bio.close()
133 133
134 return certs, key 134 return certs, key
135 135
136 def get_developer_identifier(certs): 136 def get_developer_identifier(certs):
137 for cert in certs: 137 for cert in certs:
138 subject = cert.get_subject() 138 subject = cert.get_subject()
139 for entry in subject.get_entries_by_nid(subject.nid['CN']): 139 for entry in subject.get_entries_by_nid(subject.nid['CN']):
140 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) 140 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text())
141 if m: 141 if m:
142 return m.group(1) 142 return m.group(1)
143 143
144 raise Exception('No safari developer certificate found in chain') 144 raise Exception('No Safari developer certificate found in chain')
kzar 2015/07/16 15:39:53 Nit: Capitalise Safari?
Sebastian Noack 2015/07/16 15:50:48 This code where merely copied from sitescripts. Bu
145 145
146 def createSignedXarArchive(outFile, files, certs, key): 146 def createSignedXarArchive(outFile, files, certs, key):
147 import subprocess 147 import subprocess
148 import tempfile 148 import tempfile
149 import shutil 149 import shutil
150 import M2Crypto 150 import M2Crypto
151 151
152 # write files to temporary directory and create a xar archive 152 # write files to temporary directory and create a xar archive
153 dirname = tempfile.mkdtemp() 153 dirname = tempfile.mkdtemp()
154 try: 154 try:
(...skipping 10 matching lines...) Expand all
165 165
166 subprocess.check_output( 166 subprocess.check_output(
167 ['xar', '-czf', os.path.abspath(outFile), '--distribution'] + os.listdir(d irname), 167 ['xar', '-czf', os.path.abspath(outFile), '--distribution'] + os.listdir(d irname),
168 cwd=dirname 168 cwd=dirname
169 ) 169 )
170 finally: 170 finally:
171 shutil.rmtree(dirname) 171 shutil.rmtree(dirname)
172 172
173 certificate_filenames = [] 173 certificate_filenames = []
174 try: 174 try:
175 # write each certificate in DER format to a seperate 175 # write each certificate in DER format to a separate
176 # temporary file, that they can be passed to xar 176 # temporary file, that they can be passed to xar
177 for cert in certs: 177 for cert in certs:
178 fd, filename = tempfile.mkstemp() 178 fd, filename = tempfile.mkstemp()
179 try: 179 try:
180 certificate_filenames.append(filename) 180 certificate_filenames.append(filename)
181 os.write(fd, cert.as_der()) 181 os.write(fd, cert.as_der())
182 finally: 182 finally:
183 os.close(fd) 183 os.close(fd)
184 184
185 # add certificates and placeholder signature 185 # add certificates and placeholder signature
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 fixAbsoluteUrls(files) 269 fixAbsoluteUrls(files)
270 270
271 dirname = metadata.get('general', 'basename') + '.safariextension' 271 dirname = metadata.get('general', 'basename') + '.safariextension'
272 for filename in files.keys(): 272 for filename in files.keys():
273 files[os.path.join(dirname, filename)] = files.pop(filename) 273 files[os.path.join(dirname, filename)] = files.pop(filename)
274 274
275 if not devenv and keyFile: 275 if not devenv and keyFile:
276 createSignedXarArchive(outFile, files, certs, key) 276 createSignedXarArchive(outFile, files, certs, key)
277 else: 277 else:
278 files.zip(outFile) 278 files.zip(outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld