I've included the new-and-improved version, which runs in a couple of 
seconds....

On Friday 04 July 2003 10:54, Olav Vitters wrote:
> You are looking for os.popen and friends.

OK, popen didn't work for my original version of the script, but for the 
simplified version I posted it would have worked fine, yes, and I didn't even 
think of it. Thanks.

> > Also, I have a few questions:
> >
> > 1. Is there a faster way to do this than running urpmf ~5000 times?

I already answered my own question--just read the synthesis file!

> I've attached my version. Your version is still running, so I don't know
> if it works correctly. Please compare it with the output of your version.
>
> Don't forget to change the --media.

When I try this, it doesn't work.  When I type "urpmf --media 
main-cooker,contrib-cooker --provides --obsoletes" at a command line, I get 
back a usage error from urpmf. I was hoping there was some way to tell urpmf 
to operate on everything (or at least operate on this list of files), but 
leaving the package name off doesn't seem to do it. (I've got 4.4-8mdk, if 
that's relevant.)

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

OK, I'll look into it. Ideally it should provide the equivalent interface to 
perl-URPM, right?

> > 5. Is there actually no python-expect or python-pexpect? Would anyone
> > besides me want it? (This would take a few minutes.)
>
> Searched for something like that last week. I found the following:
>   http://sourceforge.net/projects/pexpect/

Yeah, I meant "is there actually no python-expect or python-pexpect package 
for Mandrake," but I wasn't very clear. I've since found that drakian 
provides a binary-only (alien'd) python-expect for python-2.1, but that's not 
exactly what I want....

Anyway, I have the latest versions of pexpect, python-expect, and ExpectPy; 
making packages for them should be trivial. In my opinion, pexpect is the 
coolest (it's pure python, and it's tiny, it's just about as efficient as the 
others, and it handles the 95% most common uses for expect exactly like the 
real thing), but it might be nice to have python-expect or ExpectPy as well 
(since they actually wrap expect, they handle 100% of all uses exactly like 
the real thing--and, if anyone cares, they work with python 2.1).

> > 6. While I'm at it, does anyone want any other python packages? For my
> > own use, I've packaged up
> > python-{rational,cRat,fpconst,indices,xoltar,xzip,Itpl,logging} and would
> > be happy to share them (or, for that matter, describe them) if there's
> > any potential interest. I'd be happy to similarly package up any common
> > python modules....
>
> More Python packages are always welcome here.

OK, I'll submit them all.

--- CUT HERE ---
#!/usr/bin/env python

import sys
import os
import gzip

synthesispath = "/var/lib/urpmi/"
media = [ "main-cooker", "contrib-cooker" ]

def readfile(fname):
    return file(fname).readlines()
def zreadfile(fname):
    return gzip.GzipFile(fname).readlines()

print "Getting list of packages...",
everything = []
for medium in media:
    everything += zreadfile(synthesispath + '/synthesis.hdlist.' + medium + 
'.cz')
linecount = len(everything)
print linecount

obsoletes = []
provides = {}
print "This may take a while..."

tmpobsoletes = []
tmpprovides = []
for i in range(linecount):
    line = everything[i].split('@')
    if line[1] == 'provides':
        tmpprovides = line[2:]
    elif line[1] == 'obsoletes':
        tmpobsoletes = line[2:]
    elif line[1] == 'info':
        package = line[2]
        print "\rline %6d/%6d: %s" % (i, linecount, package),
        for virtual in tmpprovides:
            if not provides.has_key(virtual):
                provides[virtual] = []
            provides[virtual].append(package)
        for virtual in tmpobsoletes:
            obsoletes.append((virtual, package))
        tmpprovides = []
        tmpobsoletes = []

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...."



Reply via email to