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

Re: how to retrieve the pacakge URI and architecture from python-apt



On Tue, May 30, 2006 at 12:24:17PM +0200, A Mennucc wrote:
> hi
Hi,
 
> I need some help in using python-apt
> 
> I am preparing a program (*) that uses python-apt ; I need to list
> all packages that need upgrading, so I do this:
> 
>   import  apt, apt_pkg
>   apt_pkg.init()
>   cache=apt.Cache()
>   cache.upgrade()

You may want to use "cache.upgrade(True)" to perform a full
dist-upgrade (depends on your needs obvisouly).
 
>   for p in cache :
>     if p.isInstalled and  p.markedUpgrade \
>            and p.candidateOrigin[0].origin == 'Debian':
> 	   (work)

You could also skip the cache.upgrade() and run:

cache = apt.Cache()
upgradable = filter(lambda p: p.isUpgradable and p.candidateOrigin[0].origin == 'Debian', cache)

> and it works fine; then I would need to know where the candidate for 'p'
> is located, that is, the URL and the HTTP server where 'p' is supposed
> to be downloaded from... but I could not find a way to do that
> using 'python-apt'.... 

So you need the binary download? Try:
----------------------8<--------------------------------
import apt
import apt_pkg

cache = apt.Cache()
cache.upgrade(True)
fetcher = apt_pkg.GetAcquire()
pm = apt_pkg.GetPackageManager(cache._depcache)
pm.GetArchives(fetcher,cache._list,cache._records)
for item in fetcher.Items:
        print item.DescURI
----------------------8<--------------------------------

The above is a bit hacky, here is a different approach:
----------------------8<--------------------------------
import apt
import apt_pkg
cache = apt.Cache()
upgradable = filter(lambda p: p.isUpgradable, cache)
for pkg in upgradable:
        pkg._lookupRecord(True)
        path = apt_pkg.ParseSection(pkg._records.Record)["Filename"]
        cand = pkg._depcache.GetCandidateVer(pkg._pkg)
        for (packagefile,i) in cand.FileList:
                indexfile = cache._list.FindIndex(packagefile)
                if indexfile:
                        print indexfile.ArchiveURI(path)
----------------------8<--------------------------------

> Since  python-apt does not have documentation AFAICT, I am lost.

Yes, that is a major weak point. Most operations are now available in
python-apt (including download, install, all sorts of lookups). But
its pretty badly documented.
 
> Any help is appreciated.

I hope the above helps you.
 
> ps (*): the program in question is 'debdelta', and is available at
>   http://tonelli.sns.it/pub/mennucc1/debdelta/etch

A very interessting application! Do you have a repository of the code
somehwere? Or should I just grab the sources from that location (is
this the most current code)?

Thanks,
 Michael

-- 
Linux is not The Answer. Yes is the answer. Linux is The Question. - Neo



Reply to: