Skip to content

Commit

Permalink
fix: normalize result
Browse files Browse the repository at this point in the history
  • Loading branch information
labbbirder committed Jul 21, 2021
1 parent e944d4a commit d5789e7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def Table_String_new(tab,off):
return Table_String(tab,off).decode("utf-8")
Parser.Table.String = Table_String_new

def normalizeResult(result):
if isinstance(result,(str,bytes,unicode)):
return result
if isinstance(result,float):
result = "%f"%result
if "." in result:
return result.rstrip("0").rstrip(".")
return str(result)

def writeFile(text):
global csdPath
Expand Down Expand Up @@ -246,9 +254,7 @@ def getHeaderOption(optionData, optionKey, valuePath, defaultValue="", replaceIn
return ""
parentValue = func()

result = parentValue
if not hasattr(result,"__len__"):
result = str(result).rstrip("0").rstrip(".")
result = normalizeResult(parentValue)

# ignoring field 'LabelText' will lead to a csd file parsing error
if not optionKey in ["LabelText","ButtonText"]:
Expand Down Expand Up @@ -324,14 +330,12 @@ def getChildProperty(optionData, optionKey, valuePath, renameProperty="", specia
text = ' <%s ' %(optionKey)
for funcName in validFuncList:
func = getattr(parentValue, funcName)
result = func()
result = normalizeResult(func())
keyValue = funcName
if funcName in renameDict:
keyValue = renameDict[funcName]
# if isinstance(result, float) and result > 1.1:
# result = int(result)
if not hasattr(result,"__len__"):
result = str(result).rstrip("0").rstrip(".")
text = text + '%s="%s" ' %(keyValue, result)
text = text + "/>\n"
return text
Expand Down

0 comments on commit d5789e7

Please sign in to comment.