mirror of
https://github.com/lutris/lutris
synced 2024-09-04 15:03:35 +00:00
Uniform the way environment variables are get and set.
This commit is contained in:
parent
c1e38872ef
commit
c6d94add8d
|
@ -295,32 +295,18 @@ class Game(object):
|
|||
"%s" % terminal)
|
||||
self.state = self.STATE_STOPPED
|
||||
return
|
||||
|
||||
# Env vars
|
||||
game_env = gameplay_info.get('env') or {}
|
||||
env.update(game_env)
|
||||
|
||||
system_env = system_config.get('env') or {}
|
||||
env.update(system_env)
|
||||
|
||||
ld_preload = gameplay_info.get('ld_preload') or ''
|
||||
ld_preload = gameplay_info.get('ld_preload')
|
||||
if (ld_preload):
|
||||
env["LD_PRELOAD"] = ld_preload
|
||||
|
||||
dri_prime = system_config.get('dri_prime')
|
||||
if dri_prime:
|
||||
env["DRI_PRIME"] = "1"
|
||||
else:
|
||||
env["DRI_PRIME"] = "0"
|
||||
|
||||
# Runtime management
|
||||
ld_library_path = ""
|
||||
if self.runner.use_runtime():
|
||||
runtime_env = runtime.get_env()
|
||||
if 'STEAM_RUNTIME' in runtime_env and 'STEAM_RUNTIME' not in env:
|
||||
env['STEAM_RUNTIME'] = runtime_env['STEAM_RUNTIME']
|
||||
if 'LD_LIBRARY_PATH' in runtime_env:
|
||||
ld_library_path = runtime_env['LD_LIBRARY_PATH']
|
||||
game_ld_libary_path = gameplay_info.get('ld_library_path')
|
||||
if game_ld_libary_path:
|
||||
ld_library_path = env.get("LD_LIBRARY_PATH")
|
||||
if not ld_library_path:
|
||||
ld_library_path = '$LD_LIBRARY_PATH'
|
||||
ld_library_path = ":".join([game_ld_libary_path, ld_library_path])
|
||||
|
|
|
@ -149,6 +149,39 @@ class Runner:
|
|||
raise ValueError('runner_executable not set for {}'.format(self.name))
|
||||
return os.path.join(settings.RUNNER_DIR, self.runner_executable)
|
||||
|
||||
def get_env(self, os_env=False):
|
||||
env = {}
|
||||
|
||||
if os_env:
|
||||
env.update(os.environ.copy())
|
||||
|
||||
system_env = self.system_config.get('env') or {}
|
||||
env.update(system_env)
|
||||
|
||||
dri_prime = self.system_config.get('dri_prime')
|
||||
if dri_prime:
|
||||
env["DRI_PRIME"] = "1"
|
||||
else:
|
||||
env["DRI_PRIME"] = "0"
|
||||
|
||||
runtime_ld_library_path = None
|
||||
|
||||
if self.use_runtime():
|
||||
runtime_env = runtime.get_env()
|
||||
if 'STEAM_RUNTIME' in runtime_env and 'STEAM_RUNTIME' not in env:
|
||||
env['STEAM_RUNTIME'] = runtime_env['STEAM_RUNTIME']
|
||||
if 'LD_LIBRARY_PATH' in runtime_env:
|
||||
runtime_ld_library_path = runtime_env['LD_LIBRARY_PATH']
|
||||
|
||||
if runtime_ld_library_path:
|
||||
ld_library_path = env.get("LD_LIBRARY_PATH")
|
||||
if not ld_library_path:
|
||||
ld_library_path = '$LD_LIBRARY_PATH'
|
||||
ld_library_path = ":".join([runtime_ld_library_path, ld_library_path])
|
||||
env["LD_LIBRARY_PATH"] = ld_library_path
|
||||
|
||||
return env
|
||||
|
||||
def play(self):
|
||||
"""Dummy method, must be implemented by derived runnners."""
|
||||
raise NotImplementedError("Implement the play method in your runner")
|
||||
|
@ -158,11 +191,7 @@ class Runner:
|
|||
|
||||
Reimplement in derived runner if need be."""
|
||||
exe = self.get_executable()
|
||||
env = {}
|
||||
try:
|
||||
env = self.get_env()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return {'command': [exe], 'env': env}
|
||||
|
||||
|
@ -178,8 +207,6 @@ class Runner:
|
|||
command_data = self.get_run_data()
|
||||
command = command_data.get('command')
|
||||
env = (command_data.get('env') or {}).copy()
|
||||
if self.use_runtime():
|
||||
env.update(runtime.get_env())
|
||||
|
||||
thread = LutrisThread(command, runner=self, env=env, watch=False)
|
||||
thread.start()
|
||||
|
|
|
@ -205,7 +205,7 @@ class steam(Runner):
|
|||
return args
|
||||
|
||||
def get_env(self):
|
||||
env = {}
|
||||
env = super(steam, self).get_env()
|
||||
|
||||
if not self.runner_config.get('lsi_steam') and self.runner_config.get('steam_native_runtime'):
|
||||
env['STEAM_RUNTIME'] = '0'
|
||||
|
|
|
@ -150,11 +150,8 @@ class web(Runner):
|
|||
]
|
||||
runner_executable = 'web/electron/electron'
|
||||
|
||||
def get_env(self, full=True):
|
||||
if full:
|
||||
env = os.environ.copy()
|
||||
else:
|
||||
env = {}
|
||||
def get_env(self, os_env=True):
|
||||
env = super(web, self).get_env(self, os_env)
|
||||
|
||||
env['ENABLE_FLASH_PLAYER'] = '1' if self.runner_config['enable_flash'] else '0'
|
||||
|
||||
|
|
|
@ -900,7 +900,9 @@ class wine(Runner):
|
|||
self.set_regedit_keys()
|
||||
return True
|
||||
|
||||
def get_env(self, full=True):
|
||||
def get_env(self, os_env=True):
|
||||
env = super(wine, self).get_env(os_env)
|
||||
|
||||
if full:
|
||||
env = os.environ.copy()
|
||||
else:
|
||||
|
@ -980,7 +982,7 @@ class wine(Runner):
|
|||
return {'error': 'FILE_NOT_FOUND', 'file': game_exe}
|
||||
|
||||
launch_info = {}
|
||||
launch_info['env'] = self.get_env(full=False)
|
||||
launch_info['env'] = self.get_env(os_env=False)
|
||||
|
||||
if self.runner_config.get('x360ce-path'):
|
||||
self.setup_x360ce(self.runner_config['x360ce-path'])
|
||||
|
|
|
@ -412,14 +412,14 @@ class winesteam(wine.wine):
|
|||
return True
|
||||
|
||||
def get_run_data(self):
|
||||
return {'command': self.launch_args, 'env': self.get_env(full=False)}
|
||||
return {'command': self.launch_args, 'env': self.get_env(os_env=False)}
|
||||
|
||||
def play(self):
|
||||
self.game_launch_time = time.localtime()
|
||||
game_args = self.game_config.get('args') or ''
|
||||
|
||||
launch_info = {}
|
||||
launch_info['env'] = self.get_env(full=False)
|
||||
launch_info['env'] = self.get_env(os_env=False)
|
||||
|
||||
if self.runner_config.get('x360ce-path'):
|
||||
self.setup_x360ce(self.runner_config['x360ce-path'])
|
||||
|
@ -487,7 +487,7 @@ class winesteam(wine.wine):
|
|||
return False
|
||||
appid = appid if appid else self.appid
|
||||
|
||||
env = self.get_env(full=False)
|
||||
env = self.get_env(os_env=False)
|
||||
command = self.launch_args + ['steam://uninstall/%s' % appid]
|
||||
self.prelaunch()
|
||||
thread = LutrisThread(command, runner=self, env=env, watch=False)
|
||||
|
|
Loading…
Reference in a new issue