Add API to resolve the abs path with your own basedir

This commit is contained in:
2014-12-10 23:04:37 +01:00
parent 25419a42fa
commit 64090436cd

View File

@@ -83,6 +83,21 @@ class FPElem:
# --------
# filepath
def filepath_absolute_resolve(self, basedir=None):
"""
Resolve the filepath, with the option to override the basedir.
"""
filepath = self.filepath
if filepath.startswith(b'//'):
if basedir is None:
basedir = self.basedir
return os.path.normpath(os.path.join(
basedir,
utils.compatpath(filepath[2:]),
))
else:
return utils.compatpath(filepath)
@property
def filepath(self):
return self._get_cb()
@@ -93,14 +108,7 @@ class FPElem:
@property
def filepath_absolute(self):
filepath = self.filepath
if filepath.startswith(b'//'):
return os.path.normpath(os.path.join(
self.basedir,
utils.compatpath(filepath[2:]),
))
else:
return utils.compatpath(filepath)
return self.filepath_absolute_resolve()
class FPElem_block_path(FPElem):