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

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

Issue 838253005: Refactor serving_dirs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 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 import inspect 4 import inspect
5 import logging 5 import logging
6 import os 6 import os
7 import urlparse 7 import urlparse
8 8
9 from telemetry import user_story 9 from telemetry import user_story
10 from telemetry.page import shared_page_state 10 from telemetry.page import shared_page_state
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 assert self.is_file 188 assert self.is_file
189 file_path_url = os.path.normpath(os.path.join(self._base_dir, self.url[7:])) 189 file_path_url = os.path.normpath(os.path.join(self._base_dir, self.url[7:]))
190 # Preserve trailing slash or backslash. 190 # Preserve trailing slash or backslash.
191 # It doesn't matter in a file path, but it does matter in a URL. 191 # It doesn't matter in a file path, but it does matter in a URL.
192 if self.url.endswith('/'): 192 if self.url.endswith('/'):
193 file_path_url += os.sep 193 file_path_url += os.sep
194 return file_path_url 194 return file_path_url
195 195
196 @property 196 @property
197 def serving_dir(self): 197 def serving_dir(self):
198 if not self.is_file:
199 return None
nednguyen 2015/02/03 01:37:37 Can the logic below be moved to user_story?
aiolos (Not reviewing) 2015/02/03 02:35:36 user_story doesn't currently have a file_path para
nednguyen 2015/02/03 18:03:54 file_path is a field that only works in page's cas
198 file_path = os.path.realpath(self.file_path) 200 file_path = os.path.realpath(self.file_path)
199 if os.path.isdir(file_path): 201 if os.path.isdir(file_path):
200 return file_path 202 return file_path
201 else: 203 else:
202 return os.path.dirname(file_path) 204 return os.path.dirname(file_path)
203 205
204 @property 206 @property
205 def display_name(self): 207 def display_name(self):
206 if self.name: 208 if self.name:
207 return self.name 209 return self.name
208 if not self.is_file: 210 if not self.is_file:
209 return self.url 211 return self.url
210 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file] 212 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file]
211 common_prefix = os.path.dirname(os.path.commonprefix(all_urls)) 213 common_prefix = os.path.dirname(os.path.commonprefix(all_urls))
212 return self.url[len(common_prefix):].strip('/') 214 return self.url[len(common_prefix):].strip('/')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698