[pp:metadata] add 'newline' option (#8439)

* Add configuration setting to control newline characters in metadata.
* update docs/configuration
* introduce 'open()' method
* add 'newline' test
This commit is contained in:
featherbutt
2025-10-21 09:47:39 -07:00
committed by GitHub
parent 3deb5a413d
commit 06e3126bba
3 changed files with 71 additions and 17 deletions

View File

@@ -117,9 +117,15 @@ class MetadataPP(PostProcessor):
self.mtime = options.get("mtime")
self.omode = options.get("open", omode)
self.encoding = options.get("encoding", "utf-8")
self.newline = options.get("newline")
self.skip = options.get("skip", False)
self.meta_path = options.get("metadata-path")
def open(self, path):
return open(path, self.omode,
encoding=self.encoding,
newline=self.newline)
def run(self, pathfmt):
archive = self.archive
if archive and archive.check(pathfmt.kwdict):
@@ -138,11 +144,11 @@ class MetadataPP(PostProcessor):
return
try:
with open(path, self.omode, encoding=self.encoding) as fp:
with self.open(path) as fp:
self.write(fp, pathfmt.kwdict)
except FileNotFoundError:
os.makedirs(directory, exist_ok=True)
with open(path, self.omode, encoding=self.encoding) as fp:
with self.open(path) as fp:
self.write(fp, pathfmt.kwdict)
if archive: