Re: Sample code using rpm-objects (Iterative Delete)
seth vidal <skvidal-c/MNwgJ9CEH2fBVCVOL8/[email protected]> 23 Mar 2004 13:28:30 -0500
| Newsgroups | gmane.linux.redhat.rpm.python |
|---|---|
| Message-ID | <1080066510.14903.207.camel@opus> |
On Wed, 2005-08-31 at 09:13, Adam T. Gautier wrote:
> Below is the code I used to iterate and delete packages from the RPM
> database. I have been hacking around with the code and this should
> work, I have used it, but should be seen as just an example.
>
since you said you were new to python some style comments are included.
> def removeHeader(header):
> ''' Removes all require map references for the given header'''
> # Loop through what header requires. This is more efficent than
> # looping through the require map of headers
> for require in header.getRequires():
> # Get the list headers that require the same requirement of the
> # header given
> requires = require_map_of_headers[require]
> # Remove the header given
> requires.remove(header)
> print "Removed required ("+key+") dependancy of header("+\
> str(header.getName())+")"
> # If there are no more headers that need this requirement. remove
> # the requirement
> if(0==len(requires)):
You don't need to put your if statements in parens. It's noted as a
common mistake and generally bad style in various guides I've read.
> rpmdb.erase(str(header.getName()))
> print "Removed package("+str(header.getName())+\
> "-"+str(header.getVersion())+"-"+\
> str(header.getRelease())+")"
Doing this output with format strings %s % somevariable is a lot easier
to read and follow.
-sv