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

This commit is contained in:
Lephenixnoir 2021-12-28 19:01:43 +01:00
parent 4d46661d3b
commit bbf716b031
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

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