1 # Copyright (C) 2005 Aaron Bentley and Panometrics, Inc.
2 # <abentley@panoramicfeedback.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """Compare two bug trees"""
18 from libbe import cmdutil, bugdir
19 from libbe.utility import time_to_str
20 from libbe.bug import cmp_severity
23 def diff(old_bugdir, new_bugdir):
27 for old_bug in old_bugdir:
28 new_bug = new_bugdir.bug_map.get(old_bug.uuid)
30 removed.append(old_bug)
32 if old_bug != new_bug:
33 modified.append((old_bug, new_bug))
34 for new_bug in new_bugdir:
35 if not old_bugdir.bug_map.has_key(new_bug.uuid):
37 return (removed, modified, added)
39 def diff_report(diff_data, bug_dir):
40 (removed, modified, added) = diff_data
41 def modified_cmp(left, right):
42 return cmp_severity(left[1], right[1])
44 added.sort(cmp_severity)
45 removed.sort(cmp_severity)
46 modified.sort(modified_cmp)
49 print "New bug reports:"
51 print bug.string(shortlist=True)
55 for old_bug, new_bug in modified:
56 change_str = bug_changes(old_bug, new_bug, bug_dir)
57 if change_str is None:
61 print "Modified bug reports:"
65 print "Removed bug reports:"
67 print bug.string(shortlist=True)
69 def change_lines(old, new, attributes):
71 for attr in attributes:
72 old_attr = getattr(old, attr)
73 new_attr = getattr(new, attr)
74 if old_attr != new_attr:
75 change_list.append((attr, old_attr, new_attr))
76 if len(change_list) >= 0:
81 def bug_changes(old, new, bugs):
82 change_list = change_lines(old, new, ("time", "creator", "severity",
83 "target", "summary", "status", "assigned"))
85 old_comment_ids = [c.uuid for c in old.comment_root.traverse()]
86 new_comment_ids = [c.uuid for c in new.comment_root.traverse()]
87 change_strings = ["%s: %s -> %s" % f for f in change_list]
88 for comment_id in new_comment_ids:
89 if comment_id not in old_comment_ids:
90 summary = comment_summary(new.comment_root.comment_from_uuid(comment_id), "new")
91 change_strings.append(summary)
92 for comment_id in old_comment_ids:
93 if comment_id not in new_comment_ids:
94 summary = comment_summary(new.comment.root.comment_from_uuid(comment_id), "removed")
95 change_strings.append(summary)
97 if len(change_strings) == 0:
99 return "%s\n %s" % (new.string(shortlist=True),
100 " \n".join(change_strings))
103 def comment_summary(comment, status):
104 return "%8s comment from %s on %s" % (status, comment.From,
105 time_to_str(comment.time))
107 suite = doctest.DocTestSuite()