[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Regexp to parse "Version:" fields

Christoph Haas <haas@debian.org> writes:

> On Wed, Jun 21, 2006 at 03:04:54PM +0200, Christoph Haas wrote:
>> On Wed, Jun 21, 2006 at 09:15:41AM -0300, Otavio Salvador wrote:
>> > Christoph Haas <haas@debian.org> writes:
>> > 
>> > > So before diving into into regular expressions any further (I have no
>> > > practical experience with lookahead patterns for example) I would like
>> > > to know if anyone else has worked on this. Perhaps even some Debian tool
>> > > does this parsing. I need an implementation in Python but if someone
>> > > shows me Perl code of a non-regexp algorithm I'd be happy, too.
>> > 
>> > Use apt_pkg.UpstreamVersion(). Is the easier way to do that.
>> Wow, this is great. Just why did I implement half of that myself
>> already? :)
> I guess I was a bit too quick to throw away my regexp approach. apt_pkg
> is pretty nice just that it does not yet support Python 2.4 on Sarge,
> the documentation is practically non-existing and an attempt to read a
> control file (not sure if that's even possible) in ipython gave me a
> segmentation fault. Even the documentation in
> /usr/share/doc/libapt-pkg-doc didn't help me much. May be my ignorance
> of course.
> Unless I understand what apt_pkg really is useful for I think I'll stick
> to regular expressions. :(

To parse a control file you should use apt_pkg.ParseTagFile. That read
an RFC-822 formated file and you can walk between all records (in case
of more then one) using Step(). There's a example of it in package

Well, basically you can use apt_pkg as a interface for apt itself and
in etch package version has a apt python module that's very much
user-friendly. I agree that apt_pkg and apt documentation isn't that

        O T A V I O    S A L V A D O R
 E-mail: otavio@debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://www.freedom.ind.br/otavio
"Microsoft gives you Windows ... Linux gives
 you the whole house."

Reply to: