[postprocessor:metadata] add 'open' and 'encoding' options

This commit is contained in:
Mike Fährmann
2022-11-07 15:37:22 +01:00
parent 93e6bd6847
commit 895f36e53b
2 changed files with 37 additions and 5 deletions

View File

@@ -97,6 +97,8 @@ class MetadataPP(PostProcessor):
self.archive = None
self.mtime = options.get("mtime")
self.omode = options.get("open", "w")
self.encoding = options.get("encoding", "utf-8")
def run(self, pathfmt):
archive = self.archive
@@ -107,11 +109,11 @@ class MetadataPP(PostProcessor):
path = directory + self._filename(pathfmt)
try:
with open(path, "w", encoding="utf-8") as fp:
with open(path, self.omode, encoding=self.encoding) as fp:
self.write(fp, pathfmt.kwdict)
except FileNotFoundError:
os.makedirs(directory, exist_ok=True)
with open(path, "w", encoding="utf-8") as fp:
with open(path, self.omode, encoding=self.encoding) as fp:
self.write(fp, pathfmt.kwdict)
if archive: