Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: dart/tools/signing_script.py

Issue 23442023: Added tools/signing_script.py, used to automate steps before and after the signing step (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 import getpass
4 import hashlib
5 import optparse
6 import os
7 import shutil
8 import subprocess
9 import sys
10 import tempfile
11 import zipfile
12
13 DART_DIR = os.path.dirname(os.path.dirname(__file__))
14 GSUTIL = os.path.join(DART_DIR, 'third_party', 'gsutil', 'gsutil')
15 BASENAME_PATTERN = 'darteditor-%(system)s-%(bits)s'
16 FILENAME_PATTERN = BASENAME_PATTERN + '.zip'
17 BUCKET_PATTERN = (
18 'gs://dart-editor-archive-trunk/%(revision)s/' + FILENAME_PATTERN)
19
20 class ChangedWorkingDirectory(object):
21 def __init__(self, working_directory):
22 self._working_directory = working_directory
23
24 def __enter__(self):
25 self._old_cwd = os.getcwd()
26 print "Enter directory = ", self._working_directory
27 os.chdir(self._working_directory)
28
29 def __exit__(self, *_):
30 print "Enter directory = ", self._old_cwd
31 os.chdir(self._old_cwd)
32
33 def GetOptionsParser():
34 parser = optparse.OptionParser("usage: %prog [options]")
35 parser.add_option("--scratch-dir",
36 help="Scratch directory to use.")
37 parser.add_option("--revision", type="int",
38 help="Revision to we want to sign.")
39 parser.add_option("--prepare", action="store_true", dest="prepare",
40 default=False,
41 help="Prepare the .exe/.zip files to sign.")
42 parser.add_option("--deploy", action="store_true", dest="deploy",
43 default=False,
44 help="Pack the signed .exe/.zip files and deploy.")
45 return parser
46
47 def CalculateMd5Checksum(filename):
48 md5 = hashlib.md5()
49 with open(filename, 'rb') as f:
50 data = f.read(65536)
51 while len(data) > 0:
52 md5.update(data)
53 data = f.read(65536)
54 return md5.hexdigest()
55
56 def CreateMd5ChecksumFile(filename, md5filename):
57 checksum = CalculateMd5Checksum(filename)
58 checksum_filename = '%s.md5sum' % filename
59
60 with open(md5filename, 'w') as f:
61 f.write('%s *%s\n' % (checksum, os.path.basename(filename)))
62
63 return checksum_filename
64
65
66 def die(msg, withOptions=True):
67 print msg
68 if withOptions:
69 GetOptionsParser().print_usage()
70 sys.exit(1)
71
72 def run(command):
73 print "Running: ", command
74 process = subprocess.Popen(command,
75 stdout=subprocess.PIPE,
76 stderr=subprocess.PIPE)
77 (stdout, stderr) = process.communicate()
78 if process.returncode != 0:
79 print "DEBUG: failed to run command '%s'" % command
80 print "DEBUG: stdout = ", stdout
81 print "DEBUG: stderr = ", stderr
82 print "DEBUG: returncode = ", process.returncode
83 raise OSError(process.returncode)
84
85 def drun(command):
ricow1 2013/09/11 11:09:57 Remove, or actually add an option called --dry-run
86 print "Would Run: ", command
87
88 def clean_directory(directory):
ricow1 2013/09/11 11:09:57 add comment explaining why we don't use the build
89 if os.path.exists(directory):
90 run(['rm', '-r', directory])
91 run(['mkdir', '-p', directory])
92
93 def rm_tree(directory):
94 if os.path.exists(directory):
95 run(['rm', '-r', directory])
96
97 def copy_tree(from_dir, to_dir):
98 if os.path.exists(to_dir):
99 run(['rm', '-r', to_dir])
100 run(['cp', '-Rp', from_dir, to_dir])
101
102 def copy_file(from_file, to_file):
103 if os.path.exists(to_file):
104 run(['rm', to_file])
105 run(['cp', '-p', from_file, to_file])
106
107 def main():
108 parser = GetOptionsParser()
109 (options, args) = parser.parse_args()
110
111 if not options.scratch_dir:
ricow1 2013/09/11 11:09:57 validate that we are running on linux, this will n
112 die("No scratch directory given.")
113 if not options.revision:
114 die("No revision given.")
115 if not options.prepare and not options.deploy:
116 die("No prepare/deploy parameter given.")
117 if options.prepare and options.deploy:
118 die("Can't have prepare and deploy parameters at the same time.")
119 if len(args) > 0:
120 die("Invalid additional arguments: %s." % args)
121
122 downloads_dir = os.path.join(options.scratch_dir, 'downloads')
123 presign_dir = os.path.join(options.scratch_dir, 'presign')
124 postsign_dir = os.path.join(options.scratch_dir, 'postsign')
125 uploads_dir = os.path.join(options.scratch_dir, 'uploads')
126
127 if options.prepare:
128 # Clean all directories
129 clean_directory(downloads_dir)
130 clean_directory(presign_dir)
131 clean_directory(postsign_dir)
132 clean_directory(uploads_dir)
133 elif options.deploy:
134 #clean_directory(uploads_dir)
135 pass
136
137 # Desitination of zip files we download
138 for system in ('macos', 'win32'):
139 for bits in (32, 64):
140 config = {
141 'revision' : options.revision,
142 'system' : system,
143 'bits' : bits,
144 }
145 bucket = BUCKET_PATTERN % config
146 destination = os.path.join(downloads_dir, FILENAME_PATTERN % config)
147 destination_dir = os.path.join(downloads_dir, BASENAME_PATTERN % config)
148
149 deploy = os.path.join(uploads_dir, FILENAME_PATTERN % config)
150 deploy_dir = os.path.join(uploads_dir, BASENAME_PATTERN % config)
151
152 if options.prepare:
153 run([GSUTIL, 'cp', bucket, destination])
154 run(['unzip', destination, '-d', destination_dir])
155 if system == 'macos':
156 editor_from = os.path.join(destination_dir, 'dart', 'DartEditor.app')
ricow1 2013/09/11 11:09:57 If you add either "postfix": ".exe" or ".app" to c
157 editor_to = os.path.join(presign_dir, 'DartEditor%(bits)s.app' % confi g)
158
159 chrome_from = os.path.join(destination_dir, 'dart', 'chromium',
160 'Chromium.app')
161 chrome_to = os.path.join(presign_dir, 'Chromium%(bits)s.app' % config)
162
163 cs_from = os.path.join(destination_dir, 'dart', 'chromium',
164 'Content Shell.app')
165 cs_to = os.path.join(presign_dir, 'ContentShell%(bits)s.app' % config)
166
167 def copy_and_zip(from_dir, to_dir):
168 rm_tree(to_dir)
169 copy_tree(from_dir, to_dir)
170
171 dirname = os.path.basename(to_dir)
172 with ChangedWorkingDirectory(os.path.dirname(to_dir)):
173 run(['zip', '-r9', dirname + '.zip', dirname])
174
ricow1 2013/09/11 11:09:57 Please elaborate on the difference here, for windo
175 copy_and_zip(editor_from, editor_to)
176 copy_and_zip(chrome_from, chrome_to)
177 copy_and_zip(cs_from, cs_to)
178 elif system == 'win32':
179 editor_from = os.path.join(destination_dir, 'dart', 'DartEditor.exe')
180 editor_to = os.path.join(presign_dir, 'DartEditor%(bits)s.exe' % confi g)
181
182 chrome_from = os.path.join(destination_dir, 'dart', 'chromium',
183 'chrome.exe')
184 chrome_to = os.path.join(presign_dir, 'chrome%(bits)s.exe' % config)
185
186 cs_from = os.path.join(destination_dir, 'dart', 'chromium',
187 'content_shell.exe')
188 cs_to = os.path.join(presign_dir, 'content_shell%(bits)s.exe' % config )
189
190 copy_file(editor_from, editor_to)
191 copy_file(chrome_from, chrome_to)
192 copy_file(cs_from, cs_to)
193 elif options.deploy:
194 copy_tree(destination_dir, deploy_dir)
195 if system == 'macos':
196 editor_from = os.path.join(postsign_dir, 'DartEditor%(bits)s.app' % co nfig)
ricow1 2013/09/11 11:09:57 same comment as above, I think this would look muc
197 editor_to = os.path.join(deploy_dir, 'dart', 'DartEditor.app')
198
199 chrome_from = os.path.join(postsign_dir, 'Chromium%(bits)s.app' % conf ig)
200 chrome_to = os.path.join(deploy_dir, 'dart', 'chromium', 'Chromium.app ')
201
202 cs_from = os.path.join(postsign_dir, 'ContentShell%(bits)s.app' % conf ig)
203 cs_to = os.path.join(deploy_dir, 'dart', 'chromium', 'Content Shell.ap p')
204
205 def unzip_and_copy(from_dir, to_dir):
206 rm_tree(from_dir)
207 run(['unzip', from_dir + '.zip', '-d', postsign_dir])
208 clean_directory(to_dir)
209 copy_tree(from_dir, to_dir)
210
211 unzip_and_copy(editor_from, editor_to)
212 unzip_and_copy(chrome_from, chrome_to)
213 unzip_and_copy(cs_from, cs_to)
214 elif system == 'win32':
215 editor_from = os.path.join(postsign_dir, 'DartEditor%(bits)s.exe' % co nfig)
216 editor_to = os.path.join(deploy_dir, 'dart', 'DartEditor.exe')
217
218 chrome_from = os.path.join(postsign_dir, 'chrome%(bits)s.exe' % config )
219 chrome_to = os.path.join(deploy_dir, 'dart', 'chromium', 'chrome.exe')
220
221 cs_from = os.path.join(postsign_dir, 'content_shell%(bits)s.exe' % con fig)
222 cs_to = os.path.join(deploy_dir, 'dart', 'chromium', 'content_shell.ex e')
223
224 copy_file(editor_from, editor_to)
225 copy_file(chrome_from, chrome_to)
226 copy_file(cs_from, cs_to)
227
228 deploy_zip_file = os.path.abspath(deploy)
229 md5_zip_file = os.path.abspath(deploy) + '.md5sum'
230 with ChangedWorkingDirectory(deploy_dir):
231 run(['zip', '-r9', deploy_zip_file, 'dart'])
232 CreateMd5ChecksumFile(deploy_zip_file, md5_zip_file)
233 run([GSUTIL, 'cp', deploy_zip_file, bucket])
234 run([GSUTIL, 'cp', md5_zip_file, bucket + '.md5sum'])
235 run([GSUTIL, 'setacl', 'public-read', bucket])
236 run([GSUTIL, 'setacl', 'public-read', bucket + '.md5sum'])
237
238 if __name__ == '__main__':
239 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698