handle format string exceptions separately

This commit is contained in:
Mike Fährmann
2017-08-11 21:48:37 +02:00
parent 3c9f190757
commit ae2d61e5b3
3 changed files with 23 additions and 5 deletions

View File

@@ -183,10 +183,14 @@ class PathFormat():
def set_directory(self, keywords):
"""Build directory path and create it if necessary"""
segments = [
text.clean_path(segment.format_map(keywords).strip())
for segment in self.directory_fmt
]
try:
segments = [
text.clean_path(segment.format_map(keywords).strip())
for segment in self.directory_fmt
]
except Exception as exc:
raise exception.FormatError(exc, "directory")
self.directory = os.path.join(
self.get_base_directory(),
*segments
@@ -209,7 +213,12 @@ class PathFormat():
def build_path(self, sep=os.path.sep):
"""Use filename-keywords and directory to build a full path"""
filename = text.clean_path(self.filename_fmt.format_map(self.keywords))
try:
filename = text.clean_path(
self.filename_fmt.format_map(self.keywords))
except Exception as exc:
raise exception.FormatError(exc, "filename")
self.path = self.directory + sep + filename
self.realpath = self.realdirectory + sep + filename