OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 inspect | 5 import inspect |
6 import os | 6 import os |
7 | 7 |
8 from telemetry.story import story as story_module | 8 from telemetry.story import story as story_module |
9 from telemetry.wpr import archive_info | 9 from telemetry.wpr import archive_info |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 to self.base_dir. | 25 to self.base_dir. |
26 cloud_storage_bucket: The cloud storage bucket used to download | 26 cloud_storage_bucket: The cloud storage bucket used to download |
27 Web Page Replay's archive data. Valid values are: None, | 27 Web Page Replay's archive data. Valid values are: None, |
28 story.PUBLIC_BUCKET, story.PARTNER_BUCKET, or story.INTERNAL_BUCKET | 28 story.PUBLIC_BUCKET, story.PARTNER_BUCKET, or story.INTERNAL_BUCKET |
29 (defined in telemetry.util.cloud_storage). | 29 (defined in telemetry.util.cloud_storage). |
30 serving_dirs: A set of paths, relative to self.base_dir, to directories | 30 serving_dirs: A set of paths, relative to self.base_dir, to directories |
31 containing hash files for non-wpr archive data stored in cloud | 31 containing hash files for non-wpr archive data stored in cloud |
32 storage. | 32 storage. |
33 """ | 33 """ |
34 self.stories = [] | 34 self.stories = [] |
35 self.story_names_and_grouping_keys = set() | |
nednguyen
2016/12/02 19:59:58
Can you make this private? Things that are not sup
eakuefner
2016/12/02 20:28:58
Done. Also made stories private, since now it's cr
| |
35 self._archive_data_file = archive_data_file | 36 self._archive_data_file = archive_data_file |
36 self._wpr_archive_info = None | 37 self._wpr_archive_info = None |
37 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) | 38 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) |
38 self._cloud_storage_bucket = cloud_storage_bucket | 39 self._cloud_storage_bucket = cloud_storage_bucket |
39 if base_dir: | 40 if base_dir: |
40 if not os.path.isdir(base_dir): | 41 if not os.path.isdir(base_dir): |
41 raise ValueError('Invalid directory path of base_dir: %s' % base_dir) | 42 raise ValueError('Invalid directory path of base_dir: %s' % base_dir) |
42 self._base_dir = base_dir | 43 self._base_dir = base_dir |
43 else: | 44 else: |
44 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) | 45 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 @property | 92 @property |
92 def wpr_archive_info(self): | 93 def wpr_archive_info(self): |
93 """Lazily constructs wpr_archive_info if it's not set and returns it.""" | 94 """Lazily constructs wpr_archive_info if it's not set and returns it.""" |
94 if self.archive_data_file and not self._wpr_archive_info: | 95 if self.archive_data_file and not self._wpr_archive_info: |
95 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( | 96 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( |
96 os.path.join(self.base_dir, self.archive_data_file), self.bucket) | 97 os.path.join(self.base_dir, self.archive_data_file), self.bucket) |
97 return self._wpr_archive_info | 98 return self._wpr_archive_info |
98 | 99 |
99 def AddStory(self, story): | 100 def AddStory(self, story): |
100 assert isinstance(story, story_module.Story) | 101 assert isinstance(story, story_module.Story) |
102 assert self._IsUnique(story), ('Tried to add story with duplicate display ' | |
103 'name %s. Story display names should be ' | |
104 'unique.' % story.display_name) | |
101 self.stories.append(story) | 105 self.stories.append(story) |
106 self.story_names_and_grouping_keys.add( | |
107 story.display_name_and_grouping_key_tuple) | |
108 | |
109 def _IsUnique(self, story): | |
110 return (story.display_name_and_grouping_key_tuple not in | |
111 self.story_names_and_grouping_keys) | |
102 | 112 |
103 def RemoveStory(self, story): | 113 def RemoveStory(self, story): |
104 """Removes a Story. | 114 """Removes a Story. |
105 | 115 |
106 Allows the stories to be filtered. | 116 Allows the stories to be filtered. |
107 """ | 117 """ |
108 self.stories.remove(story) | 118 self.stories.remove(story) |
nednguyen
2016/12/02 20:00:57
Don't you need to remove the corresponding data fr
eakuefner
2016/12/02 20:28:58
Done.
| |
109 | 119 |
110 @classmethod | 120 @classmethod |
111 def Name(cls): | 121 def Name(cls): |
112 """Returns the string name of this StorySet. | 122 """Returns the string name of this StorySet. |
113 Note that this should be a classmethod so the benchmark_runner script can | 123 Note that this should be a classmethod so the benchmark_runner script can |
114 match the story class with its name specified in the run command: | 124 match the story class with its name specified in the run command: |
115 'Run <User story test name> <User story class name>' | 125 'Run <User story test name> <User story class name>' |
116 """ | 126 """ |
117 return cls.__module__.split('.')[-1] | 127 return cls.__module__.split('.')[-1] |
118 | 128 |
(...skipping 27 matching lines...) Expand all Loading... | |
146 return self.stories.__iter__() | 156 return self.stories.__iter__() |
147 | 157 |
148 def __len__(self): | 158 def __len__(self): |
149 return len(self.stories) | 159 return len(self.stories) |
150 | 160 |
151 def __getitem__(self, key): | 161 def __getitem__(self, key): |
152 return self.stories[key] | 162 return self.stories[key] |
153 | 163 |
154 def __setitem__(self, key, value): | 164 def __setitem__(self, key, value): |
155 self.stories[key] = value | 165 self.stories[key] = value |
OLD | NEW |