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

Side by Side Diff: tools/telemetry/telemetry/user_story/user_story_set.py

Issue 838253005: Refactor serving_dirs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better refactor. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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 import user_story as user_story_module 8 from telemetry import user_story as user_story_module
9 from telemetry.wpr import archive_info 9 from telemetry.wpr import archive_info
10 10
11 11
12 class UserStorySet(object): 12 class UserStorySet(object):
13 """A collection of user story. 13 """A collection of user story.
14 14
15 A typical usage of UserStorySet would be to subclass it and then calling 15 A typical usage of UserStorySet would be to subclass it and then calling
16 AddUserStory for each UserStory.. 16 AddUserStory for each UserStory..
17 """ 17 """
18 18
19 def __init__(self, archive_data_file='', cloud_storage_bucket=None, 19 def __init__(self, archive_data_file='', cloud_storage_bucket=None,
20 serving_dirs=None): 20 serving_dirs=None):
21 """Creates a new UserStorySet. 21 """Creates a new UserStorySet.
22 22
23 Args: 23 Args:
24 archive_data_file: The path to Web Page Replay's archive data, relative 24 archive_data_file: The path to Web Page Replay's archive data, relative
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 PUBLIC_BUCKET, PARTNER_BUCKET, or INTERNAL_BUCKET (defined 28 PUBLIC_BUCKET, PARTNER_BUCKET, or INTERNAL_BUCKET (defined
29 in telemetry.util.cloud_storage). 29 in telemetry.util.cloud_storage).
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
32 storage.
30 """ 33 """
31 self.user_stories = [] 34 self.user_stories = []
32 self._archive_data_file = archive_data_file 35 self._archive_data_file = archive_data_file
33 self._wpr_archive_info = None 36 self._wpr_archive_info = None
34 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) 37 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket)
35 self._cloud_storage_bucket = cloud_storage_bucket 38 self._cloud_storage_bucket = cloud_storage_bucket
36 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) 39 self._base_dir = os.path.dirname(inspect.getfile(self.__class__))
37 # Convert any relative serving_dirs to absolute paths. 40 # Convert any relative serving_dirs to absolute paths.
38 self._serving_dirs = set(os.path.realpath(os.path.join(self.base_dir, d)) 41 self._serving_dirs = set(os.path.realpath(os.path.join(self.base_dir, d))
39 for d in serving_dirs or []) 42 for d in serving_dirs or [])
40 43
41 @property 44 @property
42 def base_dir(self): 45 def base_dir(self):
43 """The base directory to resolve archive_data_file. 46 """The base directory to resolve archive_data_file.
44 47
45 This defaults to the directory containing the UserStorySet instance's class. 48 This defaults to the directory containing the UserStorySet instance's class.
46 """ 49 """
47 return self._base_dir 50 return self._base_dir
48 51
49 @property 52 @property
50 def serving_dirs(self): 53 def serving_dirs(self):
51 return self._serving_dirs 54 all_serving_dirs = self._serving_dirs.copy()
55 for user_story in self.user_stories:
56 if user_story.serving_dir:
57 all_serving_dirs.add(user_story.serving_dir)
58 return all_serving_dirs
52 59
53 @property 60 @property
54 def archive_data_file(self): 61 def archive_data_file(self):
55 return self._archive_data_file 62 return self._archive_data_file
56 63
57 @property 64 @property
58 def bucket(self): 65 def bucket(self):
59 return self._cloud_storage_bucket 66 return self._cloud_storage_bucket
60 67
61 @property 68 @property
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return self.user_stories.__iter__() 119 return self.user_stories.__iter__()
113 120
114 def __len__(self): 121 def __len__(self):
115 return len(self.user_stories) 122 return len(self.user_stories)
116 123
117 def __getitem__(self, key): 124 def __getitem__(self, key):
118 return self.user_stories[key] 125 return self.user_stories[key]
119 126
120 def __setitem__(self, key, value): 127 def __setitem__(self, key, value):
121 self.user_stories[key] = value 128 self.user_stories[key] = value
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698