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

Unified Diff: tools/perf/profile_creators/update_remote_extensions.py

Issue 1240703003: Extension profile generator + benchmark for startup with profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style and whitespace fixes. Created 5 years, 5 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
Index: tools/perf/profile_creators/update_remote_extensions.py
diff --git a/tools/perf/profile_creators/update_remote_extensions.py b/tools/perf/profile_creators/update_remote_extensions.py
new file mode 100644
index 0000000000000000000000000000000000000000..31af79ce0799cfe112cb6e0206fadf363e0ea509
--- /dev/null
+++ b/tools/perf/profile_creators/update_remote_extensions.py
@@ -0,0 +1,109 @@
+# Copyright 2016 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.
+
+import csv
+import optparse
+import os
+import shutil
+import sys
+import tempfile
+import urllib2
+import zipfile
+
+sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
+ 'telemetry'))
+
+from catapult_base import cloud_storage
+from telemetry.core import exceptions
+
+# Remote target upload directory in cloud storage for extensions.
+REMOTE_DIR = 'extension_set'
+
+# Target zip file.
+ZIP_NAME = 'extensions.zip'
+
+def _DownloadCrxFromCws(ext_id, dst):
+ """Downloads CRX specified from Chrome Web Store.
+
+ Retrieves CRX (Chrome extension file) specified by ext_id from Chrome Web
+ Store, into directory specified by dst.
+
+ Args:
+ ext_id: id of extension to retrieve.
+ dst: directory to download CRX into
+
+ Returns:
+ Returns local path to downloaded CRX.
+ If download fails, return None.
+ """
+ dst_path = os.path.join(dst, '%s.crx' % ext_id)
+ cws_url = ('https://clients2.google.com/service/update2/crx?response='
+ 'redirect&prodversion=38.0&x=id%%3D%s%%26installsource%%3D'
+ 'ondemand%%26uc' % ext_id)
+ response = urllib2.urlopen(cws_url)
+ if response.getcode() is not 200:
+ return None
+ with open(dst_path, 'w') as f:
+ f.write(response.read())
+ return dst_path
+
+def _UpdateExtensionsInCloud(local_extensions_dir, extensions_csv, remote_dir):
+ """Updates set of extensions in Cloud Storage from a CSV of extension ids.
+
+ From well-formatted CSV file containing some set of extensions
+ (extensions_csv), download them, compress into archive, and update
+ the remote extension archive under REMOTE_DIR in CHROME-PARTNER-TELEMETRY
+ bucket. This script expects 2nd column of CSV file to contain extension ids.
+
+ Args:
+ local_extensions_dir: directory to download CRX files into.
+ extension_csv: CSV to pull extension_ids from.
+ remote_dir: remote directory to put extension archive in cloud storage.
+
+ Raises:
+ Exception if a CRX download fails.
+ """
+ # Download CRX to temp files and compress into archive
+ zip_path = os.path.join(local_extensions_dir, ZIP_NAME)
+ extension_zip = zipfile.ZipFile(zip_path, 'w')
+ with open(extensions_csv, 'rb') as csvfile:
robliao 2015/07/16 21:10:04 csv_file
sydli 2015/07/17 01:00:29 Done.
+ reader = csv.reader(csvfile)
+ reader.next() # skip header line
+ for row in reader:
+ extension_id = row[1]
+ print 'Fetching extension %s...' % extension_id
+ crx_path = _DownloadCrxFromCws(extension_id, local_extensions_dir)
+ if crx_path is None:
+ raise exceptions.Error('\tCould not fetch %s.\n\n'
+ 'If this extension dl consistently fails, '
+ 'remove this entry from %s.'
+ % (extension_id, extensions_csv))
+ extension_zip.write(crx_path, arcname='%s.crx' % extension_id)
+ extension_zip.close()
+ print 'Uploading extensions to cloud...'
+ remote_zip_path = os.path.join(remote_dir, ZIP_NAME)
+ cloud_storage.Insert(cloud_storage.PARTNER_BUCKET, remote_zip_path, zip_path)
+
+def _GetCsvFromArgs():
+ """Parse options to retrieve name of CSV file."""
+ parser = optparse.OptionParser()
+ parser.add_option('-e', '--extension-csv', dest='extension_csv',
+ help='CSV of extensions to load.')
+ (options, _) = parser.parse_args()
+ if not options.extension_csv:
+ parser.error('Must specify --extension-csv option.')
+ return options.extension_csv
+
+def main():
+ extension_csv = _GetCsvFromArgs()
+ local_extensions_dir = tempfile.mkdtemp()
+ try:
+ _UpdateExtensionsInCloud(local_extensions_dir,
+ extension_csv, REMOTE_DIR)
+ finally:
+ shutil.rmtree(local_extensions_dir)
+
+if __name__ == '__main__':
+ main()
+

Powered by Google App Engine
This is Rietveld 408576698