[gnome-control-center/wip/hadess/fix-polkit-dep: 1/3] build: Add script to detect files in XDG_DATA_DIRS
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/hadess/fix-polkit-dep: 1/3] build: Add script to detect files in XDG_DATA_DIRS
- Date: Fri, 15 Oct 2021 09:08:28 +0000 (UTC)
commit 0d0226dc2769f126a66ffcf39116f61c815cf05b
Author: Bastien Nocera <hadess hadess net>
Date: Fri Oct 15 10:52:27 2021 +0200
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.
build-aux/meson/find_xdg_file.py | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
---
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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]