tag 634848 + patch
thanks

Hi Jelmer (2011.07.20_17:10:13_+0200)
> FWIW bzr-builddeb has some code for this that I've been meaning to
> upstream into python-debian.

Here's a patch that does that.

Jelmer: It looks like your current code doesn't deal with bug lists that
span lines.

SR

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  H: +27 21 465 6908 C: +27 72 419 8559  UCT: x3127
diff --git a/lib/debian/changelog.py b/lib/debian/changelog.py
index 93c348f..b7e68cd 100644
--- a/lib/debian/changelog.py
+++ b/lib/debian/changelog.py
@@ -128,6 +128,25 @@ class ChangeBlock(object):
                 changes.append(change)
             self._changes = changes
 
+    def _get_bugs_closed_generic(self, type_re):
+        changes = u' '.join(self._changes)
+        bugs = []
+        for match in type_re.finditer(changes):
+            closes_list = match.group(0)
+            for match in re.finditer("\d+", closes_list):
+                bugs.append(int(match.group(0)))
+        return bugs
+
+    def _get_bugs_closed(self):
+        return self._get_bugs_closed_generic(closes)
+
+    bugs_closed = property(_get_bugs_closed)
+
+    def _get_lp_bugs_closed(self):
+        return self._get_bugs_closed_generic(closeslp)
+
+    lp_bugs_closed = property(_get_lp_bugs_closed)
+
     def __unicode__(self):
         # TODO(jsw): Switch to StringIO or a list to join at the end.
         block = ""
@@ -183,6 +202,9 @@ vim_variables = re.compile('^vim:', re.IGNORECASE)
 cvs_keyword = re.compile('^\$\w+:.*\$')
 comments = re.compile('^\# ')
 more_comments = re.compile('^/\*.*\*/')
+closes = re.compile('closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*',
+                    re.IGNORECASE)
+closeslp = re.compile('lp:\s+\#\d+(?:,\s*\#\d+)*', re.IGNORECASE)
 
 old_format_re1 = re.compile('^(\w+\s+\w+\s+\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}'
         '\s+[\w\s]*\d{4})\s+(.*)\s+(<|\()(.*)(\)|>)')
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index 4c5b74e..c4ad14c 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -308,6 +308,9 @@ class Deb822(Deb822Dict):
             necessary in order to properly interpret the strings.)
         """
 
+        if isinstance(sequence, basestring):
+            sequence = sequence.splitlines()
+
         if _have_apt_pkg and use_apt_pkg and isinstance(sequence, file):
             parser = apt_pkg.TagFile(sequence)
             for section in parser:
diff --git a/tests/test_changelog b/tests/test_changelog
index 1924339..8aada8d 100644
--- a/tests/test_changelog
+++ b/tests/test_changelog
@@ -1,7 +1,9 @@
 gnutls13 (1:1.4.1-1) unstable; urgency=HIGH
 
   [ James Westby ]
-  * New upstream release.
+  * New upstream release. Closes: #123, #456,
+    #789. LP: #1234, #2345,
+    #3456
   * Remove the following patches as they are now included upstream:
     - 10_certtoolmanpage.diff
     - 15_fixcompilewarning.diff
diff --git a/tests/test_changelog.py b/tests/test_changelog.py
index 65e7d66..94b1728 100755
--- a/tests/test_changelog.py
+++ b/tests/test_changelog.py
@@ -55,7 +55,9 @@ class ChangelogTests(unittest.TestCase):
         """gnutls13 (1:1.4.1-1) unstable; urgency=HIGH
 
   [ James Westby ]
-  * New upstream release.
+  * New upstream release. Closes: #123, #456,
+    #789. LP: #1234, #2345,
+    #3456
   * Remove the following patches as they are now included upstream:
     - 10_certtoolmanpage.diff
     - 15_fixcompilewarning.diff
@@ -161,6 +163,14 @@ class ChangelogTests(unittest.TestCase):
         self.assertEqual(c.epoch, '1')
         self.assertEqual(str(c.version), c.full_version)
 
+    def test_bugs_closed(self):
+        f = open('test_changelog')
+        c = changelog.Changelog(f)
+        f.close()
+        block = next(iter(c))
+        self.assertEqual(block.bugs_closed, [123, 456, 789])
+        self.assertEqual(block.lp_bugs_closed, [1234, 2345, 3456])
+
     def test_allow_full_stops_in_distribution(self):
         f = open('test_changelog_full_stops')
         c = changelog.Changelog(f)
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index c3806bd..8f23e78 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -821,6 +821,16 @@ Description: python modules to work with Debian-related data formats
             UNPARSED_PARAGRAPHS_WITH_COMMENTS.splitlines(), use_apt_pkg=False))
         self._test_iter_paragraphs_comments(paragraphs)
 
+    def test_iter_paragraphs_string_comments_use_apt_pkg(self):
+        paragraphs = list(deb822.Deb822.iter_paragraphs(
+            UNPARSED_PARAGRAPHS_WITH_COMMENTS, use_apt_pkg=True))
+        self._test_iter_paragraphs_comments(paragraphs)
+
+    def test_iter_paragraphs_string_comments_native(self):
+        paragraphs = list(deb822.Deb822.iter_paragraphs(
+            UNPARSED_PARAGRAPHS_WITH_COMMENTS, use_apt_pkg=False))
+        self._test_iter_paragraphs_comments(paragraphs)
+
 
 class TestPkgRelations(unittest.TestCase):
 

Reply via email to