|
12 | 12 | import tempfile
|
13 | 13 | import threading
|
14 | 14 | import time
|
| 15 | +from pathlib import Path |
15 | 16 | from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar
|
16 | 17 |
|
17 | 18 | from core import constants, utils
|
@@ -997,28 +998,26 @@ def get_environment(self, state: bool = True) -> Dict[str, str]:
|
997 | 998 | env["SESSION_USER"] = str(self.user)
|
998 | 999 | if state:
|
999 | 1000 | env["SESSION_STATE"] = str(self.state)
|
1000 |
| - # attempt to read and add environment config file |
1001 |
| - environment_config_file = os.path.join(constants.CORE_CONF_DIR, "environment") |
1002 |
| - try: |
1003 |
| - if os.path.isfile(environment_config_file): |
1004 |
| - utils.load_config(environment_config_file, env) |
1005 |
| - except IOError: |
1006 |
| - logging.warning( |
1007 |
| - "environment configuration file does not exist: %s", |
1008 |
| - environment_config_file, |
1009 |
| - ) |
1010 |
| - # attempt to read and add user environment file |
| 1001 | + # try reading and merging optional environments from: |
| 1002 | + # /etc/core/environment |
| 1003 | + # /home/user/.core/environment |
| 1004 | + # /tmp/pycore.<session id>/environment |
| 1005 | + core_env_path = Path(constants.CORE_CONF_DIR) / "environment" |
| 1006 | + session_env_path = Path(self.session_dir) / "environment" |
1011 | 1007 | if self.user:
|
1012 |
| - environment_user_file = os.path.join( |
1013 |
| - "/home", self.user, ".core", "environment" |
1014 |
| - ) |
1015 |
| - try: |
1016 |
| - utils.load_config(environment_user_file, env) |
1017 |
| - except IOError: |
1018 |
| - logging.debug( |
1019 |
| - "user core environment settings file not present: %s", |
1020 |
| - environment_user_file, |
1021 |
| - ) |
| 1008 | + user_home_path = Path(f"~{self.user}").expanduser() |
| 1009 | + user_env1 = user_home_path / ".core" / "environment" |
| 1010 | + user_env2 = user_home_path / ".coregui" / "environment" |
| 1011 | + paths = [core_env_path, user_env1, user_env2, session_env_path] |
| 1012 | + else: |
| 1013 | + paths = [core_env_path, session_env_path] |
| 1014 | + for path in paths: |
| 1015 | + if path.is_file(): |
| 1016 | + try: |
| 1017 | + logging.info("loading environment config: %s", path) |
| 1018 | + utils.load_config(path, env) |
| 1019 | + except IOError: |
| 1020 | + logging.exception("error reading environment file: %s", path) |
1022 | 1021 | return env
|
1023 | 1022 |
|
1024 | 1023 | def set_thumbnail(self, thumb_file: str) -> None:
|
|
0 commit comments