diff --git a/pmb/chroot/root.py b/pmb/chroot/root.py index 1defcfd5..dbf8b9c6 100644 --- a/pmb/chroot/root.py +++ b/pmb/chroot/root.py @@ -32,7 +32,7 @@ def executables_absolute_path(): """ ret = {} for binary in ["sh", "chroot"]: - path = shutil.which(binary) + path = shutil.which(binary, path=pmb.config.chroot_host_path) if not path: raise RuntimeError("Could not find the '" + binary + "' executable. Make sure, that it is in" " your current user's PATH.") diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 46b02537..ca2cead3 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -75,6 +75,11 @@ chroot_path = ":".join([ "/bin" ]) +# The PATH variable used on the host, to find the "chroot" and "sh" +# executables. As pmbootstrap runs as user, not as root, the location +# for the chroot executable may not be in the PATH (Debian). +chroot_host_path = os.environ["PATH"] + ":/usr/sbin/" + # Folders, that get mounted inside the chroot # $WORK gets replaced with args.work # $ARCH gets replaced with the chroot architecture (eg. x86_64, armhf) diff --git a/pmb/helpers/run.py b/pmb/helpers/run.py index 6bfb97f3..76344158 100644 --- a/pmb/helpers/run.py +++ b/pmb/helpers/run.py @@ -32,20 +32,22 @@ def core(args, cmd, log_message, log, return_stdout, check=True): ret = None if log: if return_stdout: - ret = subprocess.run(cmd, stdout=subprocess.PIPE, - check=check).stdout.decode('utf-8') + ret = subprocess.check_output(cmd).decode("utf-8") args.logfd.write(ret) else: - subprocess.run(cmd, stdout=args.logfd, stderr=args.logfd, - check=check) + subprocess.check_call(cmd, stdout=args.logfd, + stderr=args.logfd) args.logfd.flush() else: logging.debug("*** output passed to pmbootstrap stdout, not" + " to this log ***") - subprocess.run(cmd, check=check) + subprocess.check_call(cmd) except subprocess.CalledProcessError as exc: - raise RuntimeError("Command failed: " + log_message) from exc + if check: + raise RuntimeError("Command failed: " + log_message) from exc + else: + pass return ret diff --git a/test/test_apk_static.py b/test/test_apk_static.py index 7abc52f3..4334e154 100644 --- a/test/test_apk_static.py +++ b/test/test_apk_static.py @@ -30,13 +30,13 @@ import pmb.parse.apkindex @pytest.fixture -def args(): +def args(request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) + return args def test_read_signature_info(tmpdir): diff --git a/test/test_aportgen.py b/test/test_aportgen.py index 545b91aa..43331e73 100644 --- a/test/test_aportgen.py +++ b/test/test_aportgen.py @@ -28,15 +28,15 @@ import pmb.aportgen @pytest.fixture -def args(tmpdir): +def args(tmpdir, request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) setattr(args, "_aports_real", args.aports) args.aports = str(tmpdir) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) + return args def test_aportgen(args): diff --git a/test/test_build.py b/test/test_build.py index f6a111a1..000a8783 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -27,13 +27,13 @@ import pmb.aportgen @pytest.fixture -def args(tmpdir): +def args(tmpdir, request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) + return args def test_build(args): diff --git a/test/test_keys.py b/test/test_keys.py index d3075314..b05d62d0 100644 --- a/test/test_keys.py +++ b/test/test_keys.py @@ -30,13 +30,12 @@ import pmb.helpers.git @pytest.fixture -def args(): +def args(request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) return args diff --git a/test/test_shell_escape.py b/test/test_shell_escape.py index 5c5a454a..342b4439 100644 --- a/test/test_shell_escape.py +++ b/test/test_shell_escape.py @@ -29,13 +29,13 @@ import pmb.chroot.user @pytest.fixture -def args(): +def args(request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) + return args def test_shell_escape(args): diff --git a/test/test_subprocess.py b/test/test_subprocess.py deleted file mode 100644 index 3a26a742..00000000 --- a/test/test_subprocess.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Copyright 2017 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 . -""" -import os -import glob - - -def test_use_pmb_helpers_run_instead_of_subprocess_run(): - src = os.path.abspath(os.path.dirname(__file__) + "/..") - files = glob.glob(src + "/pmb/**/*.py", - recursive=True) + glob.glob(src + "*.py") - okay = os.path.abspath(src + "/pmb/helpers/run.py") - for file in files: - with open(file, "r") as handle: - source = handle.read() - if file != okay and "subprocess.run" in source: - raise RuntimeError("File " + file + " use pmb.helpers.run.user()" - " instead of subprocess.run()!") diff --git a/test/test_version.py b/test/test_version.py index 068dec61..cca921a5 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -28,13 +28,12 @@ import pmb.helpers.git @pytest.fixture -def args(): +def args(request): import pmb.parse sys.argv = ["pmbootstrap.py", "chroot"] args = pmb.parse.arguments() setattr(args, "logfd", open("/dev/null", "a+")) - yield args - args.logfd.close() + request.addfinalizer(args.logfd.close) return args