From c5683cbf7d2f52dbf993591cd2959b4b938aac3c Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Fri, 6 Oct 2023 13:31:47 +0100 Subject: [PATCH] improve how we find the run folder --- src/exabgp/environment/base.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/exabgp/environment/base.py b/src/exabgp/environment/base.py index 922a02104..fd3523b5c 100644 --- a/src/exabgp/environment/base.py +++ b/src/exabgp/environment/base.py @@ -1,12 +1,28 @@ import os import sys -APPLICATION = 'exabgp' +def _find_root(): + root = os.environ.get('EXABGP_ROOT', '') + + if not root: + root = os.path.normpath(os.path.dirname(sys.argv[0])) + + if root.endswith('/bin') or root.endswith('/sbin'): + root = os.path.normpath(os.path.join(root, '..')) + + _index = root.find('src/exabgp/application') + if _index: + root = root[:_index] + if root.endswith('/'): + root = root[:-1] + + return root -ROOT = os.environ.get('EXABGP_ROOT', '') -if not ROOT: - ROOT = os.path.normpath(os.path.dirname(sys.argv[0])) -if ROOT.endswith('/bin') or ROOT.endswith('/sbin'): - ROOT = os.path.normpath(os.path.join(ROOT, '..')) + +APPLICATION = 'exabgp' +ROOT = _find_root() ETC = os.path.join(ROOT, 'etc', APPLICATION) ENVFILE = os.path.join(ETC, f'{APPLICATION}.env') + + +