diff options
author | Bastien Nocera <hadess@hadess.net> | 2021-10-15 10:52:27 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2021-10-20 14:25:30 +0000 |
commit | 3b7e081ae2decbd0ff5a64023a2a8c0cf2c97d23 (patch) | |
tree | 68b4425738f27e6d007e2df4cf27c490c0054f2a /build-aux | |
parent | 41c613f4b45087626b02c1040d28acb06b265da8 (diff) | |
download | gnome-control-center-3b7e081ae2decbd0ff5a64023a2a8c0cf2c97d23.tar.gz |
build: Add script to detect files in XDG_DATA_DIRS
meson doesn't have support for doing this, so use Python and just the
stdlib to find files under XDG_DATA_DIRS and XDG_DATA_HOME.
Diffstat (limited to 'build-aux')
-rw-r--r-- | build-aux/meson/find_xdg_file.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/build-aux/meson/find_xdg_file.py b/build-aux/meson/find_xdg_file.py new file mode 100644 index 000000000..8e1282319 --- /dev/null +++ b/build-aux/meson/find_xdg_file.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import os +import sys + +def usage(): + print('Usage:') + print('find_xdg_file.py FILENAME') + print('') + print('Looks for FILENAME in the XDG data directories and returns if path if found') + +if len(sys.argv) != 2: + usage() + sys.exit(1) + +filename = sys.argv[1] + +data_home = os.getenv('XDG_DATA_HOME') +if not data_home or data_home == '': + data_home = os.path.join(os.path.expanduser("~"), "local", "share") + +data_dirs_str = os.getenv('XDG_DATA_DIRS') +if not data_dirs_str or data_dirs_str == '': + data_dirs_str = '/usr/local/share/:/usr/share/' + +dirs = [] +dirs += [ data_home ] +for _dir in data_dirs_str.split(':'): + dirs += [ _dir ] + +for _dir in dirs: + full_path = os.path.join(_dir, filename) + if os.path.exists(full_path): + print(full_path) + sys.exit(0) + +print(f"'{filename}' not found in XDG data directories") +sys.exit(1) |