eric5-api.py

changeset 433
988006cb898f
parent 253
3ccdf551bde7
child 788
5b1b59777460
equal deleted inserted replaced
432:497e188ee86e 433:988006cb898f
70 print(" Show version information and exit.") 70 print(" Show version information and exit.")
71 print(" -x directory or --exclude=directory") 71 print(" -x directory or --exclude=directory")
72 print(" Specify a directory basename to be excluded.") 72 print(" Specify a directory basename to be excluded.")
73 print(" This option may be repeated multiple times.") 73 print(" This option may be repeated multiple times.")
74 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()): 74 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()):
75 print(" * %s" % lang) 75 print(" * {0}".format(lang))
76 print(" The default is 'Python'.") 76 print(" The default is 'Python'.")
77 print(" This option may be repeated multiple times.") 77 print(" This option may be repeated multiple times.")
78 sys.exit(1) 78 sys.exit(1)
79 79
80 def version(): 80 def version():
81 """ 81 """
82 Function to show the version information. 82 Function to show the version information.
83 """ 83 """
84 print("""eric5-api %s 84 print("""eric5-api {0}
85 85
86 Eric5 API generator. 86 Eric5 API generator.
87 87
88 Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> 88 Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
89 This is free software; see the LICENSE.GPL3 for copying conditions. 89 This is free software; see the LICENSE.GPL3 for copying conditions.
90 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A 90 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
91 PARTICULAR PURPOSE.""" % Version) 91 PARTICULAR PURPOSE.""".format(Version))
92 sys.exit(1) 92 sys.exit(1)
93 93
94 def main(): 94 def main():
95 """ 95 """
96 Main entry point into the application. 96 Main entry point into the application.
131 usage() 131 usage()
132 elif k in ["-V", "--version"]: 132 elif k in ["-V", "--version"]:
133 version() 133 version()
134 elif k in ["-t", "--extension"]: 134 elif k in ["-t", "--extension"]:
135 if not v.startswith("."): 135 if not v.startswith("."):
136 v = ".%s" % v 136 v = ".{0}".format(v)
137 extensions.append(v) 137 extensions.append(v)
138 elif k in ["-b", "--base"]: 138 elif k in ["-b", "--base"]:
139 basePackage = v 139 basePackage = v
140 elif k in ["-p", "--private"]: 140 elif k in ["-p", "--private"]:
141 includePrivate = True 141 includePrivate = True
142 elif k in ["-l", "--language"]: 142 elif k in ["-l", "--language"]:
143 if v not in progLanguages: 143 if v not in progLanguages:
144 if v not in \ 144 if v not in \
145 list(DocumentationTools.supportedExtensionsDictForApis.keys()): 145 list(DocumentationTools.supportedExtensionsDictForApis.keys()):
146 sys.stderr.write("Wrong language given: %s. Aborting\n" % v) 146 sys.stderr.write("Wrong language given: {0}. Aborting\n".format(v))
147 sys.exit(1) 147 sys.exit(1)
148 else: 148 else:
149 progLanguages.append(v) 149 progLanguages.append(v)
150 elif k in ["-e", "--eol"]: 150 elif k in ["-e", "--eol"]:
151 if v.lower() == "cr": 151 if v.lower() == "cr":
177 else: 177 else:
178 if len(progLanguages) == 1: 178 if len(progLanguages) == 1:
179 outputFile = outputFileName 179 outputFile = outputFileName
180 else: 180 else:
181 root, ext = os.path.splitext(outputFileName) 181 root, ext = os.path.splitext(outputFileName)
182 outputFile = "%s-%s%s" % (root, progLanguage.lower(), ext) 182 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext)
183 183
184 for arg in args: 184 for arg in args:
185 if os.path.isdir(arg): 185 if os.path.isdir(arg):
186 if os.path.exists(os.path.join(arg, 186 if os.path.exists(os.path.join(arg,
187 Utilities.joinext("__init__", ".py"))): 187 Utilities.joinext("__init__", ".py"))):
192 sys.stderr.write("Ignoring the directory.\n") 192 sys.stderr.write("Ignoring the directory.\n")
193 continue 193 continue
194 else: 194 else:
195 basename = arg 195 basename = arg
196 if basename: 196 if basename:
197 basename = "%s%s" % (basename, os.sep) 197 basename = "{0}{1}".format(basename, os.sep)
198 198
199 if recursive and not os.path.islink(arg): 199 if recursive and not os.path.islink(arg):
200 names = [arg] + Utilities.getDirs(arg, excludeDirs) 200 names = [arg] + Utilities.getDirs(arg, excludeDirs)
201 else: 201 else:
202 names = [arg] 202 names = [arg]
239 module = Utilities.ModuleParser.readModule(file, 239 module = Utilities.ModuleParser.readModule(file,
240 basename = basename, inpackage = inpackage) 240 basename = basename, inpackage = inpackage)
241 apiGenerator = APIGenerator(module) 241 apiGenerator = APIGenerator(module)
242 api = apiGenerator.genAPI(True, basePackage, includePrivate) 242 api = apiGenerator.genAPI(True, basePackage, includePrivate)
243 except IOError as v: 243 except IOError as v:
244 sys.stderr.write("%s error: %s\n" % (file, v[1])) 244 sys.stderr.write("{0} error: {1}\n".format(file, v[1]))
245 continue 245 continue
246 except ImportError as v: 246 except ImportError as v:
247 sys.stderr.write("%s error: %s\n" % (file, v)) 247 sys.stderr.write("{0} error: {1}\n".format(file, v))
248 continue 248 continue
249 249
250 for apiEntry in api: 250 for apiEntry in api:
251 if not apiEntry in apis: 251 if not apiEntry in apis:
252 apis.append(apiEntry) 252 apis.append(apiEntry)
253 sys.stdout.write("-- %s -- %s ok\n" % (progLanguage, file)) 253 sys.stdout.write("-- {0} -- {1} ok\n".format(progLanguage, file))
254 254
255 outdir = os.path.dirname(outputFile) 255 outdir = os.path.dirname(outputFile)
256 if outdir and not os.path.exists(outdir): 256 if outdir and not os.path.exists(outdir):
257 os.makedirs(outdir) 257 os.makedirs(outdir)
258 try: 258 try:
259 out = open(outputFile, "w", encoding = "utf-8", newline = newline) 259 out = open(outputFile, "w", encoding = "utf-8", newline = newline)
260 out.write("\n".join(sorted(apis)) + "\n") 260 out.write("\n".join(sorted(apis)) + "\n")
261 out.close() 261 out.close()
262 except IOError as v: 262 except IOError as v:
263 sys.stderr.write("%s error: %s\n" % (outputFile, v[1])) 263 sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1]))
264 sys.exit(3) 264 sys.exit(3)
265 265
266 sys.stdout.write('\nDone.\n') 266 sys.stdout.write('\nDone.\n')
267 sys.exit(0) 267 sys.exit(0)
268 268

eric ide

mercurial