38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import logging, os, shutil, tempfile
|
|
import os.path as path
|
|
|
|
from .exec import _exec
|
|
|
|
|
|
class Chroot(object):
|
|
def __init__(self, config, static=False):
|
|
self.config = config
|
|
|
|
# Create directories
|
|
# TODO: add config keys [chroot and clean]
|
|
self.basedir = config.get('chroot.dir')
|
|
logging.debug(f"use directory in {self.basedir}")
|
|
os.makedirs(self.basedir, exist_ok=True)
|
|
|
|
self.rootdir = path.join(self.basedir, "root")
|
|
self.flags = f"-C {path.join(config.dir, 'pacman', 'pacman.conf')} " \
|
|
f"-M {path.join(config.dir, 'pacman', 'makepkg.conf')}"
|
|
|
|
# Initialize base-devel packages
|
|
if not path.exists(self.rootdir):
|
|
logging.info(f"create chroot in {self.rootdir}")
|
|
_exec(f"mkarchroot {self.flags} {self.rootdir} base-devel")
|
|
|
|
# Make sure everything is up-to-date
|
|
_exec(f"arch-nspawn {self.rootdir} pacman -Syu")
|
|
|
|
logging.info(f"chroot ready ({self.rootdir})")
|
|
|
|
def makepkg(self, package, clean=False):
|
|
clean_flag = "-c" if clean else ""
|
|
logging.info(f"build {package.name}" + clean_flag)
|
|
ref_dir = os.getcwd()
|
|
os.chdir(path.join(self.config.get('output'), package.name))
|
|
_exec(f"makechrootpkg {clean_flag} -n -r {self.basedir}")
|
|
os.chdir(ref_dir)
|