diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-11 07:46:22 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-11 07:46:22 -0400 |
commit | f87355fddc2a931e3f984d074a713f4313d5f709 (patch) | |
tree | 4c217b7a2b9867c74e8f0f5bd1d05180cbbc6e90 | |
parent | 4038e118782113b404f0995e3c919d6e58195c22 (diff) | |
download | bugseverywhere-f87355fddc2a931e3f984d074a713f4313d5f709.tar.gz |
Adjustments to new versioned_property behavior.
Also adjusted libbe/comment.py to move to user-specified alt_ids,
rather than uuids.
-rw-r--r-- | becommands/assign.py | 6 | ||||
-rw-r--r-- | becommands/comment.py | 6 | ||||
-rw-r--r-- | becommands/new.py | 6 | ||||
-rw-r--r-- | becommands/set.py | 2 | ||||
-rw-r--r-- | becommands/target.py | 4 | ||||
-rw-r--r-- | libbe/bug.py | 16 | ||||
-rw-r--r-- | libbe/comment.py | 39 |
7 files changed, 50 insertions, 29 deletions
diff --git a/becommands/assign.py b/becommands/assign.py index 985cfdd..871a3af 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -18,7 +18,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Assign an individual or group to fix a bug""" -from libbe import cmdutil, bugdir, settings_object +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args, test=False): @@ -26,7 +26,7 @@ def execute(args, test=False): >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> bd.bug_from_shortname("a").assigned is settings_object.EMPTY + >>> bd.bug_from_shortname("a").assigned is None True >>> execute(["a"], test=True) @@ -41,7 +41,7 @@ def execute(args, test=False): >>> execute(["a","none"], test=True) >>> bd._clear_bugs() - >>> bd.bug_from_shortname("a").assigned is settings_object.EMPTY + >>> bd.bug_from_shortname("a").assigned is None True """ parser = get_parser() diff --git a/becommands/comment.py b/becommands/comment.py index a11cd90..f350291 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Add a comment to a bug""" -from libbe import cmdutil, bugdir, comment, settings_object, editor +from libbe import cmdutil, bugdir, comment, editor import os import sys try: # import core module, Python >= 2.5 @@ -42,7 +42,7 @@ def execute(args, test=False): True >>> comment.time <= int(time.time()) True - >>> comment.in_reply_to is settings_object.EMPTY + >>> comment.in_reply_to is None True >>> if 'EDITOR' in os.environ: @@ -131,7 +131,7 @@ def execute(args, test=False): raise cmdutil.UserError( "Clashing comment uuids: %s" % new.uuid) uuids.append(new.uuid) - if new.in_reply_to in [settings_object.EMPTY, None]: + if new.in_reply_to == None: new.in_reply_to = parent.uuid new_comments.append(new) else: diff --git a/becommands/new.py b/becommands/new.py index ec28138..922b5ed 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Create a new bug""" -from libbe import cmdutil, bugdir, settings_object +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args, test=False): @@ -36,7 +36,7 @@ def execute(args, test=False): True >>> print bug.severity minor - >>> bug.target == settings_object.EMPTY + >>> bug.target == None True """ parser = get_parser() @@ -56,7 +56,7 @@ def execute(args, test=False): bug.reporter = bug.creator if options.assigned != None: bug.assigned = options.assigned - elif bd.default_assignee != settings_object.EMPTY: + elif bd.default_assignee != None: bug.assigned = bd.default_assignee bd.save() print "Created bug with ID %s" % bd.bug_shortname(bug) diff --git a/becommands/set.py b/becommands/set.py index e771018..939236a 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -26,7 +26,7 @@ def _value_string(bd, setting): val = bd.settings.get(setting, settings_object.EMPTY) if val == settings_object.EMPTY: default = getattr(bd, bd._setting_name_to_attr_name(setting)) - if default != settings_object.EMPTY: + if default not in [None, settings_object.EMPTY]: val = "None (%s)" % default else: val = None diff --git a/becommands/target.py b/becommands/target.py index 283998a..aa027e0 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -20,7 +20,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Show or change a bug's target for fixing""" -from libbe import cmdutil, bugdir, settings_object +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args, test=False): @@ -56,7 +56,7 @@ def execute(args, test=False): return bug = bd.bug_from_shortname(args[0]) if len(args) == 1: - if bug.target is None or bug.target is settings_object.EMPTY: + if bug.target is None: print "No target assigned." else: print bug.target diff --git a/libbe/bug.py b/libbe/bug.py index dfa49f2..611a9cc 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -68,7 +68,7 @@ def load_severities(severity_def): global severity_values global severity_description global severity_index - if severity_def == settings_object.EMPTY: + if severity_def == None: return severity_values = tuple([val for val,description in severity_def]) severity_description = dict(severity_def) @@ -88,9 +88,9 @@ def load_status(active_status_def, inactive_status_def): global status_values global status_description global status_index - if active_status_def == settings_object.EMPTY: + if active_status_def == None: active_status_def = globals()["active_status_def"] - if inactive_status_def == settings_object.EMPTY: + if inactive_status_def == None: inactive_status_def = globals()["inactive_status_def"] active_status_values = tuple([val for val,description in active_status_def]) inactive_status_values = tuple([val for val,description in inactive_status_def]) @@ -178,7 +178,7 @@ class Bug(settings_object.SavedSettingsObject): def time_string(): return {} def _get_time(self): - if self.time_string == None or self.time_string == settings_object.EMPTY: + if self.time_string in [None, settings_object.EMPTY]: return None return utility.str_to_time(self.time_string) def _set_time(self, value): @@ -255,7 +255,7 @@ class Bug(settings_object.SavedSettingsObject): def _setting_attr_string(self, setting): value = getattr(self, setting) - if value == settings_object.EMPTY: + if value in [None, settings_object.EMPTY]: return "" else: return str(value) @@ -283,7 +283,7 @@ class Bug(settings_object.SavedSettingsObject): ("summary", self.summary)] ret = '<bug>\n' for (k,v) in info: - if v is not settings_object.EMPTY: + if v is not None: ret += ' <%s>%s</%s>\n' % (k,xml.sax.saxutils.escape(v),k) for estr in self.extra_strings: ret += ' <extra-string>%s</extra-string>\n' % estr @@ -477,8 +477,8 @@ def cmp_attr(bug_1, bug_2, attr, invert=False): return 1 val_1 = getattr(bug_1, attr) val_2 = getattr(bug_2, attr) - if val_1 == settings_object.EMPTY: val_1 = None - if val_2 == settings_object.EMPTY: val_2 = None + if val_1 == None: val_1 = None + if val_2 == None: val_2 = None if invert == True : return -cmp(val_1, val_2) diff --git a/libbe/comment.py b/libbe/comment.py index c4000fa..f573cea 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -72,13 +72,16 @@ def list_to_root(comments, bug, root=None): for comment in comments: assert comment.uuid != None uuid_map[comment.uuid] = comment + for comment in comments: + if comment.alt_id != None and comment.alt_id not in uuid_map: + uuid_map[comment.alt_id] = comment if root == None: root = Comment(bug, uuid=INVALID_UUID) else: uuid_map[root.uuid] = root for comm in comments: rep = comm.in_reply_to - if rep == None or rep == settings_object.EMPTY or rep == bug.uuid: + if rep == None or rep == bug.uuid: root_comments.append(comm) else: parentUUID = comm.in_reply_to @@ -136,6 +139,10 @@ class Comment(Tree, settings_object.SavedSettingsObject): kwargs["required_saved_properties"]=required_saved_properties return settings_object.versioned_property(**kwargs) + @_versioned_property(name="Alt-id", + doc="Alternate ID for linking imported comments. Internally comments are linked (via In-reply-to) to the parent's UUID. However, these UUIDs are generated internally, so Alt-id is provided as a user-controlled linking target.") + def alt_id(): return {} + @_versioned_property(name="From", doc="The author of the comment") def From(): return {} @@ -231,7 +238,7 @@ class Comment(Tree, settings_object.SavedSettingsObject): def _setting_attr_string(self, setting): value = getattr(self, setting) - if value == settings_object.EMPTY: + if value in [None, settings_object.EMPTY]: return "" else: return str(value) @@ -264,6 +271,7 @@ class Comment(Tree, settings_object.SavedSettingsObject): email.encoders.encode_base64(msg) body = msg.as_string() info = [("uuid", self.uuid), + ("alt-id", self.alt_id), ("short-name", shortname), ("in-reply-to", self.in_reply_to), ("from", self._setting_attr_string("From")), @@ -272,7 +280,7 @@ class Comment(Tree, settings_object.SavedSettingsObject): ("body", body)] lines = ["<comment>"] for (k,v) in info: - if v not in [settings_object.EMPTY, None]: + if v != None: lines.append(' <%s>%s</%s>' % (k,xml.sax.saxutils.escape(v),k)) lines.append("</comment>") istring = ' '*indent @@ -281,33 +289,44 @@ class Comment(Tree, settings_object.SavedSettingsObject): def from_xml(self, xml_string, verbose=True): """ - Warning: does not check for comment uuid collision. + Note: If alt-id is not given, translates any <uuid> fields to + <alt-id> fields. >>> commA = Comment(bug=None, body="Some\\ninsightful\\nremarks\\n") >>> commA.uuid = "0123" >>> commA.time_string = "Thu, 01 Jan 1970 00:00:00 +0000" >>> xml = commA.xml(shortname="com-1") >>> commB = Comment() >>> commB.from_xml(xml) - >>> attrs=['uuid','in_reply_to','From','time_string','content_type','body'] - >>> for attr in attrs: + >>> attrs=['uuid','alt_id','in_reply_to','From','time_string','content_type','body'] + >>> for attr in attrs: # doctest: +ELLIPSIS ... if getattr(commB, attr) != getattr(commA, attr): ... estr = "Mismatch on %s: '%s' should be '%s'" ... args = (attr, getattr(commB, attr), getattr(commA, attr)) ... print estr % args + Mismatch on uuid: '...' should be '0123' + Mismatch on alt_id: '0123' should be 'None' + >>> print commB.alt_id + 0123 + >>> commA.From + >>> commB.From """ comment = ElementTree.XML(xml_string) if comment.tag != "comment": raise InvalidXML(comment, "root element must be <comment>") - tags=['uuid','in-reply-to','from','date','content-type','body'] + tags=['uuid','alt-id','in-reply-to','from','date','content-type','body'] + uuid = None for child in comment.getchildren(): if child.tag == "short-name": pass elif child.tag in tags: - if child.text == None: + if child.text == None or len(child.text) == 0: text = settings_object.EMPTY else: text = xml.sax.saxutils.unescape(child.text.strip()) - if child.tag == 'from': + if child.tag == "uuid": + uuid = text + continue # don't set the bug's uuid tag. + elif child.tag == 'from': attr_name = "From" elif child.tag == 'date': attr_name = 'time_string' @@ -319,6 +338,8 @@ class Comment(Tree, settings_object.SavedSettingsObject): elif verbose == True: print >> sys.stderr, "Ignoring unknown tag %s in %s" \ % (child.tag, comment.tag) + if self.alt_id == None and uuid != None: + self.alt_id = uuid def string(self, indent=0, shortname=None): """ |