dimanche 15 septembre 2013

pyalpm : archlinux pacman bindings in python

Wanted to toy with python and pacman. Starting with subprocess calls to `pacman` and ugly string processing. But the google fairy told me I was heading in the wrong direction.

sudo pacman -S pyalpm

5 minutes later, I choke. I can't find a way to instantiate anything. ipython helps navigating modules, 5 more minutes I find a "hack" to get a Handle and then the local package database.

import pyalpm

PATH="/var/lib/pacman"

def init():
    "() -> db"
    h = pyalpm.Handle(PATH,PATH)
    return h.get_localdb()

DB = init()

def installed_pkgs():
    return DB.pkgcache()

In [115]: pkgs = installed_pkgs()

In [116]: pkgs[:10]
Out[116]: 
[<alpm.Package("ghc-7.6.3-1-i686") at 0xb5a1b130>,
 <alpm.Package("qemu-1.5.2-1-i686") at 0xb5a1ce50>,
 <alpm.Package("chromium-29.0.1547.65-1-i686") at 0xb5a18ab0>,
 <alpm.Package("emacs-24.3-4-i686") at 0xb5a18ae0>,
 <alpm.Package("faenza-icon-theme-1.3.1-2-any") at 0xb5a18d40>,
 <alpm.Package("python-3.3.2-2-i686") at 0xb5a1ccb0>,
 <alpm.Package("jre7-openjdk-headless-7.u40_2.4.1-3-i686") at 0xb5a1b8f0>,
 <alpm.Package("gcc-4.8.1-3-i686") at 0xb5a1b080>,
 <alpm.Package("python2-2.7.5-2-i686") at 0xb5a1cd50>,

 <alpm.Package("linux-3.10.10-1-i686") at 0xb5a1c420>]

<yay/>

Aucun commentaire:

Enregistrer un commentaire