Chromium Code Reviews| Index: dart/tools/signing_script.py |
| diff --git a/dart/tools/signing_script.py b/dart/tools/signing_script.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..2da51fd825047fecf88bb481313a2e5807692638 |
| --- /dev/null |
| +++ b/dart/tools/signing_script.py |
| @@ -0,0 +1,239 @@ |
| +#!/usr/bin/env python |
| + |
| +import getpass |
| +import hashlib |
| +import optparse |
| +import os |
| +import shutil |
| +import subprocess |
| +import sys |
| +import tempfile |
| +import zipfile |
| + |
| +DART_DIR = os.path.dirname(os.path.dirname(__file__)) |
| +GSUTIL = os.path.join(DART_DIR, 'third_party', 'gsutil', 'gsutil') |
| +BASENAME_PATTERN = 'darteditor-%(system)s-%(bits)s' |
| +FILENAME_PATTERN = BASENAME_PATTERN + '.zip' |
| +BUCKET_PATTERN = ( |
| + 'gs://dart-editor-archive-trunk/%(revision)s/' + FILENAME_PATTERN) |
| + |
| +class ChangedWorkingDirectory(object): |
| + def __init__(self, working_directory): |
| + self._working_directory = working_directory |
| + |
| + def __enter__(self): |
| + self._old_cwd = os.getcwd() |
| + print "Enter directory = ", self._working_directory |
| + os.chdir(self._working_directory) |
| + |
| + def __exit__(self, *_): |
| + print "Enter directory = ", self._old_cwd |
| + os.chdir(self._old_cwd) |
| + |
| +def GetOptionsParser(): |
| + parser = optparse.OptionParser("usage: %prog [options]") |
| + parser.add_option("--scratch-dir", |
| + help="Scratch directory to use.") |
| + parser.add_option("--revision", type="int", |
| + help="Revision to we want to sign.") |
| + parser.add_option("--prepare", action="store_true", dest="prepare", |
| + default=False, |
| + help="Prepare the .exe/.zip files to sign.") |
| + parser.add_option("--deploy", action="store_true", dest="deploy", |
| + default=False, |
| + help="Pack the signed .exe/.zip files and deploy.") |
| + return parser |
| + |
| +def CalculateMd5Checksum(filename): |
| + md5 = hashlib.md5() |
| + with open(filename, 'rb') as f: |
| + data = f.read(65536) |
| + while len(data) > 0: |
| + md5.update(data) |
| + data = f.read(65536) |
| + return md5.hexdigest() |
| + |
| +def CreateMd5ChecksumFile(filename, md5filename): |
| + checksum = CalculateMd5Checksum(filename) |
| + checksum_filename = '%s.md5sum' % filename |
| + |
| + with open(md5filename, 'w') as f: |
| + f.write('%s *%s\n' % (checksum, os.path.basename(filename))) |
| + |
| + return checksum_filename |
| + |
| + |
| +def die(msg, withOptions=True): |
| + print msg |
| + if withOptions: |
| + GetOptionsParser().print_usage() |
| + sys.exit(1) |
| + |
| +def run(command): |
| + print "Running: ", command |
| + process = subprocess.Popen(command, |
| + stdout=subprocess.PIPE, |
| + stderr=subprocess.PIPE) |
| + (stdout, stderr) = process.communicate() |
| + if process.returncode != 0: |
| + print "DEBUG: failed to run command '%s'" % command |
| + print "DEBUG: stdout = ", stdout |
| + print "DEBUG: stderr = ", stderr |
| + print "DEBUG: returncode = ", process.returncode |
| + raise OSError(process.returncode) |
| + |
| +def drun(command): |
|
ricow1
2013/09/11 11:09:57
Remove, or actually add an option called --dry-run
|
| + print "Would Run: ", command |
| + |
| +def clean_directory(directory): |
|
ricow1
2013/09/11 11:09:57
add comment explaining why we don't use the build
|
| + if os.path.exists(directory): |
| + run(['rm', '-r', directory]) |
| + run(['mkdir', '-p', directory]) |
| + |
| +def rm_tree(directory): |
| + if os.path.exists(directory): |
| + run(['rm', '-r', directory]) |
| + |
| +def copy_tree(from_dir, to_dir): |
| + if os.path.exists(to_dir): |
| + run(['rm', '-r', to_dir]) |
| + run(['cp', '-Rp', from_dir, to_dir]) |
| + |
| +def copy_file(from_file, to_file): |
| + if os.path.exists(to_file): |
| + run(['rm', to_file]) |
| + run(['cp', '-p', from_file, to_file]) |
| + |
| +def main(): |
| + parser = GetOptionsParser() |
| + (options, args) = parser.parse_args() |
| + |
| + if not options.scratch_dir: |
|
ricow1
2013/09/11 11:09:57
validate that we are running on linux, this will n
|
| + die("No scratch directory given.") |
| + if not options.revision: |
| + die("No revision given.") |
| + if not options.prepare and not options.deploy: |
| + die("No prepare/deploy parameter given.") |
| + if options.prepare and options.deploy: |
| + die("Can't have prepare and deploy parameters at the same time.") |
| + if len(args) > 0: |
| + die("Invalid additional arguments: %s." % args) |
| + |
| + downloads_dir = os.path.join(options.scratch_dir, 'downloads') |
| + presign_dir = os.path.join(options.scratch_dir, 'presign') |
| + postsign_dir = os.path.join(options.scratch_dir, 'postsign') |
| + uploads_dir = os.path.join(options.scratch_dir, 'uploads') |
| + |
| + if options.prepare: |
| + # Clean all directories |
| + clean_directory(downloads_dir) |
| + clean_directory(presign_dir) |
| + clean_directory(postsign_dir) |
| + clean_directory(uploads_dir) |
| + elif options.deploy: |
| + #clean_directory(uploads_dir) |
| + pass |
| + |
| + # Desitination of zip files we download |
| + for system in ('macos', 'win32'): |
| + for bits in (32, 64): |
| + config = { |
| + 'revision' : options.revision, |
| + 'system' : system, |
| + 'bits' : bits, |
| + } |
| + bucket = BUCKET_PATTERN % config |
| + destination = os.path.join(downloads_dir, FILENAME_PATTERN % config) |
| + destination_dir = os.path.join(downloads_dir, BASENAME_PATTERN % config) |
| + |
| + deploy = os.path.join(uploads_dir, FILENAME_PATTERN % config) |
| + deploy_dir = os.path.join(uploads_dir, BASENAME_PATTERN % config) |
| + |
| + if options.prepare: |
| + run([GSUTIL, 'cp', bucket, destination]) |
| + run(['unzip', destination, '-d', destination_dir]) |
| + if system == 'macos': |
| + 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
|
| + editor_to = os.path.join(presign_dir, 'DartEditor%(bits)s.app' % config) |
| + |
| + chrome_from = os.path.join(destination_dir, 'dart', 'chromium', |
| + 'Chromium.app') |
| + chrome_to = os.path.join(presign_dir, 'Chromium%(bits)s.app' % config) |
| + |
| + cs_from = os.path.join(destination_dir, 'dart', 'chromium', |
| + 'Content Shell.app') |
| + cs_to = os.path.join(presign_dir, 'ContentShell%(bits)s.app' % config) |
| + |
| + def copy_and_zip(from_dir, to_dir): |
| + rm_tree(to_dir) |
| + copy_tree(from_dir, to_dir) |
| + |
| + dirname = os.path.basename(to_dir) |
| + with ChangedWorkingDirectory(os.path.dirname(to_dir)): |
| + run(['zip', '-r9', dirname + '.zip', dirname]) |
| + |
|
ricow1
2013/09/11 11:09:57
Please elaborate on the difference here, for windo
|
| + copy_and_zip(editor_from, editor_to) |
| + copy_and_zip(chrome_from, chrome_to) |
| + copy_and_zip(cs_from, cs_to) |
| + elif system == 'win32': |
| + editor_from = os.path.join(destination_dir, 'dart', 'DartEditor.exe') |
| + editor_to = os.path.join(presign_dir, 'DartEditor%(bits)s.exe' % config) |
| + |
| + chrome_from = os.path.join(destination_dir, 'dart', 'chromium', |
| + 'chrome.exe') |
| + chrome_to = os.path.join(presign_dir, 'chrome%(bits)s.exe' % config) |
| + |
| + cs_from = os.path.join(destination_dir, 'dart', 'chromium', |
| + 'content_shell.exe') |
| + cs_to = os.path.join(presign_dir, 'content_shell%(bits)s.exe' % config) |
| + |
| + copy_file(editor_from, editor_to) |
| + copy_file(chrome_from, chrome_to) |
| + copy_file(cs_from, cs_to) |
| + elif options.deploy: |
| + copy_tree(destination_dir, deploy_dir) |
| + if system == 'macos': |
| + editor_from = os.path.join(postsign_dir, 'DartEditor%(bits)s.app' % config) |
|
ricow1
2013/09/11 11:09:57
same comment as above, I think this would look muc
|
| + editor_to = os.path.join(deploy_dir, 'dart', 'DartEditor.app') |
| + |
| + chrome_from = os.path.join(postsign_dir, 'Chromium%(bits)s.app' % config) |
| + chrome_to = os.path.join(deploy_dir, 'dart', 'chromium', 'Chromium.app') |
| + |
| + cs_from = os.path.join(postsign_dir, 'ContentShell%(bits)s.app' % config) |
| + cs_to = os.path.join(deploy_dir, 'dart', 'chromium', 'Content Shell.app') |
| + |
| + def unzip_and_copy(from_dir, to_dir): |
| + rm_tree(from_dir) |
| + run(['unzip', from_dir + '.zip', '-d', postsign_dir]) |
| + clean_directory(to_dir) |
| + copy_tree(from_dir, to_dir) |
| + |
| + unzip_and_copy(editor_from, editor_to) |
| + unzip_and_copy(chrome_from, chrome_to) |
| + unzip_and_copy(cs_from, cs_to) |
| + elif system == 'win32': |
| + editor_from = os.path.join(postsign_dir, 'DartEditor%(bits)s.exe' % config) |
| + editor_to = os.path.join(deploy_dir, 'dart', 'DartEditor.exe') |
| + |
| + chrome_from = os.path.join(postsign_dir, 'chrome%(bits)s.exe' % config) |
| + chrome_to = os.path.join(deploy_dir, 'dart', 'chromium', 'chrome.exe') |
| + |
| + cs_from = os.path.join(postsign_dir, 'content_shell%(bits)s.exe' % config) |
| + cs_to = os.path.join(deploy_dir, 'dart', 'chromium', 'content_shell.exe') |
| + |
| + copy_file(editor_from, editor_to) |
| + copy_file(chrome_from, chrome_to) |
| + copy_file(cs_from, cs_to) |
| + |
| + deploy_zip_file = os.path.abspath(deploy) |
| + md5_zip_file = os.path.abspath(deploy) + '.md5sum' |
| + with ChangedWorkingDirectory(deploy_dir): |
| + run(['zip', '-r9', deploy_zip_file, 'dart']) |
| + CreateMd5ChecksumFile(deploy_zip_file, md5_zip_file) |
| + run([GSUTIL, 'cp', deploy_zip_file, bucket]) |
| + run([GSUTIL, 'cp', md5_zip_file, bucket + '.md5sum']) |
| + run([GSUTIL, 'setacl', 'public-read', bucket]) |
| + run([GSUTIL, 'setacl', 'public-read', bucket + '.md5sum']) |
| + |
| +if __name__ == '__main__': |
| + main() |