fxconv: resolve name_regex in the fxconv-metadata.txt API

pull/9/head
Lephenixnoir 9 months ago
parent 4d46661d3b
commit bbf716b031
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
  1. 16
      fxconv/fxconv.py

@ -1178,11 +1178,7 @@ def convert(input, params, target, output=None, model=None, custom=None):
if output is None:
output = os.path.splitext(input)[0] + ".o"
if "name" in params:
pass
elif "name_regex" in params:
params["name"] = re.sub(*params["name_regex"], os.path.basename(input))
else:
if "name" not in params:
raise FxconvError(f"no name specified for conversion '{input}'")
if target["arch"] is None:
@ -1448,7 +1444,8 @@ class Metadata:
def rules_for(self, path):
"""
Returns the parameters that apply to the specified path, or None if no
wildcard matches it.
wildcard matches it. The special key "name_regex" is also resolved into
the regular key "name".
"""
basename = os.path.basename(path)
@ -1460,4 +1457,9 @@ class Metadata:
params.update(**p)
matched = True
return params if matched else None
if not matched:
return None
if "name_regex" in params and not "name" in params:
params["name"] = re.sub(*params["name_regex"], basename)
return params

Loading…
Cancel
Save