aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/bug.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-06-23 11:35:23 -0400
committerW. Trevor King <wking@drexel.edu>2009-06-23 11:35:23 -0400
commit83e06581ad007e1a1f27f311ccb3a747f0a81ade (patch)
treeda64348e2f7a638e6f0664d5277aa24f1500e3c5 /libbe/bug.py
parent37195a33108299504f8d37042dec06df0540d0d2 (diff)
downloadbugseverywhere-83e06581ad007e1a1f27f311ccb3a747f0a81ade.tar.gz
Added Bug.extra_strings to support add-on functionality, e.g. `be tag`.
Versioned properties whose data is a mutable type are tricky, since the simple comparisons we'd been using in libbe.properties.change_hook_property don't work for mutables. For now, we avoid that problem by assuming a change happened whenever a mutable property is set. change_hook_property is a bit untidy at the moment while I work out how to deal with mutables. As an example of using Bug.extra_strings to patch on some useful functionality, I've written becommands/tag.py. I'd suggest future add-ons (e.g. becommands/depend.py?) use the "<LABEL>:<value>" string format to keep it easy to sort out which strings belong to which add-ons. tag.py is still missing command line tag-removal and tag-searching for `be list'. Perhaps something like be list --extra-strings TAG:<your-tag>,TAG:<another-tag>,DEPEND:<bug-id> would be good, although it would requre escaping commas from the tags, or refusing to allow commas in the tags... libbe.properties.ValueCheckError also got a minor update so the printed error message makes sense when raised with allowed being an iterable (i.e. check_property) or a function (e.g. fn_checked_property). All of this digging around turned up a really buggy libbe.bugdir.MultipleBugMatches. Obviously I had never actually called it before :p. Should be fixed now. libbe.comment._set_comment_body has also been normalized to match the suggested change_hook interface: change_hook(self, old, new). Although, I'm not sure why it hadn't been causing obvious problems before, so maybe I'm misunderstanding something about that.
Diffstat (limited to 'libbe/bug.py')
-rw-r--r--libbe/bug.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/libbe/bug.py b/libbe/bug.py
index 43974dd..89c0266 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -18,6 +18,7 @@ import os
import os.path
import errno
import time
+import types
import xml.sax.saxutils
import doctest
@@ -184,6 +185,25 @@ class Bug(settings_object.SavedSettingsObject):
fset=_set_time,
doc="An integer version of .time_string")
+ def _extra_strings_check_fn(value):
+ "Require an iterable full of strings"
+ if not hasattr(value, "__iter__"):
+ return False
+ for x in value:
+ if type(x) not in types.StringTypes:
+ return False
+ return True
+ def _extra_strings_change_hook(self, old, new):
+ self.extra_strings.sort() # to make merging easier
+ self._prop_save_settings(old, new)
+ @_versioned_property(name="extra_strings",
+ doc="Space for an array of extra strings. Useful for storing state for functionality implemented purely in becommands/<some_function>.py.",
+ default=[],
+ check_fn=_extra_strings_check_fn,
+ change_hook=_extra_strings_change_hook,
+ mutable=True)
+ def extra_strings(): return {}
+
@_versioned_property(name="summary",
doc="A one-line bug description")
def summary(): return {}