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.
This commit is contained in:
parent
41c613f4b4
commit
3b7e081ae2
1 changed files with 38 additions and 0 deletions
38
build-aux/meson/find_xdg_file.py
Normal file
38
build-aux/meson/find_xdg_file.py
Normal file
|
@ -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)
|
Loading…
Add table
Reference in a new issue