Parsing single debian/control file
John Wright
jsw at debian.org
Fri May 4 12:11:29 UTC 2012
Sorry, let's try again with the real mailing list address. :)
On Fri, May 04, 2012 at 05:08:40AM -0700, John Wright wrote:
> Hi Andreas,
>
> Sorry I didn't get back to you earlier.
>
> On Wed, Apr 18, 2012 at 09:25:46PM +0200, Andreas Tille wrote:
> > Hi John,
> >
> > I wonder what might be the proper mailing list to ask questions
> > like this - feel free to quote me fully or in parts in public.
>
> I have added the package discussion mailing list to Cc.
>
> > I intend to parse some machine readable files in some team maintained
> > packages. When trying something like
> >
> > ctrl = open('debian/control','r')
> > for ctrlstanza in deb822.Packages.iter_paragraphs(ctrl):
> > print ctrlstanza
> >
> > I get the full text of debian/control (same if I try
> > deb822.Sources.iter_paragraphs instead) - so there is no chance to parse
> > the single paragraphs in the Sources and Binary packages section. I
> > might be stupid because I'd regard this as a basic use case for
> > python-debian but I did not found a way to approach this. Any hint how
> > to do this properly?
>
> The code you have above is correct (though I would generally use
> deb822.Deb822.iter_paragraphs - Packages and Sources may have some
> special semantics). The string representation of a Deb822 instance is
> designed to be just like its input - idential to it, if possible. But
> it works like a dict, so you can do
>
> for stanza in deb822.Deb822.iter_paragraphs(ctrl):
> if 'source' in stanza:
> print 'Source:', stanza['source']
> if 'package' in stanza:
> print 'Package:', stanza['package']
>
> The keys are case-insensitive. You can also add new keys. The string
> representation will place the new fields at the end, using whatever
> capitalization you initially used.
>
> This could probably use some examples and better documentation in
> general.
>
> > Something related but not high priority for me and thus perhaps an issue
> > for a wishlist bug (have not checked BTS for it): Since DEP5 is accepted
> > the parsing of debian/copyright might be an interesting feature as well.
>
> I haven't seen a request for this yet. Please do file a bug!
>
> > Kind regards and thanks for your help
> >
> > Andreas.
> >
> > --
> > http://fam-tille.de
--
John Wright <jsw at debian.org>
More information about the pkg-python-debian-discuss
mailing list