[PATCH] osmo-gsm-tester[master]: config: resolve real paths from symlinks, add paths debug lo...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu May 4 14:42:33 UTC 2017


Review at  https://gerrit.osmocom.org/2476

config: resolve real paths from symlinks, add paths debug logging

Change-Id: I11a905b2467cda691d9ccea30ae436bac96476c9
---
M src/osmo_gsm_tester/config.py
1 file changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/76/2476/1

diff --git a/src/osmo_gsm_tester/config.py b/src/osmo_gsm_tester/config.py
index 4abdebb..b3f45fc 100644
--- a/src/osmo_gsm_tester/config.py
+++ b/src/osmo_gsm_tester/config.py
@@ -88,9 +88,11 @@
         locations = DEFAULT_CONFIG_LOCATIONS
 
     for l in locations:
-        p = os.path.join(l, basename)
+        real_l = os.path.realpath(l)
+        p = os.path.realpath(os.path.join(real_l, basename))
         if os.path.isfile(p):
-            return (p, l)
+            log.dbg(None, log.C_CNF, 'Found config file', basename, 'as', p, 'in', l, 'which is', real_l)
+            return (p, real_l)
     if not fail_if_missing:
         return None, None
     raise RuntimeError('configuration file not found: %r in %r' % (basename,
@@ -115,20 +117,25 @@
     env_name = ENV_PREFIX + label.upper()
     env_path = os.getenv(env_name)
     if env_path:
-        return env_path
+        real_env_path = os.path.realpath(env_path)
+        log.dbg(None, log.C_CNF, 'Found path', label, 'as', env_path, 'in', '$' + env_name, 'which is', real_env_path)
+        return real_env_path
 
     if PATHS is None:
         paths_file, found_in = _get_config_file(PATHS_CONF)
         PATHS = read(paths_file, PATHS_SCHEMA)
         for key, path in PATHS.items():
             if not path.startswith(os.pathsep):
-                PATHS[key] = os.path.join(found_in, path)
+                PATHS[key] = os.path.realpath(os.path.join(found_in, path))
+                log.dbg(None, log.C_CNF, paths_file + ': relative path', path, 'is', PATHS[key])
     p = PATHS.get(label)
     if p is None and not allow_unset:
         raise RuntimeError('missing configuration in %s: %r' % (PATHS_CONF, label))
 
+    log.dbg(None, log.C_CNF, 'Found path', label, 'as', p)
     if p.startswith(PATHS_TEMPDIR_STR):
         p = os.path.join(get_tempdir(), p[len(PATHS_TEMPDIR_STR):])
+        log.dbg(None, log.C_CNF, 'Path', label, 'contained', PATHS_TEMPDIR_STR, 'and becomes', p)
     return p
 
 def get_state_dir():

-- 
To view, visit https://gerrit.osmocom.org/2476
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11a905b2467cda691d9ccea30ae436bac96476c9
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list