lib.ExecContext.run(), .sudo(): Rename env
The name of the env parameter to ExecContext.run() and .sudo() is not descriptive enough for which environment is supposed to be modified and how, so rename and split it up as follows: - .run(): env -> mod_env - .sudo(): env -> mod_env_sudo and mod_env_cmd The parameters have the following meaning: - "mod_env*" means that the environment is modified, not replaced - "mod_env" and "mod_env_cmd" modify the environment "cmd" runs in - "mod_env_sudo" modifies the environment sudo runs in Fix the fallout of the API change all over jw-pkg. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
9f756222fe
commit
54aecff8e4
9 changed files with 164 additions and 159 deletions
|
|
@ -161,16 +161,16 @@ async def get_profile_env(throw: bool=True, keep: Iterable[str]|bool=False, ec:
|
|||
Returns:
|
||||
Dictionary with fresh environment
|
||||
"""
|
||||
env: dict[str,str]|None = None
|
||||
mod_env: dict[str,str]|None = None
|
||||
if keep == False or isinstance(keep, Iterable):
|
||||
env = {
|
||||
mod_env = {
|
||||
'HOME': os.environ.get('HOME', '/'),
|
||||
'USER': os.environ.get('USER', ''),
|
||||
'PATH': '/usr/bin:/bin',
|
||||
}
|
||||
# Run bash as a login shell, which sources /etc/profile, then print environment as NUL-separated key=value pairs
|
||||
cmd = ['/usr/bin/env', '-i', '/bin/bash', '-lc', 'env -0']
|
||||
result = await run_cmd(cmd, throw=throw, verbose=True, env=env, ec=ec)
|
||||
result = await run_cmd(cmd, throw=throw, verbose=True, mod_env=mod_env, ec=ec)
|
||||
ret: dict[str, str] = {}
|
||||
for entry in result.stdout.rstrip(b"\0").split(b"\0"):
|
||||
if not entry:
|
||||
|
|
|
|||
Loading…
Reference in a new issue