DocumentationTools/APIGenerator.py

changeset 406
eacf81fad150
parent 253
3ccdf551bde7
child 791
9ec2ac20e54e
equal deleted inserted replaced
405:374066392929 406:eacf81fad150
37 modulePath = self.module.name.split('.') 37 modulePath = self.module.name.split('.')
38 if modulePath[-1] == '__init__': 38 if modulePath[-1] == '__init__':
39 del modulePath[-1] 39 del modulePath[-1]
40 if basePackage: 40 if basePackage:
41 modulePath[0] = basePackage 41 modulePath[0] = basePackage
42 self.moduleName = "%s." % '.'.join(modulePath) 42 self.moduleName = "{0}.".format('.'.join(modulePath))
43 self.api = [] 43 self.api = []
44 self.__addGlobalsAPI() 44 self.__addGlobalsAPI()
45 self.__addClassesAPI() 45 self.__addClassesAPI()
46 self.__addFunctionsAPI() 46 self.__addFunctionsAPI()
47 return self.api 47 return self.api
58 58
59 def __addGlobalsAPI(self): 59 def __addGlobalsAPI(self):
60 """ 60 """
61 Private method to generate the api section for global variables. 61 Private method to generate the api section for global variables.
62 """ 62 """
63 moduleNameStr = "%s" % self.moduleName 63 moduleNameStr = "{0}".format(self.moduleName)
64 64
65 for globalName in sorted(self.module.globals.keys()): 65 for globalName in sorted(self.module.globals.keys()):
66 if not self.__isPrivate(self.module.globals[globalName]): 66 if not self.__isPrivate(self.module.globals[globalName]):
67 if self.module.globals[globalName].isPublic(): 67 if self.module.globals[globalName].isPublic():
68 id = Editor.AttributeID 68 id = Editor.AttributeID
69 elif self.module.globals[globalName].isProtected(): 69 elif self.module.globals[globalName].isProtected():
70 id = Editor.AttributeProtectedID 70 id = Editor.AttributeProtectedID
71 else: 71 else:
72 id = Editor.AttributePrivateID 72 id = Editor.AttributePrivateID
73 self.api.append("%s%s?%d" % (moduleNameStr, globalName, id)) 73 self.api.append("{0}{1}?{2:d}".format(moduleNameStr, globalName, id))
74 74
75 def __addClassesAPI(self): 75 def __addClassesAPI(self):
76 """ 76 """
77 Private method to generate the api section for classes. 77 Private method to generate the api section for classes.
78 """ 78 """
96 id = Editor.ClassID 96 id = Editor.ClassID
97 elif _class.isProtected(): 97 elif _class.isProtected():
98 id = Editor.ClassProtectedID 98 id = Editor.ClassProtectedID
99 else: 99 else:
100 id = Editor.ClassPrivateID 100 id = Editor.ClassPrivateID
101 self.api.append('%s%s?%d(%s)' % \ 101 self.api.append('{0}{1}?{2:d}({3})'.format(
102 (self.moduleName, _class.name, id, 102 self.moduleName, _class.name, id,
103 ', '.join(_class.methods['__init__'].parameters[1:]))) 103 ', '.join(_class.methods['__init__'].parameters[1:])))
104 104
105 classNameStr = "%s%s." % (self.moduleName, className) 105 classNameStr = "{0}{1}.".format(self.moduleName, className)
106 for method in methods: 106 for method in methods:
107 if not self.__isPrivate(_class.methods[method]): 107 if not self.__isPrivate(_class.methods[method]):
108 if _class.methods[method].isPublic(): 108 if _class.methods[method].isPublic():
109 id = Editor.MethodID 109 id = Editor.MethodID
110 elif _class.methods[method].isProtected(): 110 elif _class.methods[method].isProtected():
111 id = Editor.MethodProtectedID 111 id = Editor.MethodProtectedID
112 else: 112 else:
113 id = Editor.MethodPrivateID 113 id = Editor.MethodPrivateID
114 self.api.append('%s%s?%d(%s)' % \ 114 self.api.append('{0}{1}?{2:d}({3})'.format(
115 (classNameStr, method, id, 115 classNameStr, method, id,
116 ', '.join(_class.methods[method].parameters[1:]))) 116 ', '.join(_class.methods[method].parameters[1:])))
117 117
118 def __addClassVariablesAPI(self, className): 118 def __addClassVariablesAPI(self, className):
119 """ 119 """
120 Private method to generate class api section for class variables. 120 Private method to generate class api section for class variables.
121 121
122 @param classname Name of the class containing the class variables. (string) 122 @param classname Name of the class containing the class variables. (string)
123 """ 123 """
124 _class = self.module.classes[className] 124 _class = self.module.classes[className]
125 classNameStr = "%s%s." % (self.moduleName, className) 125 classNameStr = "{0}{1}.".format(self.moduleName, className)
126 for variable in sorted(_class.globals.keys()): 126 for variable in sorted(_class.globals.keys()):
127 if not self.__isPrivate(_class.globals[variable]): 127 if not self.__isPrivate(_class.globals[variable]):
128 if _class.globals[variable].isPublic(): 128 if _class.globals[variable].isPublic():
129 id = Editor.AttributeID 129 id = Editor.AttributeID
130 elif _class.globals[variable].isProtected(): 130 elif _class.globals[variable].isProtected():
131 id = Editor.AttributeProtectedID 131 id = Editor.AttributeProtectedID
132 else: 132 else:
133 id = Editor.AttributePrivateID 133 id = Editor.AttributePrivateID
134 self.api.append('%s%s?%d' % (classNameStr, variable, id)) 134 self.api.append('{0}{1}?{2:d}'.format(classNameStr, variable, id))
135 135
136 def __addFunctionsAPI(self): 136 def __addFunctionsAPI(self):
137 """ 137 """
138 Private method to generate the api section for functions. 138 Private method to generate the api section for functions.
139 """ 139 """
144 id = Editor.MethodID 144 id = Editor.MethodID
145 elif self.module.functions[funcName].isProtected(): 145 elif self.module.functions[funcName].isProtected():
146 id = Editor.MethodProtectedID 146 id = Editor.MethodProtectedID
147 else: 147 else:
148 id = Editor.MethodPrivateID 148 id = Editor.MethodPrivateID
149 self.api.append('%s%s?%d(%s)' % \ 149 self.api.append('{0}{1}?{2:d}({3})'.format(
150 (self.moduleName, self.module.functions[funcName].name, id, 150 self.moduleName, self.module.functions[funcName].name, id,
151 ', '.join(self.module.functions[funcName].parameters))) 151 ', '.join(self.module.functions[funcName].parameters)))

eric ide

mercurial