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

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: Formatting + fix to update_remote_extensions 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..f6f4bfa4456b0cad6268d29978ea48aacaca0a4f
--- /dev/null
+++ b/tools/perf/profile_creators/update_remote_extensions.py
@@ -0,0 +1,106 @@
+# 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 directory to upload extensions to in cloud storage.
robliao 2015/07/16 18:33:25 Could be Remote target upload directory in cloud s
sydli 2015/07/16 20:01:31 Done.
+REMOTE_DIR = "extension_set"
+# Name of zip archive to write to
robliao 2015/07/16 18:33:25 Linebreak above, add period. Could also be target
sydli 2015/07/16 20:01:30 Done.
+ZIP_NAME = "extensions.zip"
+
+def _DownloadCRXFromCWS(ext_id, dst):
robliao 2015/07/16 18:33:25 Should probably be _DownloadCrxFromCws since we do
sydli 2015/07/16 20:01:30 Done.
+ """ Downloads CRX specified from Chrome Web Store.
robliao 2015/07/16 18:33:25 Remove leading whitespace.
sydli 2015/07/16 20:01:30 Done.
+
+ Retrieves CRX (Chrome extension file) sepcified by ext_id from Chrome Web
robliao 2015/07/16 18:33:25 specified
sydli 2015/07/16 20:01:31 Done.
+ 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. """
robliao 2015/07/16 18:33:25 Remove trailing whitespace. Also the """ should go
sydli 2015/07/16 20:01:30 Done.
+ 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 CSV of extension ids.
robliao 2015/07/16 18:33:25 Remove leading white space. Nit: From a csv
sydli 2015/07/16 20:01:31 Done.
+
+ 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. """
robliao 2015/07/16 18:33:25 Move """ to the next line.
sydli 2015/07/16 20:01:31 Done.
+ # 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:
+ 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 extension %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():
robliao 2015/07/16 18:33:25 This should probably be _GetCsvFromArgs. If you c
sydli 2015/07/16 20:01:30 I'll just uncaps the function names from here on o
+ """ Parse options to retrieve name of CSV file. """
robliao 2015/07/16 18:33:25 Remove leading and trailing whitespace in the docs
sydli 2015/07/16 20:01:30 Done.
+ 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__":
robliao 2015/07/16 18:33:25 Add a around the ==
sydli 2015/07/16 20:01:31 Done.
+ main()

Powered by Google App Engine
This is Rietveld 408576698