| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 @property | 91 @property |
| 92 def wpr_archive_info(self): | 92 def wpr_archive_info(self): |
| 93 """Lazily constructs wpr_archive_info if it's not set and returns it.""" | 93 """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: | 94 if self.archive_data_file and not self._wpr_archive_info: |
| 95 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( | 95 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( |
| 96 os.path.join(self.base_dir, self.archive_data_file), self.bucket) | 96 os.path.join(self.base_dir, self.archive_data_file), self.bucket) |
| 97 return self._wpr_archive_info | 97 return self._wpr_archive_info |
| 98 | 98 |
| 99 def AddStory(self, story): | 99 def AddStory(self, story): |
| 100 assert isinstance(story, story_module.Story) | 100 assert isinstance(story, story_module.Story) |
| 101 assert self._IsUnique(story), ('Tried to add story with duplicate display ' | |
| 102 'name %s. Story display names should be ' | |
| 103 'unique.' % story.display_name) | |
| 104 self.stories.append(story) | 101 self.stories.append(story) |
| 105 | 102 |
| 106 def _IsUnique(self, story): | |
| 107 return not any((story.display_name == other.display_name) and | |
| 108 sorted(story.grouping_keys.iteritems()) == | |
| 109 sorted(other.grouping_keys.iteritems()) | |
| 110 for other in self.stories) | |
| 111 | |
| 112 def RemoveStory(self, story): | 103 def RemoveStory(self, story): |
| 113 """Removes a Story. | 104 """Removes a Story. |
| 114 | 105 |
| 115 Allows the stories to be filtered. | 106 Allows the stories to be filtered. |
| 116 """ | 107 """ |
| 117 self.stories.remove(story) | 108 self.stories.remove(story) |
| 118 | 109 |
| 119 @classmethod | 110 @classmethod |
| 120 def Name(cls): | 111 def Name(cls): |
| 121 """Returns the string name of this StorySet. | 112 """Returns the string name of this StorySet. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return self.stories.__iter__() | 146 return self.stories.__iter__() |
| 156 | 147 |
| 157 def __len__(self): | 148 def __len__(self): |
| 158 return len(self.stories) | 149 return len(self.stories) |
| 159 | 150 |
| 160 def __getitem__(self, key): | 151 def __getitem__(self, key): |
| 161 return self.stories[key] | 152 return self.stories[key] |
| 162 | 153 |
| 163 def __setitem__(self, key, value): | 154 def __setitem__(self, key, value): |
| 164 self.stories[key] = value | 155 self.stories[key] = value |
| OLD | NEW |