|
92 | 92 | APP_GENEWEB = "application/x-geneweb"
|
93 | 93 | APP_VCARD = ["text/x-vcard", "text/x-vcalendar"]
|
94 | 94 |
|
| 95 | + |
95 | 96 | # -------------------------------------------------------------------------
|
96 | 97 | #
|
97 | 98 | # Determine the user data and user configuration directories.
|
98 | 99 | #
|
99 | 100 | # -------------------------------------------------------------------------
|
| 101 | +def _glib_get_home_dir() -> str: |
| 102 | + return GLib.get_home_dir() |
| 103 | + |
| 104 | + |
| 105 | +def _glib_get_user_cache_dir() -> str: |
| 106 | + if "XDG_CACHE_HOME" in os.environ and os.environ["XDG_CACHE_HOME"]: |
| 107 | + return os.environ["XDG_CACHE_HOME"] |
| 108 | + cache_dir = get_special_folder_internet_cache() |
| 109 | + if cache_dir: |
| 110 | + return cache_dir |
| 111 | + return os.path.join(_glib_get_home_dir(), ".cache") |
| 112 | + |
| 113 | + |
| 114 | +def _glib_get_user_config_dir() -> str: |
| 115 | + if "XDG_CONFIG_HOME" in os.environ and os.environ["XDG_CONFIG_HOME"]: |
| 116 | + return os.environ["XDG_CONFIG_HOME"] |
| 117 | + config_dir = get_special_folder_local_app_data() |
| 118 | + if config_dir: |
| 119 | + return config_dir |
| 120 | + return os.path.join(_glib_get_home_dir(), ".config") |
| 121 | + |
| 122 | + |
| 123 | +def _glib_get_user_data_dir() -> str: |
| 124 | + if "XDG_DATA_HOME" in os.environ and os.environ["XDG_DATA_HOME"]: |
| 125 | + return os.environ["XDG_DATA_HOME"] |
| 126 | + data_dir = get_special_folder_local_app_data() |
| 127 | + if data_dir: |
| 128 | + return data_dir |
| 129 | + return os.path.join(_glib_get_home_dir(), ".local", "share") |
| 130 | + |
| 131 | + |
100 | 132 | if "GRAMPSHOME" in os.environ:
|
101 | 133 | USER_HOME = get_env_var("GRAMPSHOME")
|
102 | 134 | USER_DATA = os.path.join(USER_HOME, "gramps")
|
|
117 | 149 | shutil.move(OLD_HOME, USER_DATA)
|
118 | 150 | else:
|
119 | 151 | USER_HOME = get_env_var("HOME")
|
120 |
| - USER_DATA = os.path.join(GLib.get_user_data_dir(), "gramps") |
121 |
| - USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps") |
| 152 | + USER_DATA = os.path.join(_glib_get_user_data_dir(), "gramps") |
| 153 | + USER_CONFIG = os.path.join(_glib_get_user_config_dir(), "gramps") |
122 | 154 | # Copy the database directory into the XDG directory.
|
123 | 155 | OLD_HOME = os.path.join(USER_HOME, ".gramps")
|
124 | 156 | if os.path.exists(OLD_HOME):
|
|
129 | 161 | if os.path.exists(db_dir):
|
130 | 162 | shutil.copytree(db_dir, os.path.join(USER_DATA, "grampsdb"))
|
131 | 163 |
|
132 |
| -USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps") |
| 164 | +USER_CACHE = os.path.join(_glib_get_user_cache_dir(), "gramps") |
133 | 165 |
|
134 | 166 | if "SAFEMODE" in os.environ:
|
135 | 167 | USER_CONFIG = get_env_var("SAFEMODE")
|
|
0 commit comments