Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / user_story / __init__.py
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
3 # found in the LICENSE file.
4
5 import re
6
7 _next_user_story_id = 0
8
9
10 class UserStory(object):
11   def __init__(self, name=''):
12     self._name = name
13     global _next_user_story_id
14     self._id = _next_user_story_id
15     _next_user_story_id += 1
16
17   @property
18   def id(self):
19     return self._id
20
21   @property
22   def name(self):
23     return self._name
24
25   def AsDict(self):
26     """Converts a user story object to a dict suitable for JSON output."""
27     d = {
28       'id': self._id,
29     }
30     if self._name:
31       d['name'] = self._name
32     return d
33
34   @property
35   def file_safe_name(self):
36     """A version of display_name that's safe to use as a filename."""
37     # Just replace all special characters in the url with underscore.
38     return re.sub('[^a-zA-Z0-9]', '_', self.display_name)
39
40   @property
41   def display_name(self):
42     if self.name:
43       return self.name
44     else:
45       return self.__class__.__name__