From 8d6bc9c14f64c5598d77a046f90fe2a87f016baf Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 2 Jun 2024 16:08:03 +0200 Subject: [PATCH] fxconv: add new return type convention for custom converters Previously converters had to return: - 0 on success, having called fxconv.elf() themselves - 1 on failure Now they also have the (preferred option) to return: - a bytes or ObjectData on success, without calling fxconv.elf() - None of failure --- fxconv/fxconv.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fxconv/fxconv.py b/fxconv/fxconv.py index a9b2d24..6e8c89b 100644 --- a/fxconv/fxconv.py +++ b/fxconv/fxconv.py @@ -1178,7 +1178,13 @@ def convert(input, params, target, output=None, model=None, custom=None): o = convert_libimg_cg(input, params) elif custom is not None: for converter in custom: - if converter(input, output, params, target) == 0: + rc = converter(input, output, params, target) + # Old convention: 0 on success, 1 on failure + if rc == 0: + return + # New convention: bytes() or ObjectData() on success + if isinstance(rc, bytes) or isinstance(rc, ObjectData): + elf(rc, output, "_" + params["name"], **target) return raise FxconvError(f'unknown custom resource type \'{t}\'') else: