Andi Payn <[EMAIL PROTECTED]> writes:

> I wrote a quick python hack to look for any current packages that obsolete any 
> other current package. I've included it at the end of this email. 
> Unfortunately, I think it would take just about forever for me to run it 
> (~5000 urpmf calls). Anyone who can run it faster, I'll be your best friend 
> and love you forever and ever and all that stuff....
> 
> You'll probably have to change line 6 (where I set urpmflags to select the 
> right media), but that's about it. Oh, and ignore the tmpnam warnings; 
> there's no other good alternative without python-expect or -pexpect. Just 
> don't run two copies at once.
> 
> Also, I have a few questions:
> 
> 1. Is there a faster way to do this than running urpmf ~5000 times?

Yes, using perl-URPM will to it nicely, look at distriblint packages from
Olivier Thauvin for example.

> 2. Does running urpmf ~5000 times go out to the internet ~5000 times?

No, it only uses local copy of hdlist.

> 3. Would it help if I did this in perl (because we have a perl-URPM but not a 
> python-URPM)?

Yes, it will do the equivalent of one urpmf (hdlist loaded once) and everything
else will be very fast.

> 4. Would anyone besides me want a python-URPM? (This would obviously take some 
> time, but I'd be happy to look into it.)

If anyone want to do it.

>...
> --- CUT HERE ---
> #!/usr/bin/env python
> 
> import sys
> import os
> 
> urpmflags = "--media main-cooker,contrib-cooker"
> 
> def readfile(fname):
>     return file(fname).readlines()
> 
> print "Getting list of packages...",
> pkgsfname = os.tmpnam()
> os.system("urpmq %s --list >%s" % (urpmflags, pkgsfname))

The same, this results is immediat (a simple
  foreach (@{$urpm->{deplist}}) {
    print $_->name."\n";
  }

> pkgs = readfile(pkgsfname)
> pkgcount = len(pkgs)
> print pkgcount
> 
> obsoletes = []
> provides = {}
> print "This may take a while..."
> pkgfname = os.tmpnam()
> for i in range(pkgcount):
>     pkg = pkgs[i]
>     print "\rprocessing #%4d/%4d: %s..." % (i, pkgcount, pkg),
>     os.system("urpmf %s --provides --obsoletes %s > %s" % (urpmflags, 
> pkg.strip(), pkgfname))

Such a command does not read hdlist but synthesis, so your script will be a bit
more faster.

>     provobs = readfile(pkgfname)
>     for line in provobs:
>         ptv = line.strip().split(':')
>         if len(ptv) == 3:
>             package, tag, virtual = ptv
>             if tag == 'obsoletes':
>                 obsoletes.append([virtual, package])
>             elif tag == 'provides':
>                 if not provides.has_key(virtual):
>                     provides[virtual] = []
>                     provides[virtual].append(package)
> 
> print "\r",
> for obsolete in obsoletes:
>     virtual, pkgo = obsolete
>     if provides.has_key(virtual):
>         for pkgp in provides[virtual]:
>             if pkgp != pkgo:
>                 print "%s obsoletes %s, provided by %s" % (pkgo, virtual, 
> pkgp)
> print "And there you go...."

Fran�ois.

Reply via email to