On Thu, Jul 30, 2009 at 08:32:34PM +0200, Michael Bienia wrote:
> I'm trying to improve some parts from Ubuntu's requestsync script (in
> ubuntu-dev-tools) and was looking if the Changelog class from
> python-debian is usable to replace the simple code from requestsync to
> copy new changelog entries from a existing Debian changelog into the
> sync bug.
> Unfortunately the Changelog class does only support adding new blocks
> but nothing to access existing changelog blocks or to iterate over the
> changelog blocks. I'd like to do something like this:

the attached patch is supposed to add iterator over changelog blocks, I'm
sending it for review if someone wants to comment

filippo
-- 
Filippo Giunchedi - http://esaurito.net - 0x6B79D401

Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem.
-- David Wheeler
>From b156ca0785a55121df90c3eeba63a36d0f7e59a9 Mon Sep 17 00:00:00 2001
From: Filippo Giunchedi <fili...@esaurito.net>
Date: Sun, 9 Aug 2009 12:36:14 +0100
Subject: [PATCH] changelog: add iterator over changelog blocks

Also add a basic test for the returned iterator

Closes: #539334
---
 debian/changelog           |    6 +++++-
 debian_bundle/changelog.py |    7 +++++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 748ec97..6185069 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,6 @@
 python-debian (0.1.15) UNRELEASED; urgency=low
 
+  [ John Wright ]
   * deb822: Don't ignore leading newlines on field data with apt_pkg
     (Closes: #466753)
   * changelog: Consistently parse different types of inputs.  The
@@ -9,7 +10,10 @@ python-debian (0.1.15) UNRELEASED; urgency=low
   * deb822: Faster non-shared storage by keeping a TagFile object
     around for each Deb822 object yielded
 
- -- John Wright <j...@debian.org>  Thu, 30 Jul 2009 01:03:49 +0200
+  [ Filippo Giunchedi ]
+  * changelog: add iterator over changelog blocks (Closes: #539334)
+
+ -- Filippo Giunchedi <fili...@debian.org>  Sun, 09 Aug 2009 12:35:00 +0100
 
 python-debian (0.1.14) unstable; urgency=low
 
diff --git a/debian_bundle/changelog.py b/debian_bundle/changelog.py
index ae72a90..0beab84 100644
--- a/debian_bundle/changelog.py
+++ b/debian_bundle/changelog.py
@@ -495,6 +495,9 @@ class Changelog(object):
             cl += str(block)
         return cl
 
+    def __iter__(self):
+        return iter(self._blocks)
+
     def set_distributions(self, distributions):
         self._blocks[0].distributions = distributions
     distributions = property(lambda self: self._blocks[0].distributions,
@@ -658,6 +661,10 @@ class ChangelogTests(unittest.TestCase):
         for c in (c1, c2, c3):
             self.assertEqual(str(c), cl_data)
 
+    def test_block_iterator(self):
+        c = Changelog(open('test_changelog'))
+        self.assertEqual(len(c._blocks), len([b for b in c]))
+
 class VersionTests(unittest.TestCase):
 
     def _test_version(self, full_version, epoch, upstream, debian):
-- 
1.6.3.3

Reply via email to