aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/bug.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/bug.py')
-rw-r--r--libbe/bug.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/libbe/bug.py b/libbe/bug.py
index 6d3d836..be6f44d 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -1,5 +1,8 @@
-# Copyright (C) 2008-2011 Gianluca Montecchi <gian@grys.it>
+# Copyright (C) 2008-2011 Chris Ball <cjb@laptop.org>
+# Gianluca Montecchi <gian@grys.it>
+# Robert Lehmann <mail@robertlehmann.de>
# Thomas Habets <thomas@habets.pp.se>
+# Valtteri Kokkoniemi <rvk@iki.fi>
# W. Trevor King <wking@drexel.edu>
#
# This file is part of Bugs Everywhere.
@@ -47,11 +50,6 @@ if libbe.TESTING == True:
import doctest
-class DiskAccessRequired (Exception):
- def __init__(self, goal):
- msg = "Cannot %s without accessing the disk" % goal
- Exception.__init__(self, msg)
-
### Define and describe valid bug categories
# Use a tuple of (category, description) tuples since we don't have
# ordered dicts in Python yet http://www.python.org/dev/peps/pep-0372/
@@ -199,10 +197,19 @@ class Bug (settings_object.SavedSettingsObject):
def _get_time(self):
if self.time_string == None:
+ self._cached_time_string = None
+ self._cached_time = None
return None
- return utility.str_to_time(self.time_string)
+ if (not hasattr(self, '_cached_time_string')
+ or self.time_string != self._cached_time_string):
+ self._cached_time_string = self.time_string
+ self._cached_time = utility.str_to_time(self.time_string)
+ return self._cached_time
def _set_time(self, value):
- self.time_string = utility.time_to_str(value)
+ if not hasattr(self, '_cached_time') or value != self._cached_time:
+ self.time_string = utility.time_to_str(value)
+ self._cached_time_string = self.time_string
+ self._cached_time = value
time = property(fget=_get_time,
fset=_set_time,
doc="An integer version of .time_string")
@@ -290,6 +297,8 @@ class Bug (settings_object.SavedSettingsObject):
("Reporter", self._setting_attr_string("reporter")),
("Creator", self._setting_attr_string("creator")),
("Created", timestring)]
+ for estr in self.extra_strings:
+ info.append(('Extra string', estr))
longest_key_len = max([len(k) for k,v in info])
infolines = [" %*s : %s\n" %(longest_key_len,k,v) for k,v in info]
bugout = "".join(infolines) + "%s" % self.summary.rstrip('\n')
@@ -337,7 +346,7 @@ class Bug (settings_object.SavedSettingsObject):
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
- def from_xml(self, xml_string, verbose=True):
+ def from_xml(self, xml_string, preserve_uuids=False, verbose=True):
u"""
Note: If a bug uuid is given, set .alt_id to it's value.
>>> bugA = Bug(uuid="0123", summary="Need to test Bug.from_xml()")
@@ -359,9 +368,13 @@ class Bug (settings_object.SavedSettingsObject):
>>> bugB.xml(show_comments=True) == xml
True
>>> bugB.explicit_attrs # doctest: +NORMALIZE_WHITESPACE
- ['severity', 'status', 'creator', 'created', 'summary']
+ ['severity', 'status', 'creator', 'time', 'summary']
>>> len(list(bugB.comments()))
3
+ >>> bugC = Bug()
+ >>> bugC.from_xml(xml, preserve_uuids=True)
+ >>> bugC.uuid == bugA.uuid
+ True
"""
if type(xml_string) == types.UnicodeType:
xml_string = xml_string.strip().encode('unicode_escape')
@@ -383,7 +396,8 @@ class Bug (settings_object.SavedSettingsObject):
pass
elif child.tag == 'comment':
comm = comment.Comment(bug=self)
- comm.from_xml(child)
+ comm.from_xml(
+ child, preserve_uuids=preserve_uuids, verbose=verbose)
comments.append(comm)
continue
elif child.tag in tags:
@@ -392,9 +406,13 @@ class Bug (settings_object.SavedSettingsObject):
else:
text = xml.sax.saxutils.unescape(child.text)
text = text.decode('unicode_escape').strip()
- if child.tag == 'uuid':
+ if child.tag == 'uuid' and not preserve_uuids:
uuid = text
continue # don't set the bug's uuid tag.
+ elif child.tag == 'created':
+ self.time = utility.str_to_time(text)
+ self.explicit_attrs.append('time')
+ continue
elif child.tag == 'extra-string':
estrs.append(text)
continue # don't set the bug's extra_string yet.
@@ -632,8 +650,8 @@ class Bug (settings_object.SavedSettingsObject):
def load_settings(self, settings_mapfile=None):
if settings_mapfile == None:
- settings_mapfile = \
- self.storage.get(self.id.storage('values'), default='\n')
+ settings_mapfile = self.storage.get(
+ self.id.storage('values'), '\n')
try:
settings = mapfile.parse(settings_mapfile)
except mapfile.InvalidMapfileContents, e: