[core] Value need to be exposed without quotes to allow to compose simple expressions

For instance, on the Meshing node "outputMesh" param expression is:
value="{cache}/{nodeType}/{uid0}/mesh.{outputMeshFileTypeValue}",

So the extension here should not contains quotes.
This commit is contained in:
Fabien Castan 2024-02-02 19:47:52 +01:00
parent a35f1c72e2
commit c6d0933d4f
3 changed files with 24 additions and 17 deletions

View file

@ -516,10 +516,10 @@ class ListAttribute(Attribute):
def getValueStr(self, withQuotes=True):
assert(isinstance(self.value, ListModel))
if self.attributeDesc.joinChar == ' ':
return self.attributeDesc.joinChar.join([v.getValueStr(withQuotes=True) for v in self.value])
return self.attributeDesc.joinChar.join([v.getValueStr(withQuotes=withQuotes) for v in self.value])
else:
v = self.attributeDesc.joinChar.join([v.getValueStr(withQuotes=False) for v in self.value])
if v:
if withQuotes and v:
return '"{}"'.format(v)
return v

View file

@ -709,9 +709,10 @@ class BaseNode(BaseObject):
group = attr.attributeDesc.group(attr.node) if isinstance(attr.attributeDesc.group, types.FunctionType) else attr.attributeDesc.group
if group is not None:
# if there is a valid command line "group"
v = attr.getValueStr()
v = attr.getValueStr(withQuotes=True)
cmdVars[name] = '--{name} {value}'.format(name=name, value=v)
cmdVars[name + 'Value'] = v
# xxValue is exposed without quotes to allow to compose expressions
cmdVars[name + 'Value'] = attr.getValueStr(withQuotes=False)
# List elements may give a fully empty string and will not be sent to the command line.
# String attributes will return only quotes if it is empty and thus will be send to the command line.
@ -763,10 +764,11 @@ class BaseNode(BaseObject):
except ValueError as e:
logging.warning('Invalid expression value on "{nodeName}.{attrName}" with value "{defaultValue}".\nError: {err}'.format(nodeName=self.name, attrName=attr.name, defaultValue=defaultValue, err=str(e)))
v = attr.getValueStr()
v = attr.getValueStr(withQuotes=True)
self._cmdVars[name] = '--{name} {value}'.format(name=name, value=v)
self._cmdVars[name + 'Value'] = v
# xxValue is exposed without quotes to allow to compose expressions
self._cmdVars[name + 'Value'] = attr.getValueStr(withQuotes=False)
if v:
self._cmdVars[attr.attributeDesc.group] = self._cmdVars.get(attr.attributeDesc.group, '') + \

View file

@ -29,34 +29,37 @@ def test_formatting_listOfFiles():
n1.featuresFolders.resetValue()
assert n1.featuresFolders.getValueStr() == ''
value = '"/non/existing/fileA" "/non/existing/with space/fileB"'
n1.featuresFolders.extend(inputImages)
assert n1.featuresFolders.getValueStr() == value
assert n1.featuresFolders.getValueStr() == '"/non/existing/fileA" "/non/existing/with space/fileB"'
n1._buildCmdVars() # prepare vars for command line creation
# and check some values
name = 'featuresFolders'
assert n1._cmdVars[name + 'Value'] == value
assert n1._cmdVars[name + 'Value'] == '/non/existing/fileA /non/existing/with space/fileB'
def test_formatting_strings():
graph = Graph('')
n1 = graph.addNewNode('ImageMatching')
name = 'weights'
assert n1._cmdVars[name + 'Value'] == '""' # Empty string should generate empty quotes
assert n1.weights.getValueStr() == '""' # Empty string should generate empty quotes
assert n1._cmdVars[name + 'Value'] == ''
name = 'method'
assert n1._cmdVars[name + 'Value'] == '"SequentialAndVocabularyTree"'
assert n1.method.getValueStr() == '"SequentialAndVocabularyTree"'
assert n1._cmdVars[name + 'Value'] == 'SequentialAndVocabularyTree'
n2 = graph.addNewNode('ImageMatching')
n2._buildCmdVars() # prepare vars for command line creation
name = 'featuresFolders'
assert n2._cmdVars[name + 'Value'] == '' # Empty list should become fully empty
assert n2._cmdVars[name + 'Value'] == '', 'Empty list should become fully empty'
n2.featuresFolders.extend('')
n2._buildCmdVars() # prepare vars for command line creation
assert n2._cmdVars[name + 'Value'] == '""' # A list with one empty string should generate empty quotes
assert n2.featuresFolders.getValueStr() == '""', 'A list with one empty string should generate empty quotes'
assert n2._cmdVars[name + 'Value'] == '', 'The Value is always only the value, so empty here'
n2.featuresFolders.extend('')
n2._buildCmdVars() # prepare vars for command line creation
assert n2._cmdVars[name + 'Value'] == '"" ""' # A list with 2 empty strings should generate quotes
assert n2.featuresFolders.getValueStr() == '"" ""', 'A list with 2 empty strings should generate quotes'
assert n2._cmdVars[name + 'Value'] == ' ', 'The Value is always only the value, so 2 empty with the space separator in the middle'
def test_formatting_groups():
@ -64,9 +67,11 @@ def test_formatting_groups():
n3 = graph.addNewNode('ImageProcessing')
n3._buildCmdVars() # prepare vars for command line creation
name = 'sharpenFilter'
assert n3._cmdVars[name + 'Value'] == '"False:3:1.0:0.0"'
assert n3.sharpenFilter.getValueStr() == '"False:3:1.0:0.0"'
assert n3._cmdVars[name + 'Value'] == 'False:3:1.0:0.0', 'The Value is always only the value, so no quotes'
name = 'fillHoles'
assert n3._cmdVars[name + 'Value'] == 'False' # Booleans
assert n3._cmdVars[name + 'Value'] == 'False', 'Booleans'
name = 'noiseFilter'
assert n3._cmdVars[name + 'Value'] == '"False:uniform:0.0:1.0:True"'
assert n3.noiseFilter.getValueStr() == '"False:uniform:0.0:1.0:True"'
assert n3._cmdVars[name + 'Value'] == 'False:uniform:0.0:1.0:True'