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

Unified Diff: tools/telemetry/telemetry/page/page_set.py

Issue 24294003: [Telemetry] Move WPR archives and credentials from src-internal to Cloud Storage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit test fixes and .gitignore 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/page_set.py
diff --git a/tools/telemetry/telemetry/page/page_set.py b/tools/telemetry/telemetry/page/page_set.py
index ce79f388113c359bd0c1249bb38e67107426336f..a01b80a73b61e463af5c5b7b3b12075d03b8729a 100644
--- a/tools/telemetry/telemetry/page/page_set.py
+++ b/tools/telemetry/telemetry/page/page_set.py
@@ -23,50 +23,59 @@ class PageSet(object):
for k, v in attributes.iteritems():
setattr(self, k, v)
- self.pages = []
-
+ # Create a PageSetArchiveInfo object.
if self.archive_data_file:
self.wpr_archive_info = page_set_archive_info.PageSetArchiveInfo.FromFile(
os.path.join(self._base_dir, self.archive_data_file), file_path)
else:
self.wpr_archive_info = None
- @classmethod
- def FromFile(cls, file_path):
- with open(file_path, 'r') as f:
- contents = f.read()
- data = json.loads(contents)
- return cls.FromDict(data, file_path)
-
- @classmethod
- def FromDict(cls, data, file_path):
- page_set = cls(file_path, data)
-
- for page_attributes in data['pages']:
- url = page_attributes.pop('url')
-
- page = page_module.Page(url, page_set, attributes=page_attributes,
- base_dir=page_set._base_dir) # pylint: disable=W0212
- page_set.pages.append(page)
-
+ # Create a Page object for every page.
+ self.pages = []
+ if attributes and 'pages' in attributes:
+ for page_attributes in attributes['pages']:
+ url = page_attributes.pop('url')
+
+ page = page_module.Page(
+ url, self, attributes=page_attributes, base_dir=self._base_dir)
+ self.pages.append(page)
+
+ # Attempt to download the credentials file.
+ if self.credentials_path:
+ cloud_storage.GetIfChanged(
+ cloud_storage.INTERNAL_BUCKET,
+ os.path.join(self._base_dir, self.credentials_path))
+
+ # For every file:// URL, scan that directory for .sha1 files,
+ # and download them from Cloud Storage. Assume all data is public.
all_serving_dirs = set()
- for page in page_set:
+ for page in self:
if page.is_file:
serving_dirs, _ = page.serving_dirs_and_file
if isinstance(serving_dirs, list):
all_serving_dirs |= set(serving_dirs)
else:
all_serving_dirs.add(serving_dirs)
+
for serving_dir in all_serving_dirs:
for dirpath, _, filenames in os.walk(serving_dir):
for filename in filenames:
- file_path, extension = os.path.splitext(
+ path, extension = os.path.splitext(
os.path.join(dirpath, filename))
if extension != '.sha1':
continue
- cloud_storage.GetIfChanged(cloud_storage.DEFAULT_BUCKET, file_path)
+ cloud_storage.GetIfChanged(cloud_storage.PUBLIC_BUCKET, path)
+
+ @classmethod
+ def FromFile(cls, file_path):
+ with open(file_path, 'r') as f:
+ contents = f.read()
+ data = json.loads(contents)
+ return cls.FromDict(data, file_path)
- return page_set
+ @classmethod
+ def FromDict(cls, data, file_path):
+ return cls(file_path, data)
@property
def _base_dir(self):

Powered by Google App Engine
This is Rietveld 408576698