mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-21 04:56:28 +02:00
[core] Update formatting with quotes for List and Group
If the joinChar is NOT space, we use global quotes. If the joinChar is space, we use quotes per element.
This commit is contained in:
parent
092dcfe722
commit
a35f1c72e2
2 changed files with 24 additions and 11 deletions
|
@ -312,7 +312,7 @@ class Attribute(BaseObject):
|
|||
return Template(self.value).safe_substitute(os.environ)
|
||||
return self.value
|
||||
|
||||
def getValueStr(self):
|
||||
def getValueStr(self, withQuotes=True):
|
||||
'''
|
||||
Return the value formatted as a string with quotes to deal with spaces.
|
||||
If it is a string, expressions will be evaluated.
|
||||
|
@ -325,11 +325,11 @@ class Attribute(BaseObject):
|
|||
# ensure value is a list as expected
|
||||
assert(isinstance(self.value, Sequence) and not isinstance(self.value, str))
|
||||
v = self.attributeDesc.joinChar.join(self.getEvalValue())
|
||||
if v:
|
||||
if withQuotes and v:
|
||||
return '"{}"'.format(v)
|
||||
return v
|
||||
# String, File, single value Choice are based on strings and should includes quotes to deal with spaces
|
||||
if isinstance(self.attributeDesc, (desc.StringParam, desc.File, desc.ChoiceParam)):
|
||||
if withQuotes and isinstance(self.attributeDesc, (desc.StringParam, desc.File, desc.ChoiceParam)):
|
||||
return '"{}"'.format(self.getEvalValue())
|
||||
return str(self.getEvalValue())
|
||||
|
||||
|
@ -513,9 +513,15 @@ class ListAttribute(Attribute):
|
|||
else:
|
||||
return [attr.getPrimitiveValue(exportDefault=exportDefault) for attr in self._value if not attr.isDefault]
|
||||
|
||||
def getValueStr(self):
|
||||
def getValueStr(self, withQuotes=True):
|
||||
assert(isinstance(self.value, ListModel))
|
||||
return self.attributeDesc.joinChar.join([v.getValueStr() for v in self.value])
|
||||
if self.attributeDesc.joinChar == ' ':
|
||||
return self.attributeDesc.joinChar.join([v.getValueStr(withQuotes=True) for v in self.value])
|
||||
else:
|
||||
v = self.attributeDesc.joinChar.join([v.getValueStr(withQuotes=False) for v in self.value])
|
||||
if v:
|
||||
return '"{}"'.format(v)
|
||||
return v
|
||||
|
||||
def updateInternals(self):
|
||||
super(ListAttribute, self).updateInternals()
|
||||
|
@ -631,7 +637,7 @@ class GroupAttribute(Attribute):
|
|||
else:
|
||||
return {name: attr.getPrimitiveValue(exportDefault=exportDefault) for name, attr in self._value.items() if not attr.isDefault}
|
||||
|
||||
def getValueStr(self):
|
||||
def getValueStr(self, withQuotes=True):
|
||||
# add brackets if requested
|
||||
strBegin = ''
|
||||
strEnd = ''
|
||||
|
@ -642,9 +648,16 @@ class GroupAttribute(Attribute):
|
|||
else:
|
||||
raise AttributeError("Incorrect brackets on GroupAttribute: {}".format(self.attributeDesc.brackets))
|
||||
|
||||
# particular case when using space separator
|
||||
spaceSep = self.attributeDesc.joinChar == ' '
|
||||
|
||||
# sort values based on child attributes group description order
|
||||
sortedSubValues = [self._value.get(attr.name).getValueStr() for attr in self.attributeDesc.groupDesc]
|
||||
return strBegin + self.attributeDesc.joinChar.join(sortedSubValues) + strEnd
|
||||
sortedSubValues = [self._value.get(attr.name).getValueStr(withQuotes=spaceSep) for attr in self.attributeDesc.groupDesc]
|
||||
s = self.attributeDesc.joinChar.join(sortedSubValues)
|
||||
|
||||
if withQuotes and not spaceSep:
|
||||
return '"{}{}{}"'.format(strBegin, s, strEnd)
|
||||
return '{}{}{}'.format(strBegin, s, strEnd)
|
||||
|
||||
def updateInternals(self):
|
||||
super(GroupAttribute, self).updateInternals()
|
||||
|
|
|
@ -64,9 +64,9 @@ 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._cmdVars[name + 'Value'] == '"False:3:1.0:0.0"'
|
||||
name = 'fillHoles'
|
||||
assert n3._cmdVars[name + 'Value'] == 'False' # Booleans
|
||||
name = 'noiseFilter'
|
||||
assert n3._cmdVars[name + 'Value'] == 'False:"uniform":0.0:1.0:True'
|
||||
assert n3._cmdVars[name + 'Value'] == '"False:uniform:0.0:1.0:True"'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue