[docs]defgetPathEnv(varName):""" Gets a path from env var 'varName' and normalizes it e.g. removes trailing slashes. This removes some cases from the rest of the code. """varContent=getEnv(varName)returnos.path.normpath(varContent)ifvarContentelseNone
[docs]defisDescendant(base,path):""" Is 'path' is a descendant of 'base'? """returnos.path.commonprefix([base,path])==base
[docs]defvalidatePath(path):ifnotisDescendant(HOST_BASE_PATH,path):raiseInvalidHostPath(f"'{path}' is not a descendant of 'HOST_BASE_PATH' ({HOST_BASE_PATH})")