eric5_api.py

changeset 1342
30226d5a7ffb
parent 945
8cd4d08fa9f6
child 1509
c0b5e693b0eb
equal deleted inserted replaced
1341:6104ae9ceb55 1342:30226d5a7ffb
169 progLanguages = ["Python3"] 169 progLanguages = ["Python3"]
170 170
171 for progLanguage in sorted(progLanguages): 171 for progLanguage in sorted(progLanguages):
172 basename = "" 172 basename = ""
173 apis = [] 173 apis = []
174 basesDict = {}
174 175
175 supportedExtensions = \ 176 supportedExtensions = \
176 DocumentationTools.supportedExtensionsDictForApis[progLanguage] 177 DocumentationTools.supportedExtensionsDictForApis[progLanguage]
177 supportedExtensions.extend(extensions) 178 supportedExtensions.extend(extensions)
178 if "%L" in outputFileName: 179 if "%L" in outputFileName:
181 if len(progLanguages) == 1: 182 if len(progLanguages) == 1:
182 outputFile = outputFileName 183 outputFile = outputFileName
183 else: 184 else:
184 root, ext = os.path.splitext(outputFileName) 185 root, ext = os.path.splitext(outputFileName)
185 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext) 186 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext)
187 basesFile = os.path.splitext(outputFile)[0] + '.bas'
186 188
187 for arg in args: 189 for arg in args:
188 if os.path.isdir(arg): 190 if os.path.isdir(arg):
189 if os.path.exists(os.path.join(arg, 191 if os.path.exists(os.path.join(arg,
190 Utilities.joinext("__init__", ".py"))): 192 Utilities.joinext("__init__", ".py"))):
241 try: 243 try:
242 module = Utilities.ModuleParser.readModule(file, 244 module = Utilities.ModuleParser.readModule(file,
243 basename=basename, inpackage=inpackage) 245 basename=basename, inpackage=inpackage)
244 apiGenerator = APIGenerator(module) 246 apiGenerator = APIGenerator(module)
245 api = apiGenerator.genAPI(True, basePackage, includePrivate) 247 api = apiGenerator.genAPI(True, basePackage, includePrivate)
248 bases = apiGenerator.genBases(includePrivate)
246 except IOError as v: 249 except IOError as v:
247 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) 250 sys.stderr.write("{0} error: {1}\n".format(file, v[1]))
248 continue 251 continue
249 except ImportError as v: 252 except ImportError as v:
250 sys.stderr.write("{0} error: {1}\n".format(file, v)) 253 sys.stderr.write("{0} error: {1}\n".format(file, v))
251 continue 254 continue
252 255
253 for apiEntry in api: 256 for apiEntry in api:
254 if not apiEntry in apis: 257 if not apiEntry in apis:
255 apis.append(apiEntry) 258 apis.append(apiEntry)
259 for basesEntry in bases:
260 if bases[basesEntry]:
261 basesDict[basesEntry] = bases[basesEntry][:]
256 sys.stdout.write("-- {0} -- {1} ok\n".format(progLanguage, file)) 262 sys.stdout.write("-- {0} -- {1} ok\n".format(progLanguage, file))
257 263
258 outdir = os.path.dirname(outputFile) 264 outdir = os.path.dirname(outputFile)
259 if outdir and not os.path.exists(outdir): 265 if outdir and not os.path.exists(outdir):
260 os.makedirs(outdir) 266 os.makedirs(outdir)
263 out.write("\n".join(sorted(apis)) + "\n") 269 out.write("\n".join(sorted(apis)) + "\n")
264 out.close() 270 out.close()
265 except IOError as v: 271 except IOError as v:
266 sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1])) 272 sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1]))
267 sys.exit(3) 273 sys.exit(3)
274 try:
275 out = open(basesFile, "w", encoding="utf-8", newline=newline)
276 for baseEntry in sorted(basesDict.keys()):
277 out.write("{0} {1}\n".format(
278 baseEntry, " ".join(sorted(basesDict[baseEntry]))))
279 out.close()
280 except IOError as v:
281 sys.stderr.write("{0} error: {1}\n".format(basesFile, v[1]))
282 sys.exit(3)
268 283
269 sys.stdout.write('\nDone.\n') 284 sys.stdout.write('\nDone.\n')
270 sys.exit(0) 285 sys.exit(0)
271 286
272 if __name__ == '__main__': 287 if __name__ == '__main__':

eric ide

mercurial