pmbootstrap init: check for required programs (!1845)

Prepare to require "git" in a follow-up patch.
This commit is contained in:
Oliver Smith 2019-12-22 10:58:36 +01:00
parent 3f2a064993
commit b1cb662645
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
3 changed files with 59 additions and 0 deletions

View File

@ -47,6 +47,11 @@ pmaports_min_version = "4"
# see migrate_work_folder()).
work_version = 3
# Programs that pmbootstrap expects to be available from the host system. Keep
# in sync with README.md, and try to keep the list as small as possible. The
# idea is to run almost everything in Alpine chroots.
required_programs = ["openssl", "ps"]
# Keys saved in the config file (mostly what we ask in 'pmbootstrap init')
config_keys = ["ccache_size", "device", "extra_packages", "hostname", "jobs",
"kernel", "keymap", "nonfree_firmware", "nonfree_userland",

View File

@ -19,6 +19,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
import logging
import glob
import os
import shutil
import pmb.config
import pmb.config.pmaports
@ -32,6 +33,17 @@ import pmb.parse.deviceinfo
import pmb.parse._apkbuild
def require_programs():
missing = []
for program in pmb.config.required_programs:
if not shutil.which(program):
missing.append(program)
if missing:
raise RuntimeError("Can't find all programs required to run"
" pmbootstrap. Please install first: " +
", ".join(missing))
def ask_for_work_path(args):
"""
Ask for the work path, until we can create it (when it does not exist) and
@ -345,6 +357,8 @@ def ask_for_ssh_keys(args):
def frontend(args):
require_programs()
# Work folder (needs to be first, so we can create chroots early)
cfg = pmb.config.load(args)
work, work_exists = ask_for_work_path(args)

40
test/test_config_init.py Normal file
View File

@ -0,0 +1,40 @@
"""
Copyright 2019 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import pytest
import sys
# Import from parent directory
sys.path.insert(0, os.path.realpath(
os.path.join(os.path.dirname(__file__) + "/..")))
import pmb.config.init
def test_require_programs(monkeypatch):
func = pmb.config.init.require_programs
# Nothing missing
func()
# Missing program
invalid = "invalid-program-name-here-asdf"
monkeypatch.setattr(pmb.config, "required_programs", [invalid])
with pytest.raises(RuntimeError) as e:
func()
assert str(e.value).startswith("Can't find all programs")