Fix add_attribute insertion logic

The code didn't work if it couldn't find a property in the file
that is lexicographically greater than the new attribute.
It now accepts _identity as an "end point" to insert before, and
empty lines in _initAttributes() and _useAttributes(), as they mark
the end of the method.

Also add "float" as a possible type, mainly for the "score" attribute
in search results.
This commit is contained in:
Thialfihar
2014-02-08 21:06:43 +01:00
parent 59e92f89bd
commit 6ef3a0220f
+10 -7
View File
@@ -35,6 +35,7 @@ types = {
"string": ("string", "(str, unicode)", "attributes[\"" + attributeName + "\"]"),
"int": ("integer", "(int, long)", "attributes[\"" + attributeName + "\"]"),
"bool": ("bool", "bool", "attributes[\"" + attributeName + "\"]"),
"float": ("float", "float", "attributes[\"" + attributeName + "\"]"),
"datetime": ("datetime.datetime", "(str, unicode)", "self._parseDatetime(attributes[\"" + attributeName + "\"])"),
}
@@ -61,7 +62,7 @@ while not added:
if line.startswith(" def "):
if isProperty:
attrName = line[8:-7]
if attrName != "_identity" and attrName > attributeName:
if attrName == "_identity" or attrName > attributeName:
newLines.append(" def " + attributeName + "(self):")
newLines.append(" \"\"\"")
newLines.append(" :type: " + attributeDocType)
@@ -83,9 +84,10 @@ while not added:
if line == " def _initAttributes(self):":
inInit = True
if inInit:
if line.endswith(" = github.GithubObject.NotSet"):
attrName = line[14:-29]
if attrName > attributeName:
if not line or line.endswith(" = github.GithubObject.NotSet"):
if line:
attrName = line[14:-29]
if not line or attrName > attributeName:
newLines.append(" self._" + attributeName + " = github.GithubObject.NotSet")
added = True
newLines.append(line)
@@ -99,9 +101,10 @@ while not added:
if line == " def _useAttributes(self, attributes):":
inUse = True
if inUse:
if line.endswith(" in attributes: # pragma no branch"):
attrName = line[12:-36]
if attrName > attributeName:
if not line or line.endswith(" in attributes: # pragma no branch"):
if line:
attrName = line[12:-36]
if not line or attrName > attributeName:
newLines.append(" if \"" + attributeName + "\" in attributes: # pragma no branch")
newLines.append(" assert attributes[\"" + attributeName + "\"] is None or isinstance(attributes[\"" + attributeName + "\"], " + attributeAssertType + "), attributes[\"" + attributeName + "\"]")
newLines.append(" self._" + attributeName + " = " + attributeValue)