This commit is contained in:
Wan Liuyang
2020-02-12 02:01:58 +08:00
parent d6dee0164a
commit f8bf46f82b
3 changed files with 69 additions and 17 deletions
+59 -13
View File
@@ -39,11 +39,35 @@ else:
types = {
"string": ("string", None, "self._makeStringAttribute(attributes[\"" + attributeName + "\"])"),
"int": ("integer", None, "self._makeIntAttribute(attributes[\"" + attributeName + "\"])"),
"bool": ("bool", None, "self._makeBoolAttribute(attributes[\"" + attributeName + "\"])"),
"datetime": ("datetime.datetime", "(str, unicode)", "self._makeDatetimeAttribute(attributes[\"" + attributeName + "\"])"),
"class": (":class:`" + attributeClassType + "`", None, "self._makeClassAttribute(" + attributeClassType + ", attributes[\"" + attributeName + "\"])"),
"string": (
"string",
None,
'self._makeStringAttribute(attributes["' + attributeName + '"])',
),
"int": (
"integer",
None,
'self._makeIntAttribute(attributes["' + attributeName + '"])',
),
"bool": (
"bool",
None,
'self._makeBoolAttribute(attributes["' + attributeName + '"])',
),
"datetime": (
"datetime.datetime",
"(str, unicode)",
'self._makeDatetimeAttribute(attributes["' + attributeName + '"])',
),
"class": (
":class:`" + attributeClassType + "`",
None,
"self._makeClassAttribute("
+ attributeClassType
+ ', attributes["'
+ attributeName
+ '"])',
),
}
attributeDocType, attributeAssertType, attributeValue = types[attributeType]
@@ -73,15 +97,19 @@ while not added:
elif line.startswith(" def "):
attrName = line[8:-7]
# Properties will be inserted after __repr__, but before any other function.
if attrName != "__repr__" and (attrName == "_identity" or attrName > attributeName or not isProperty):
if attrName != "__repr__" and (
attrName == "_identity" or attrName > attributeName or not isProperty
):
if not isProperty:
newLines.append(" @property")
newLines.append(" def " + attributeName + "(self):")
newLines.append(" \"\"\"")
newLines.append(' """')
newLines.append(" :type: " + attributeDocType)
newLines.append(" \"\"\"")
newLines.append(' """')
if isCompletable:
newLines.append(" self._completeIfNotSet(self._" + attributeName + ")")
newLines.append(
" self._completeIfNotSet(self._" + attributeName + ")"
)
newLines.append(" return self._" + attributeName + ".value")
newLines.append("")
if isProperty:
@@ -103,7 +131,9 @@ while not added:
if line:
attrName = line[14:-29]
if not line or attrName > attributeName:
newLines.append(" self._" + attributeName + " = github.GithubObject.NotSet")
newLines.append(
" self._" + attributeName + " = github.GithubObject.NotSet"
)
added = True
newLines.append(line)
@@ -123,10 +153,26 @@ while not added:
if line:
attrName = line[12:-36]
if not line or attrName > attributeName:
newLines.append(" if \"" + attributeName + "\" in attributes: # pragma no branch")
newLines.append(
' if "'
+ attributeName
+ '" in attributes: # pragma no branch'
)
if attributeAssertType:
newLines.append(" assert attributes[\"" + attributeName + "\"] is None or isinstance(attributes[\"" + attributeName + "\"], " + attributeAssertType + "), attributes[\"" + attributeName + "\"]")
newLines.append(" self._" + attributeName + " = " + attributeValue)
newLines.append(
' assert attributes["'
+ attributeName
+ '"] is None or isinstance(attributes["'
+ attributeName
+ '"], '
+ attributeAssertType
+ '), attributes["'
+ attributeName
+ '"]'
)
newLines.append(
" self._" + attributeName + " = " + attributeValue
)
added = True
newLines.append(line)
+9 -3
View File
@@ -61,7 +61,9 @@ def generateLicenseSection(filename):
def listContributors(filename):
contributors = set()
for line in subprocess.check_output(["git", "log", "--format=format:%ad %an <%ae>", "--date=short", "--", filename]).split("\n"):
for line in subprocess.check_output(
["git", "log", "--format=format:%ad %an <%ae>", "--date=short", "--", filename]
).split("\n"):
year = line[0:4]
name = line[11:]
contributors.add((year, name))
@@ -105,7 +107,11 @@ class PythonHeader:
if len(bodyLines) > 0 and bodyLines[0] != "":
newLines.append("")
if "import " not in bodyLines[0] and bodyLines[0] != '"""' and not bodyLines[0].startswith("##########"):
if (
"import " not in bodyLines[0]
and bodyLines[0] != '"""'
and not bodyLines[0].startswith("##########")
):
newLines.append("")
newLines += bodyLines
@@ -129,7 +135,7 @@ class StandardHeader:
def findHeadersAndFiles():
for root, dirs, files in os.walk('.', topdown=True):
for root, dirs, files in os.walk(".", topdown=True):
if ".git" in dirs:
dirs.remove(".git")
if "developer.github.com" in dirs:
+1 -1
View File
@@ -227,5 +227,5 @@ __all__ = [
]
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()