Skip to content

Commit

Permalink
Extend set_environment
Browse files Browse the repository at this point in the history
Setting e.g. `util.set_environment('SOMEPATH', '/usr/lib/somedir:/usr/lib64/somedir', ':')`
will append given paths to the end of `SOMEPATH` environment variable.
  • Loading branch information
pchome authored Feb 19, 2022
1 parent 24ecb37 commit 3f745c2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions protonfixes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,21 @@ def append_argument(argument):
sys.argv.append(argument)
log.debug('New commandline: ' + str(sys.argv))

def set_environment(envvar, value):
""" Add or override an environment value
def set_environment(envvar, value, separator=None):
""" Add, extend or override an environment value
"""
os_env = value
pm_env = value

log.info('Adding env: ' + envvar + '=' + value)
os.environ[envvar] = value
protonmain.g_session.env[envvar] = value
if separator is not None:
if envvar in os.environ:
os_env = os.environ[envvar] + separator + value
if envvar in protonmain.g_session.env:
pm_env = protonmain.g_session.env[envvar] + separator + value

log.info('Adding env: ' + envvar + '=' + pm_env)
os.environ[envvar] = os_env
protonmain.g_session.env[envvar] = pm_env

def del_environment(envvar):
""" Remove an environment variable
Expand Down

0 comments on commit 3f745c2

Please sign in to comment.