Am Mittwoch, den 25.08.2010, 16:40 -0700 schrieb John Wright:
> 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....Thanks. That simplifies my code. You can inspect wrap-and-sort in ubuntu-dev-tools >= 0.102 (from experimental). -- Benjamin Drung Ubuntu Developer (www.ubuntu.com) | Debian Maintainer (www.debian.org)
signature.asc
Description: This is a digitally signed message part

