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

Unified Diff: remoting/host/installer/build-installer-archive.py

Issue 10071027: [Chromoting] Add target to build archive for remoting_me2me_host files. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | remoting/remoting.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/installer/build-installer-archive.py
===================================================================
--- remoting/host/installer/build-installer-archive.py (revision 0)
+++ remoting/host/installer/build-installer-archive.py (working copy)
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Create a zip archive for the Chrome Remote Desktop Host installer.
alexeypa (please no reviews) 2012/04/13 17:27:13 nit: Create -> Creates?
alexeypa (please no reviews) 2012/04/13 17:27:13 Add TODO about merging this script with the one th
garykac 2012/04/13 18:06:03 Done.
garykac 2012/04/13 18:06:03 Done.
+
+This script builds a zip file that contains all the files needed to build an
+installer for Chrome Remote Desktop Host.
+
+This zip archive is then used by the signing bots to:
+(1) Sign the binaries
+(2) Build the final installer
+"""
+
+import os
+import shutil
+import sys
+import zipfile
+
+
+def cleanDir(dir):
+ """Delete and recreate the dir to make sure it is clean.
alexeypa (please no reviews) 2012/04/13 17:27:13 nit: Deletes and recreates
garykac 2012/04/13 18:06:03 Done.
+
+ Args:
+ dir: The directory to clean.
+ """
+ try:
+ shutil.rmtree(dir)
+ except OSError:
+ if os.path.exists(dir):
+ raise
+ else:
+ pass
+ os.makedirs(dir, 0775)
+
+
+def createZip(zip_path, directory):
+ """Creates a zipfile at zip_path for the given directory.
+
+ Args:
+ zip_path: Path to zip file to create.
+ directory: Directory with contents to archive.
+ """
+ zipfile_base = os.path.splitext(os.path.basename(zip_path))[0]
+ zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
+ for (root, dirs, files) in os.walk(directory):
+ for f in files:
+ full_path = os.path.join(root, f)
+ rel_path = os.path.relpath(full_path, directory)
+ zip.write(full_path, os.path.join(zipfile_base, rel_path))
+ zip.close()
+
+
+def copyFileIntoArchive(src_file, out_dir, files_root, dst_file):
+ """Copy the src_file into the out_dir, preserving the directory structure.
alexeypa (please no reviews) 2012/04/13 17:27:13 Copies :-)
garykac 2012/04/13 18:06:03 Done.
+
+ Args:
+ src_file: Full or relative path to source file to copy.
+ out_dir: Target directory where files are copied.
+ files_root: Path prefix which is stripped of dst_file before appending
+ it to the temp_dir.
+ dst_file: Relative path (and filename) where src_file should be copied.
+ """
+ root_len = len(files_root)
+ local_path = dst_file[root_len:]
+ full_dst_file = os.path.join(out_dir, local_path)
+ dst_dir = os.path.dirname(full_dst_file)
+ if not os.path.exists(dst_dir):
+ os.makedirs(dst_dir, 0775)
+ shutil.copy2(src_file, full_dst_file)
+
+
+def buildHostArchive(temp_dir, zip_path, files_root, files, binaries_src,
+ binaries_dst):
+ """Build a zip archive with the files needed to build the installer.
alexeypa (please no reviews) 2012/04/13 17:27:13 Builds
garykac 2012/04/13 18:06:03 Done.
+
+ Args:
+ temp_dir: Temporary dir used to build up the contents for the archive.
+ zip_path: Full path to the zip file to create.
+ files_root: Path prefix to strip off |files| when adding to archive.
+ files: The array of files to add to archive. The path structure is
+ preserved (except for the |files_root| prefix).
+ binaries_src: Full path to binaries to add to archive.
+ binaries_dst: Relative path of where to add binary files in archive.
+ This array needs to parallel |binaries_src|.
+ """
+ cleanDir(temp_dir)
+
+ for file in files:
+ base_file = os.path.basename(file)
+ if base_file == '*':
+ # Copy entire directory tree.
+ for (root, dirs, files) in os.walk(os.path.dirname(file)):
+ for f in files:
+ full_path = os.path.join(root, f)
+ copyFileIntoArchive(full_path, temp_dir, files_root, full_path)
+ else:
+ copyFileIntoArchive(file, temp_dir, files_root, file)
+
+ for bs, bd in zip(binaries_src, binaries_dst):
+ copyFileIntoArchive(bs, temp_dir, '', bd)
+
+ createZip(zip_path, temp_dir)
+
+
+def usage():
+ """Display basic usage information."""
+ print ('Usage:', sys.argv[0],
+ '<temp-dir> <zip-path> <files-root-dir>'
+ '--files <files...> '
+ '--binaries-src <src binary files...> '
alexeypa (please no reviews) 2012/04/13 17:27:13 nit: The way we map source files to their location
garykac 2012/04/13 18:06:03 We need a flat array of filenames for gyp dependen
+ '--binaries-dst <dst for binary files...>')
+
+
+def main():
+ if len(sys.argv) < 5:
+ usage()
+ return 1
+
+ temp_dir = sys.argv[1]
+ zip_path = sys.argv[2]
+ files_root = sys.argv[3]
alexeypa (please no reviews) 2012/04/13 17:27:13 What if there are less arguments than required?
garykac 2012/04/13 18:06:03 Changed above check to ensure 3 or more args.
+
+ arg_mode = ''
+ files = []
+ binaries_src = []
+ binaries_dst = []
+ for arg in sys.argv[4:]:
+ if arg == '--files':
+ arg_mode = 'files'
+ elif arg == '--binaries-src':
+ arg_mode = 'bin-src'
+ elif arg == '--binaries-dst':
+ arg_mode = 'bin-dst'
+
+ elif arg_mode == 'files':
+ files.append(arg)
+ elif arg_mode == 'bin-src':
+ binaries_src.append(arg)
+ elif arg_mode == 'bin-dst':
+ binaries_dst.append(arg)
+ else:
+ usage()
+ return 1
+
+ # Ensure that files_root ends with a directory separator.
+ if files_root[-1:] != os.sep:
+ files_root += os.sep
+
+ # Verify that the 2 'binaries' arrays have the same number of elements.
+ if len(binaries_src) < len(binaries_dst):
+ print "ERROR: --binaries-src and --binaries-dst should be the same length"
+ return 1
+ while len(binaries_src) > len(binaries_dst):
+ binaries_dst.append('')
+
+ result = buildHostArchive(temp_dir, zip_path, files_root, files,
+ binaries_src, binaries_dst)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main())
Property changes on: remoting/host/installer/build-installer-archive.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | remoting/remoting.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698