util: add canon_path()

We need a common definition for canonicalizing paths; the lack of one
is causing issues on Windows.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Marti 2019-05-15 11:29:27 -06:00 committed by Carles Cufí
parent 3f81eb4195
commit c20abf8868
1 changed files with 11 additions and 0 deletions

View File

@ -42,6 +42,17 @@ import textwrap
import yaml
def canon_path(path):
'''Returns a canonical version of the path.
This is currently ``os.path.normcase(os.path.abspath(path))``. The
path separator is converted to os.sep on platforms where that
matters (Windows).
:param path: path whose canonical name to return; need not
refer to an existing file.
'''
return os.path.normcase(os.path.abspath(path))
def escapes_directory(path, directory):
'''Returns True if `path` escapes parent directory `directory`.