Skip to content

Instantly share code, notes, and snippets.

@radupotop
Created November 14, 2024 10:55
Show Gist options
  • Save radupotop/821240916d3b93b2faf28408f1235f37 to your computer and use it in GitHub Desktop.
Save radupotop/821240916d3b93b2faf28408f1235f37 to your computer and use it in GitHub Desktop.
import json
from operator import attrgetter
import pyalpm
handle = pyalpm.Handle("/", "/var/lib/pacman")
db = handle.get_localdb()
getpkgdata = attrgetter("name", "version")
pkgjson = json.dumps([getpkgdata(pkg) for pkg in db.pkgcache])
print(pkgjson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment