Re: 0.99 vs redhat

Vincent Cojot <[email protected]>
Newsgroups gmane.network.up2date.current.devel
Message-ID <[email protected]>
Hello everyone,

	We had this problem before and one of the guys in our Team solved
it.. The solution is not to use rpm.labelCompare but to use
rpm.headerFromPackage and rpm.versionCompare.. The code that we use runs
under python 2.2 (because of listDir(), which gives you the most recent
package even if there are -several- packages by the same name in the same
directory ).. Here are the main classes:

---- myclasses.py -------------------
import os, rpm

class RPMfile:
        def __init__(self, file):
                self.filename = file

                package = os.open(file, os.O_RDONLY)
                (self.header, self.source) = rpm.headerFromPackage(package)
                os.close(package)

                self.name = self.header[rpm.RPMTAG_NAME]
                self.version = self.header[rpm.RPMTAG_VERSION]
                self.release = self.header[rpm.RPMTAG_RELEASE]
                self.arch = self.header[rpm.RPMTAG_ARCH]

                if self.source == 0: self.type = 'binary'
                elif self.source == 1: self.type = 'source'

def compareHeaders(rpmfile1, rpmfile2):
        if rpm.versionCompare(rpmfile1.header, rpmfile2.header) > 0: return rpmfile1
        if rpm.versionCompare(rpmfile1.header, rpmfile2.header) < 0: return rpmfile2

def listDir(directory, ext): return [os.path.join(directory, unit) for unit in os.listdir(directory) if os.path.splitext(unit)[1] ==  ext]

def uniqList(list):
        d = {}
        for item in list:
                d[item] = 1
        return d.keys()

def countList(list):
        d = {}
        for item in uniqList(list):
                d[item] = list.count(item)
        return d

def filterDict(dict):
        for unit in dict.items():
                if unit[1] == 1: del dict[unit[0]]
        return dict


----- Sample use of this (requires python 2.2 but feel free to adapt it to 1.5.2) ----:

#!/usr/bin/python2.2

import os
import sys
from myclasses import *

if len(sys.argv) != 2: sys.exit("Only one argument
allowed!")
if not os.path.isdir(sys.argv[1]): sys.exit("%s is not
a directory!" %sys.argv[1])

rpms = [RPMfile(unit) for unit in listDir(sys.argv[1], ".rpm")]
archs = uniqList([unit.arch for unit in rpms])

struct = {}
discr = []
for dude in archs:
        struct[dude] = filterDict(countList([unit.name for unit in rpms if unit.arch == dude]))
        for elem in struct[dude].items():
                discr.append([unit for unit in rpms if (unit.arch == dude and unit.name == elem[0])])

reject = []
for unit in discr:
        unit.remove(reduce(compareHeaders, unit))
        for elem in unit:
                reject.append(elem.filename)

print struct
for unit in reject:
        print "deleting %s" %unit
        os.unlink(unit)

-------------------- end ---------------


Without using this script, and by commenting out "listDir()", it is
possible to run it under 1.5.2:

[root@pains rpm]# python
Python 1.5.2 (#1, Dec 21 2000, 15:29:08)  [GCC egcs-2.91.66 19990314/Linux
(egcs - on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from myclasses import RPMfile, compareHeaders
>>>
>>> compareHeaders(RPMfile("php-3.0.18-1.6.x.i386.rpm"), RPMfile("php-3.0.18-8.i386.rpm")).filename
'php-3.0.18-8.i386.rpm'
>>>
compareHeaders(RPMfile("php-3.0.18-8.i386.rpm"),RPMfile("php-3.0.18-1.6.x.i386.rpm")).filename
'php-3.0.18-8.i386.rpm'

(this returns the right result)...

PS: If you find this useful, please credit Cedric Karm
([email protected])

I hope this helps, current is a great package and we will try to help...

Vincent
,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,
Vincent S. Cojot, Computer Engineering. STEP project. _.,-*~'`^`'~*-,._.,-*~
Ecole Polytechnique de Montreal, Comite Micro-Informatique. _.,-*~'`^`'~*-,.
Linux Xview/OpenLook resources page _.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'
http://step.polymtl.ca/~coyote  _.,-*~'`^`'~*-,._ [email protected]

They cannot scare me with their empty spaces
Between stars - on stars where no human race is
I have it in me so much nearer home
To scare myself with my own desert places.       - Robert Frost

On Thu, 7 Mar 2002, John Berninger wrote:

> Replies inlined:
>
> On Thu, 07 Mar 2002, Rob Hagopian wrote:
>
> > Mar 03 11:26:00 Adding php-3.0.18-1.6.x.i386.rpm
> > Mar 03 11:26:00   type(hit) = <type 'string'>
> > Mar 03 11:26:00 hit = php:3.0.18:8:
> > Mar 03 11:26:00 Comparing packages: php-3.0.18-1.6.x and php-3.0.18-8
> > Mar 03 11:26:00 Removing php-3.0.18-8.i386.rpm
> > Mar 03 11:26:00 Older package deleted from db.
>         Eww.  This is not good - the code used to compare the package
> ages is take directly from the Python RPM bindings - we actually make a
> call to rpm.labelCompare() which is implemented inside the rpm-python
> shared library.  I'll check Red Hat's bugzilla and if encessary submit a
> bug about this.  I don't think we can do much, since we don't want to be
> in the business of comparing RPM ages...  that gets ugly real quick.
>
>
> > Mar 03 11:36:42 Adding kernel-2.4.9-31.i586.rpm
> > Mar 03 11:36:42   type(hit) = <type 'string'>
> > Mar 03 11:36:42 hit = kernel:2.4.9:31:
> > Mar 03 11:36:42 Comparing packages: kernel-2.4.9-31 and kernel-2.4.9-31
> > Mar 03 11:36:42 Package is same as in database - symlink issues?
> > Mar 03 11:36:42 Adding kernel-smp-2.4.9-31.i586.rpm
>         This is definitely somewhere in the Current code - I'll try to
> take a look at it tonight / tomorrow / this weekend.  I'm not /too/
> surprised at this, but having it warn me about symlink issues on
> different archs doesn't really seem quite right.  :)
>
> > I cleaned up the trees by hand (not like I haven't had to before), and
> > everything works great!
>         Except for the PHP thing above, you really shouldn't have to do
> that anymore - or, at least, we'd hoped so...
>
> --
> Thank you,
> John Berninger
>
> Systems Administrator		[email protected]
> Department of Mathematics	Box 8205, Harrelson Hall
> NC State University		Raleigh, NC 27695
> Phone:  (919)515-6315		Fax:	(919)515-3798
>
> GPG Key ID: A8C1D45C
>         Fingerprint: B1BB 90CB 5314 3113 CF22  66AE 822D 42A8 A8C1 D45C
> --
> _______________________________________________
> Current-server mailing list
> [email protected]
> http://lists.dulug.duke.edu/mailman/listinfo/current-server
>

,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,
Vincent S. Cojot, Computer Engineering. STEP project. _.,-*~'`^`'~*-,._.,-*~
Ecole Polytechnique de Montreal, Comite Micro-Informatique. _.,-*~'`^`'~*-,.
Linux Xview/OpenLook resources page _.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'
http://step.polymtl.ca/~coyote  _.,-*~'`^`'~*-,._ [email protected]

They cannot scare me with their empty spaces
Between stars - on stars where no human race is
I have it in me so much nearer home
To scare myself with my own desert places.       - Robert Frost
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.