32 lines
1015 B
Python
32 lines
1015 B
Python
import logging, os, tempfile
|
|
import os.path as path
|
|
|
|
|
|
class Chroot(object):
|
|
def __init__(self, config):
|
|
# Create directories
|
|
self.basedir = tempfile.mkdtemp()
|
|
rootdir = path.join(self.basedir, "root")
|
|
logging.info(f"created temporary directory in {self.basedir}")
|
|
|
|
# Initialize base-devel packages
|
|
pacman = f"-C {p}" if (p := config.get('chroot.pacman')) else ""
|
|
makepkg = f"-M {p}" if (p := config.get('chroot.makepkg')) else ""
|
|
_exec(f"mkarchroot {pacman} {makepkg} {rootdir} base-devel")
|
|
|
|
# Make sure everything is up-to-date
|
|
_exec(f"arch-nspawn {rootdir} pacman -Syu")
|
|
|
|
logging.info("chroot initialized")
|
|
|
|
def makepkg(self, package, config):
|
|
current_dir = os.getcwd()
|
|
os.chdir(path.join(config.get('pkgbuilds'), package.name))
|
|
_exec(f"makechrootpkg -c -r {self.basedir}")
|
|
os.chdir(current_dir)
|
|
|
|
def _exec(cmd):
|
|
logging.info(cmd)
|
|
r = os.popen(cmd)
|
|
logging.debug(r.read())
|