need help to parse a specfile from python

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

 



Hi folks

I could use some help on an apparently very simple task, that I can't get to work..


Our build needs to inspect specfiles in order to discover the actual contents, in terms of the exact set of output rpms, and the like

So far we were using a C-code, that relied on a few rpm libraries:
cc -g -Wall spec2make.c -o spec2make -lrpm -lrpmbuild -lrpmio -lpopt

This code more or less needs attention each time we move to a more recent linux distro, 
with fedora15 and rpm-4.9 it's so bad that I'm trying to move to a python-based code instead

The objective is pretty simple, parse a specfile, compute the list of rpms that would be output with rpmbuild;
Something like this would almost do the trick:

########
specfile='kernel-2.6.spec'

import rpm
ts=rpm.TransactionSet()
s=ts.parseSpec(specfile)
for p in s.packages:
    h=p.header
    print 'Found package',h.format('%{name}'),h.format('%{version}'),h.format('%{release}',h.format('%{arch}'))
########

However, in many cases like with this kernel specfile, the list of packages actually built may be shorter than this 'theoretical' list

The C version was doing something like this (very simplified) in order to successfully filter out irrelevant packages

/*-----*/

  ts = rpmtsCreate();
  parseSpec (ts, filename, ...)
  spec = rpmtsSpec (ts)

  for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {

    (void) headerNEVRA(pkg->header, &name, &unused, &version, &release, &arch);

    if (name && version && release && arch && pkg->fileList) {
	/* print out package info */
    }
  }

/*-----*/


Now for my question

1. how can I write a python code that does the equivalent of pkg->fileList ?
I have tried most of the methods available to the 'h' (rpm.hdr) object, and mostly everything returns void information
It feels like the object is not properly initialized...


And I'd also be interested in discussing the following questions, although less critical to me at this point:

2. moving beyond what is described above, I'd also love to be able to pass the python code some data to model any rpmbuild command-line argument; I mean, if the build actually invokes e.g.
rpmbuild --without-doc --define "foo bar" -bs kernel-2.6.spec
then it may impact the set of output rpms, but I would not know how to instruct the python code about that
(the C-code that I mention tried to pass popt options through rpmcliInit, which never quite worked out...)

3. I've never been able to find an online resource that would explain all this, and mostly came up with the python code by guessing, which felt cool at first but turned out very frustrating afterwards :) I guess I'm doing it all wrong because of that..
Any examples / resources out there, apart from the doxygen doc that honestly I found of poor help for this very simple task.

many thanks in advance -- Thierry

_______________________________________________
Rpm-list mailing list
Rpm-list@xxxxxxxxxxxxx
http://lists.rpm.org/mailman/listinfo/rpm-list


[Index of Archives]     [RPM Ecosystem]     [Linux Kernel]     [Red Hat Install]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Red Hat]     [Gimp]     [Yosemite News]     [IETF Discussion]

  Powered by Linux