Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
crash with pyalpm-0.10.2-1
#! /usr/bin/env python3
import os
from pathlib import Path
import pycman
import pyalpm
PACCONF = """
[options]
RootDir = /
DBPath = {pacdbpath}
CacheDir = {cachedir}
LogFile = {pacdbpath}
# Use system GPGDir so that we don't have to populate it
GPGDir = /etc/pacman.d/gnupg/
Architecture = {arch}
[core]
Include = /etc/pacman.d/mirrorlist
[extra]
Include = /etc/pacman.d/mirrorlist
[community]
Include = /etc/pacman.d/mirrorlist
[multilib]
Include = /etc/pacman.d/mirrorlist
"""
class ManPagesFinder:
def __init__(self, topdir):
topdir = Path(topdir).resolve()
self.dbpath = topdir / "pacdbpath"
self.cachedir = topdir / "cached_packages"
os.makedirs(self.dbpath, exist_ok=True)
os.makedirs(self.cachedir, exist_ok=True)
self.sync_db = self.init_sync_db(PACCONF, arch="x86_64")
def init_sync_db(self, config, arch):
confpath = self.dbpath / "pacman.conf"
f = open(confpath, "w")
f.write(config.format(pacdbpath=self.dbpath,
cachedir=self.cachedir,
arch=arch))
f.close()
return pycman.config.init_with_config(confpath)
# sync databases like pacman -Sy
def _refresh_sync_db(self, pacdb, force=False):
for db in pacdb.get_syncdbs():
# since this is private pacman database, there is no locking
db.update(force)
# sync all
def refresh(self):
try:
print("Syncing pacman database (x86_64)...")
self._refresh_sync_db(self.sync_db)
except pyalpm.error:
print("Failed to sync pacman database.")
raise
def _download_package(self, pkg):
class Options:
downloadonly = True
nodeps = True
t = pycman.transaction.init_from_options(self.sync_db, Options)
# reset callback functions which print lots of text into the logs
def _void_cb(*args):
pass
self.sync_db.dlcb = _void_cb
self.sync_db.eventcb = _void_cb
self.sync_db.questioncb = _void_cb
self.sync_db.progresscb = _void_cb
t.add_pkg(pkg)
if not pycman.transaction.finalize(t):
raise Exception("Pycman transaction failed: {}".format(t))
finder = ManPagesFinder("__deleteme__")
finder.refresh()
finder._download_package("archlinux-keyring")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment