Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Int substitution in recipe Args #896

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions Code/autopkglib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,23 @@ def getdata(match):
"""Returns data from a match object"""
return a_dict[match.group("key")]

def getdata_str(match):
"""Returns string data from a match object"""
return str(a_dict[match.group("key")])

def do_variable_substitution(item):
"""Do variable substitution for item"""
if isinstance(item, str):
try:
item = RE_KEYREF.sub(getdata, item)
except KeyError as err:
log_err(f"Use of undefined key in variable substitution: {err}")
except TypeError as err:
if "sequence item 0: expected str instance, int found" in str(err):
log(f"WARNING: subtituting int for string: {err}")
item = RE_KEYREF.sub(getdata_str, item)
else:
raise err
elif isinstance(item, (list, NSArray)):
for index in range(len(item)):
item[index] = do_variable_substitution(item[index])
Expand Down