[postprocessor:metadata] assume 'mode: custom' when format is set

{"name": "metadata", "format": "foobar"}
will now implicitly use mode:custom and no longer mode:json like before
pull/3028/head
Mike Fährmann 2 years ago
parent f0321f423d
commit b57015cf0a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -20,14 +20,8 @@ class MetadataPP(PostProcessor):
PostProcessor.__init__(self, job)
mode = options.get("mode", "json")
if mode == "custom":
self.write = self._write_custom
cfmt = options.get("content-format") or options.get("format")
if isinstance(cfmt, list):
cfmt = "\n".join(cfmt) + "\n"
self._content_fmt = formatter.parse(cfmt).format_map
ext = "txt"
elif mode == "tags":
cfmt = options.get("content-format") or options.get("format")
if mode == "tags":
self.write = self._write_tags
ext = "txt"
elif mode == "modify":
@ -41,6 +35,12 @@ class MetadataPP(PostProcessor):
self.run = self._run_delete
self.fields = options.get("fields")
ext = None
elif mode == "custom" or cfmt:
self.write = self._write_custom
if isinstance(cfmt, list):
cfmt = "\n".join(cfmt) + "\n"
self._content_fmt = formatter.parse(cfmt).format_map
ext = "txt"
else:
self.write = self._write_json
self.indent = options.get("indent", 4)

@ -267,6 +267,7 @@ class MetadataTest(BasePostprocessorTest):
test({"mode": "custom", "content-format": "{foo}\n{missing}\n"})
test({"mode": "custom", "content-format": ["{foo}", "{missing}"]})
test({"mode": "custom", "format": "{foo}\n{missing}\n"})
test({"format": "{foo}\n{missing}\n"})
def test_metadata_extfmt(self):
pp = self._create({

Loading…
Cancel
Save