Bug#593525: python-debian: Please add a Control object

John Wright jsw at debian.org
Wed Aug 25 23:40:55 UTC 2010


Hi Benjamin,

On Thu, Aug 19, 2010 at 01:25:30AM +0200, Benjamin Drung wrote:
> Package: python-debian
> Version: 0.1.16
> Severity: wishlist
> 
> I want to parse a debian/control file and found no 'Control' object that
> represents a debian/control file. I had to create my own Crontol object that
> contains a list of Deb822 objects:
> 
> def get_blocks(blocks, line):
> 	if line.strip() == "":
> 		blocks.append(list())
> 	else:
> 		blocks[-1].append(line)
> 	return blocks
> 
> lines = open("debian/control").readlines()
> blocks = reduce(get_blocks, lines, [[]])
> self.blocks = map(debian.deb822.Deb822, blocks)
> 
> Please add a Control object.

The classes in the deb822 packages each represent one "paragraph" of a
multi-paragraph file.  What you probably want is the iter_paragraphs
method on Deb822 (and hence all of its subclasses).  It yields one
object for each paragraph in the file.  Control files have no special
multivalued fields, so the Deb822 class should work fine:

    for paragraph in deb822.Deb822.iter_paragraphs(open('debian/control')):
        # paragraph is a Deb822 object.
	print paragraph.items()

We could probably use some better documentation for new users....

-- 
John Wright <jsw at debian.org>





More information about the pkg-python-debian-maint mailing list