Add initial commit outlining scale-build python structure

This commit is contained in:
Waqar Ahmed
2021-04-13 02:39:07 +05:00
committed by Waqar Ahmed
parent 28d1d5f7b4
commit 6c65ed66f5
12 changed files with 204 additions and 0 deletions

57
scale_build/preflight.py Normal file
View File

@@ -0,0 +1,57 @@
import logging
import os
import shutil
from .exceptions import CallError, MissingPackagesException
from .utils.manifest import get_manifest
from .utils.system import has_low_ram
from .utils.variables import TMP_DIR, HASH_DIR, LOG_DIR, PKG_DIR
logger = logging.getLogger(__name__)
WANTED_PACKAGES = {
'make',
'debootstrap',
'git',
'xorriso',
'grub-mkrescue',
'mksquashfs',
'unzip',
}
def is_root():
return os.geteuid() == 0
def retrieve_missing_packages():
missing = {pkg for pkg in WANTED_PACKAGES if not shutil.which(pkg)}
if not os.path.exists('/lib/grub/x86_64-efi') and not os.path.exists('/usr/lib/grub/x86_64-efi'):
missing.add('grub-efi-amd64-bin')
if not os.path.exists('/lib/grub/i386-pc') and not os.path.exists('/usr/lib/grub/i386-pc'):
missing.add('grub-pc-bin')
return missing
def setup_dirs():
for d in (TMP_DIR, HASH_DIR, LOG_DIR, PKG_DIR):
os.makedirs(d, exist_ok=True)
def preflight_check():
# TODO: Please see how we should delete overlayfs/bootstrapdir when exceptions are raised
if not is_root():
raise CallError('Must be run as root (or using sudo)!')
missing_packages = retrieve_missing_packages()
if missing_packages:
raise MissingPackagesException(missing_packages)
if has_low_ram():
logging.warning('WARNING: Running with less than 16GB of memory. Build may fail...')
setup_dirs()
get_manifest()