Bumped to version 1.0.1
[be.git] / libbe / diff.py
index 94a2dc3f456db681ef8da9a421b054a715f587be..4c24073d891c4799ad17bcc937def561efe032ee 100644 (file)
@@ -1,22 +1,25 @@
-# Copyright (C) 2005-2010 Aaron Bentley and Panometrics, Inc.
+# Copyright (C) 2005-2011 Aaron Bentley <abentley@panoramicfeedback.com>
+#                         Chris Ball <cjb@laptop.org>
 #                         Gianluca Montecchi <gian@grys.it>
 #                         W. Trevor King <wking@drexel.edu>
 #
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
+# This file is part of Bugs Everywhere.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# Bugs Everywhere is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 2 of the License, or (at your
+# option) any later version.
 #
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# Bugs Everywhere is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Bugs Everywhere.  If not, see <http://www.gnu.org/licenses/>.
 
-"""Compare two bug trees."""
+"""Tools for comparing two :class:`libbe.bug.BugDir`\s.
+"""
 
 import difflib
 import types
@@ -30,8 +33,7 @@ from libbe.util.utility import time_to_str
 
 
 class SubscriptionType (libbe.util.tree.Tree):
-    """
-    Trees of subscription types to allow users to select exactly what
+    """Trees of subscription types to allow users to select exactly what
     notifications they want to subscribe to.
     """
     def __init__(self, type_name, *args, **kwargs):
@@ -80,7 +82,11 @@ def type_from_name(name, type_root, default=None, default_ok=False):
     raise InvalidType(name, type_root)
 
 class Subscription (object):
-    """
+    """A user subscription.
+
+    Examples
+    --------
+
     >>> subscriptions = [Subscription('XYZ', 'all'),
     ...                  Subscription('DIR', 'new'),
     ...                  Subscription('ABC', BUG_TYPE_ALL),]
@@ -112,7 +118,11 @@ class Subscription (object):
         return '<Subscription: %s (%s)>' % (self.id, self.type)
 
 def subscriptions_from_string(string=None, subscription_sep=',', id_sep=':'):
-    """
+    """Provide a simple way for non-Python interfaces to read in subscriptions.
+
+    Examples
+    --------
+
     >>> subscriptions_from_string(None)
     [<Subscription: DIR (all)>]
     >>> subscriptions_from_string('DIR:new,DIR:rem,ABC:all,XYZ:all')
@@ -135,8 +145,11 @@ def subscriptions_from_string(string=None, subscription_sep=',', id_sep=':'):
     return subscriptions
 
 class DiffTree (libbe.util.tree.Tree):
-    """
-    A tree holding difference data for easy report generation.
+    """A tree holding difference data for easy report generation.
+
+    Examples
+    --------
+
     >>> bugdir = DiffTree('bugdir')
     >>> bdsettings = DiffTree('settings', data='target: None -> 1.0')
     >>> bugdir.append(bdsettings)
@@ -251,8 +264,11 @@ class DiffTree (libbe.util.tree.Tree):
         return data_part
 
 class Diff (object):
-    """
-    Difference tree generator for BugDirs.
+    """Difference tree generator for BugDirs.
+
+    Examples
+    --------
+
     >>> import copy
     >>> bd = libbe.bugdir.SimpleBugDir(memory=True)
     >>> bd_new = copy.deepcopy(bd)
@@ -671,4 +687,7 @@ class Diff (object):
         return self._comment_summary_string(new_comment)
     def comment_body_change_string(self, bodies):
         old_body,new_body = bodies
-        return difflib.unified_diff(old_body, new_body)
+        return ''.join(difflib.unified_diff(
+                old_body.splitlines(True),
+                new_body.splitlines(True),
+                'before', 'after'))