From 65b71872aad027a129cd9682cc9c299997b2060c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 21 Nov 2020 17:49:28 +0200 Subject: Probe several locations for configuration file --- scripts/gen-default-cfg.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'scripts/gen-default-cfg.py') diff --git a/scripts/gen-default-cfg.py b/scripts/gen-default-cfg.py index c27b482..afcaed2 100755 --- a/scripts/gen-default-cfg.py +++ b/scripts/gen-default-cfg.py @@ -26,6 +26,27 @@ def writeItem(node, file): node = node.next +def writeConfigPaths(file): + # -1: invalid + # 0: $HOME + # 1: $XDG_CONFIG_HOME + + locations = [ + "$HOME/.poirc", + "$XDG_CONFIG_HOME/smolbote.conf", + "$XDG_CONFIG_HOME/smolbote/config", + "$HOME/.config/smolbote.conf", + "$HOME/.config/smolbote/config", + "/etc/smolbote/config"] + + for item in locations: + if item.startswith("$HOME/"): + print('\t\tstd::make_pair(0, "{}"),'.format(item[len("$HOME/"):]), file=file) + elif item.startswith("$XDG_CONFIG_HOME/"): + print('\t\tstd::make_pair(1, "{}"),'.format(item[len("$XDG_CONFIG_HOME/"):]), file=file) + else: + print('\t\tstd::make_pair(-1, "{}"),'.format(item), file=file) + if __name__ == "__main__": parser = argparse.ArgumentParser() @@ -47,5 +68,7 @@ if __name__ == "__main__": for line in args.input: if "@__DEFAULT_CFG__" in line: writeItem(kconf.top_node.list, file=args.output) + elif "@__CONFIG_PATHS__" in line: + writeConfigPaths(file=args.output) else: print(line, end='', file=args.output) -- cgit v1.2.1