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

Side by Side Diff: tools/telemetry/telemetry/page/page_set_archive_info.py

Issue 779383002: Move WPR-related attributes to UserStorySet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import tempfile 10 import tempfile
11 11
12 from telemetry import page as page_module
12 from telemetry.util import cloud_storage 13 from telemetry.util import cloud_storage
13 14
14 15
16 def AssertValidCloudStorageBucket(bucket):
17 is_valid = bucket in (None,
18 cloud_storage.PUBLIC_BUCKET,
19 cloud_storage.PARTNER_BUCKET,
20 cloud_storage.INTERNAL_BUCKET)
21 if not is_valid:
22 raise ValueError("Cloud storage privacy bucket %s is invalid" % bucket)
23
24
25 # TODO(chrishenry): Rename this (and module) to wpr_archive_info.WprArchiveInfo
26 # and move to telemetry.user_story or telemetry.wpr or telemetry.core.
15 class PageSetArchiveInfo(object): 27 class PageSetArchiveInfo(object):
16 def __init__(self, file_path, data, bucket, ignore_archive=False): 28 def __init__(self, file_path, data, bucket, ignore_archive=False):
29 AssertValidCloudStorageBucket(bucket)
17 self._file_path = file_path 30 self._file_path = file_path
18 self._base_dir = os.path.dirname(file_path) 31 self._base_dir = os.path.dirname(file_path)
19 self._bucket = bucket 32 self._bucket = bucket
20 33
21 # Ensure directory exists. 34 # Ensure directory exists.
22 if not os.path.exists(self._base_dir): 35 if not os.path.exists(self._base_dir):
23 os.makedirs(self._base_dir) 36 os.makedirs(self._base_dir)
24 37
25 # Download all .wpr files. 38 # Download all .wpr files.
26 if not ignore_archive: 39 if not ignore_archive:
(...skipping 29 matching lines...) Expand all
56 69
57 @classmethod 70 @classmethod
58 def FromFile(cls, file_path, bucket, ignore_archive=False): 71 def FromFile(cls, file_path, bucket, ignore_archive=False):
59 if os.path.exists(file_path): 72 if os.path.exists(file_path):
60 with open(file_path, 'r') as f: 73 with open(file_path, 'r') as f:
61 data = json.load(f) 74 data = json.load(f)
62 return cls(file_path, data, bucket, ignore_archive=ignore_archive) 75 return cls(file_path, data, bucket, ignore_archive=ignore_archive)
63 return cls(file_path, {'archives': {}}, bucket, 76 return cls(file_path, {'archives': {}}, bucket,
64 ignore_archive=ignore_archive) 77 ignore_archive=ignore_archive)
65 78
66 def WprFilePathForPage(self, page): 79 def WprFilePathForUserStory(self, story):
67 if self.temp_target_wpr_file_path: 80 if self.temp_target_wpr_file_path:
68 return self.temp_target_wpr_file_path 81 return self.temp_target_wpr_file_path
69 wpr_file = self._page_name_to_wpr_file.get(page.display_name, None) 82 wpr_file = self._page_name_to_wpr_file.get(story.display_name, None)
70 if wpr_file is None: 83 if wpr_file is None and isinstance(story, page_module.Page):
71 # Some old page sets always use the URL to identify a page rather than the 84 # Some old page sets always use the URL to identify a page rather than the
72 # display_name, so try to look for that. 85 # display_name, so try to look for that.
73 wpr_file = self._page_name_to_wpr_file.get(page.url, None) 86 wpr_file = self._page_name_to_wpr_file.get(story.url, None)
74 if wpr_file: 87 if wpr_file:
75 return self._WprFileNameToPath(wpr_file) 88 return self._WprFileNameToPath(wpr_file)
76 return None 89 return None
77 90
78 def AddNewTemporaryRecording(self, temp_wpr_file_path=None): 91 def AddNewTemporaryRecording(self, temp_wpr_file_path=None):
79 if temp_wpr_file_path is None: 92 if temp_wpr_file_path is None:
80 temp_wpr_file_handle, temp_wpr_file_path = tempfile.mkstemp() 93 temp_wpr_file_handle, temp_wpr_file_path = tempfile.mkstemp()
81 os.close(temp_wpr_file_handle) 94 os.close(temp_wpr_file_handle)
82 self.temp_target_wpr_file_path = temp_wpr_file_path 95 self.temp_target_wpr_file_path = temp_wpr_file_path
83 96
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 187
175 def _SetWprFileForPage(self, page_name, wpr_file): 188 def _SetWprFileForPage(self, page_name, wpr_file):
176 """For modifying the metadata when we're going to record a new archive.""" 189 """For modifying the metadata when we're going to record a new archive."""
177 old_wpr_file = self._page_name_to_wpr_file.get(page_name, None) 190 old_wpr_file = self._page_name_to_wpr_file.get(page_name, None)
178 if old_wpr_file: 191 if old_wpr_file:
179 self._wpr_file_to_page_names[old_wpr_file].remove(page_name) 192 self._wpr_file_to_page_names[old_wpr_file].remove(page_name)
180 self._page_name_to_wpr_file[page_name] = wpr_file 193 self._page_name_to_wpr_file[page_name] = wpr_file
181 if wpr_file not in self._wpr_file_to_page_names: 194 if wpr_file not in self._wpr_file_to_page_names:
182 self._wpr_file_to_page_names[wpr_file] = [] 195 self._wpr_file_to_page_names[wpr_file] = []
183 self._wpr_file_to_page_names[wpr_file].append(page_name) 196 self._wpr_file_to_page_names[wpr_file].append(page_name)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page/page_set.py ('k') | tools/telemetry/telemetry/page/page_set_archive_info_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698