forked from Mirror/pmbootstrap
helpers: drop args from helpers.run functions (MR 2252)
Now we can run commands without needs args available! Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
02f04ba3a8
commit
05c86be11c
42 changed files with 161 additions and 160 deletions
|
@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional, Sequence
|
|||
from pmb.core.types import Env, PathString, PmbArgs
|
||||
|
||||
|
||||
def user(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log", output_return: bool = False,
|
||||
def user(cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log", output_return: bool = False,
|
||||
check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str | int | subprocess.Popen:
|
||||
"""
|
||||
Run a command on the host system as user.
|
||||
|
@ -33,20 +33,20 @@ def user(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] =
|
|||
pmb.helpers.run_core.add_proxy_env_vars(env)
|
||||
if env:
|
||||
cmd_parts = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd_parts, env=env)]
|
||||
return pmb.helpers.run_core.core(args, msg, cmd_parts, working_dir, output,
|
||||
return pmb.helpers.run_core.core(msg, cmd_parts, working_dir, output,
|
||||
output_return, check, sudo)
|
||||
|
||||
# FIXME: should probably use some kind of wrapper class / builder pattern for all these parameters...
|
||||
def user_output(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log",
|
||||
def user_output(cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log",
|
||||
check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str:
|
||||
ret = user(args, cmd, working_dir, output, output_return=True, check=check, env=env, sudo=sudo)
|
||||
ret = user(cmd, working_dir, output, output_return=True, check=check, env=env, sudo=sudo)
|
||||
if not isinstance(ret, str):
|
||||
raise TypeError("Expected str output, got " + str(ret))
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def root(args: PmbArgs, cmd: Sequence[PathString], working_dir=None, output="log", output_return=False,
|
||||
def root(cmd: Sequence[PathString], working_dir=None, output="log", output_return=False,
|
||||
check=None, env={}):
|
||||
"""Run a command on the host system as root, with sudo or doas.
|
||||
|
||||
|
@ -63,5 +63,5 @@ def root(args: PmbArgs, cmd: Sequence[PathString], working_dir=None, output="log
|
|||
cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd, env=env)]
|
||||
cmd = pmb.config.sudo(cmd)
|
||||
|
||||
return user(args, cmd, working_dir, output, output_return, check, env,
|
||||
return user(cmd, working_dir, output, output_return, check, env,
|
||||
True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue