Added the functionality to let the @set command accept simple lists and dicts (relevant for @batch building)
This commit is contained in:
parent
27809694d7
commit
973f606f3f
1 changed files with 16 additions and 1 deletions
|
|
@ -1112,7 +1112,10 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
Sets attributes on objects. The second form clears
|
Sets attributes on objects. The second form clears
|
||||||
a previously set attribute while the last form
|
a previously set attribute while the last form
|
||||||
inspects the current value of the attribute
|
inspects the current value of the attribute
|
||||||
(if any).
|
(if any). You can also set lists [...] and dicts {...}
|
||||||
|
on attributes with @set (but not nested combinations). Also
|
||||||
|
note that such lists/dicts will always hold strings (never numbers).
|
||||||
|
Use @py if you need to set arbitrary lists and dicts.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "@set"
|
key = "@set"
|
||||||
|
|
@ -1156,6 +1159,18 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
string += "\n%s has no attribute '%s'." % (obj.name, attr)
|
string += "\n%s has no attribute '%s'." % (obj.name, attr)
|
||||||
else:
|
else:
|
||||||
# setting attribute(s)
|
# setting attribute(s)
|
||||||
|
|
||||||
|
# analyze if we are trying to set a list or a dict.
|
||||||
|
if value.startswith('[') and value.endswith(']'):
|
||||||
|
value = value.lstrip('[').rstrip(']').split(',')
|
||||||
|
value = [utils.to_str(val) for val in value]
|
||||||
|
elif value.startswith('{') and value.endswith('}') and ':' in value:
|
||||||
|
dictpairs = value.lstrip('{').rstrip('}').split(',')
|
||||||
|
try:
|
||||||
|
value = dict([[utils.to_str(p.strip()) for p in pair.split(':')] for pair in dictpairs])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
obj.set_attribute(attr, value)
|
obj.set_attribute(attr, value)
|
||||||
string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value)
|
string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue