Small useful script: whence

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

 



Every now and then somebody on IRC asks "how do I get package X".  You
have package X installed, but don't remember from which repository it
came.  apt-cache policy does not help, since it only shows the hostname
(repository.maemo.org) so you can't tell Extras from Extras-Devel from
Fremantle Tools.

Here's a short Python script that wraps apt-cache showpkg and produces a
concise summary of which repositories have which versions.  Sample
output:

  ~ $ whence conboy
  installed
    0.6.0-alpha9
  repository.maemo.org/extras-devel/dists/fremantle/free/binary-armel/Packages
    0.3.2 0.4.0 0.4.1 0.4.2 0.4.3 0.4.4 0.4.5 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 1:0.5.6
  repository.maemo.org/extras/dists/fremantle/free/binary-armel/Packages
    0.5.4

Script is attached.

(I've been asked on IRC to package this into a deb, but knowing my
lazyness and capability of procrastination I thought I'd send a copy to
the list, in case someone else wants to package it first.  I won't mind.
Hint, hint.)

Marius Gedminas
-- 
What goes up, must come down. Ask any system administrator.
#!/usr/bin/python
"""
'whence packagename' tells the user in which repositories the package can be
found.  Useful since Extras, Extras-devel, Extras-testing, and SDK tools
repositories look the same ('repository.maemo.org') in apt-cache policy output.

Copyright (c) 2009 Marius Gedminas <marius@xxxxxxxxx>
Licenced under the GNU GPL v2 or later.
"""

import subprocess, sys, os, re, collections

def main():
    if len(sys.argv) < 2:
        sys.exit('usage: whence pkgname')

    pkgname = sys.argv[1]
    pipe = subprocess.Popen(['apt-cache', 'showpkg', pkgname],
                            stdout=subprocess.PIPE)
    for line in pipe.stdout:
        if line == 'Versions: \n':
            break
    sources = collections.defaultdict(list)
    for line in pipe.stdout:
        if line == 'Reverse Depends: \n':
            break
        if line and not line[0].isspace():
            version = line.split(None, 1)[0]
            for filename in re.findall(r'[(]([^)]+)[)]', line):
                filename = os.path.basename(filename)
                if filename == 'status':
                    filename = 'installed'
                sources[filename].append(version)

    for source, versions in sorted(sources.items()):
        print source.replace('_', '/')
        print ' ', ' '.join(sorted(versions))

if __name__ == '__main__':
    main()

Attachment: signature.asc
Description: Digital signature

_______________________________________________
maemo-users mailing list
maemo-users@xxxxxxxxx
https://lists.maemo.org/mailman/listinfo/maemo-users

[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Big List of Linux Books]    

  Powered by Linux