diff options
author | Simon McVittie <smcv@debian.org> | 2021-02-10 12:07:56 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2023-03-14 12:37:48 +0000 |
commit | 05a3364e14965eeab04da8fd5e57bb883c162217 (patch) | |
tree | 92f95400669e938edb2fe8f60663cdc8716a56a7 /giscanner/utils.py | |
parent | a15ae089e49c110a4d4e19fac0ab9d135a119e5f (diff) | |
download | gobject-introspection-wip/smcv/search-paths.tar.gz |
Search XDG_DATA_HOME/gir-1.0 for GIR XML toowip/smcv/search-paths
For completeness. There probably won't be any, but the XDG base directory
specification is most useful if it's consistently followed everywhere,
and the specification says to look in XDG_DATA_HOME before XDG_DATA_DIRS.
Signed-off-by: Simon McVittie <smcv@debian.org>
Diffstat (limited to 'giscanner/utils.py')
-rw-r--r-- | giscanner/utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/giscanner/utils.py b/giscanner/utils.py index 31c7ea48..9840143c 100644 --- a/giscanner/utils.py +++ b/giscanner/utils.py @@ -236,6 +236,36 @@ def get_user_cache_dir(dir=None): return None +def get_user_data_dir(): + ''' + This is a Python reimplemention of `g_get_user_data_dir()` because we don't want to + rely on the python-xdg package and we can't depend on GLib via introspection. + If any changes are made to that function they'll need to be copied here. + ''' + + xdg_data_home = os.environ.get('XDG_DATA_HOME') + if xdg_data_home is not None: + try: + os.makedirs(xdg_data_home, mode=0o700, exist_ok=True) + except EnvironmentError: + # Let's fall back to ~/.local/share below + pass + else: + return xdg_data_home + + homedir = os.path.expanduser('~') + if homedir is not None: + datadir = os.path.join(homedir, '.local', 'share') + try: + os.makedirs(datadir, mode=0o700, exist_ok=True) + except EnvironmentError: + return None + else: + return datadir + + return None + + def get_system_data_dirs(): ''' This is a Python reimplemention of `g_get_system_data_dirs()` because we don't want to |