eric5_api.py

changeset 945
8cd4d08fa9f6
parent 908
d00447340771
child 1342
30226d5a7ffb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
20 import Utilities.ModuleParser 20 import Utilities.ModuleParser
21 from DocumentationTools.APIGenerator import APIGenerator 21 from DocumentationTools.APIGenerator import APIGenerator
22 from UI.Info import Version 22 from UI.Info import Version
23 import Utilities 23 import Utilities
24 import DocumentationTools 24 import DocumentationTools
25
25 26
26 def usage(): 27 def usage():
27 """ 28 """
28 Function to print some usage information. 29 Function to print some usage information.
29 30
75 print(" * {0}".format(lang)) 76 print(" * {0}".format(lang))
76 print(" The default is 'Python3'.") 77 print(" The default is 'Python3'.")
77 print(" This option may be repeated multiple times.") 78 print(" This option may be repeated multiple times.")
78 sys.exit(1) 79 sys.exit(1)
79 80
81
80 def version(): 82 def version():
81 """ 83 """
82 Function to show the version information. 84 Function to show the version information.
83 """ 85 """
84 print("""eric5_api {0} 86 print("""eric5_api {0}
89 This is free software; see the LICENSE.GPL3 for copying conditions. 91 This is free software; see the LICENSE.GPL3 for copying conditions.
90 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A 92 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
91 PARTICULAR PURPOSE.""".format(Version)) 93 PARTICULAR PURPOSE.""".format(Version))
92 sys.exit(1) 94 sys.exit(1)
93 95
96
94 def main(): 97 def main():
95 """ 98 """
96 Main entry point into the application. 99 Main entry point into the application.
97 """ 100 """
98 global supportedExtensions 101 global supportedExtensions
100 import getopt 103 import getopt
101 104
102 try: 105 try:
103 opts, args = getopt.getopt(sys.argv[1:], "b:e:hl:o:pRrt:Vx:", 106 opts, args = getopt.getopt(sys.argv[1:], "b:e:hl:o:pRrt:Vx:",
104 ["base=", "eol=", "exclude=", "exclude-file=", "extension=", "help", 107 ["base=", "eol=", "exclude=", "exclude-file=", "extension=", "help",
105 "language=", "output=", "private", "recursive", 108 "language=", "output=", "private", "recursive",
106 "version", ]) 109 "version", ])
107 except getopt.error: 110 except getopt.error:
108 usage() 111 usage()
109 112
110 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject", 113 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject",
111 ".eric5project", "_eric5project", "dist", "build", "doc", "docs"] 114 ".eric5project", "_eric5project", "dist", "build", "doc", "docs"]
112 excludePatterns = [] 115 excludePatterns = []
113 outputFileName = "" 116 outputFileName = ""
114 recursive = False 117 recursive = False
115 basePackage = "" 118 basePackage = ""
181 root, ext = os.path.splitext(outputFileName) 184 root, ext = os.path.splitext(outputFileName)
182 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext) 185 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext)
183 186
184 for arg in args: 187 for arg in args:
185 if os.path.isdir(arg): 188 if os.path.isdir(arg):
186 if os.path.exists(os.path.join(arg, 189 if os.path.exists(os.path.join(arg,
187 Utilities.joinext("__init__", ".py"))): 190 Utilities.joinext("__init__", ".py"))):
188 basename = os.path.dirname(arg) 191 basename = os.path.dirname(arg)
189 if arg == '.': 192 if arg == '.':
190 sys.stderr.write("The directory '.' is a package.\n") 193 sys.stderr.write("The directory '.' is a package.\n")
191 sys.stderr.write("Please repeat the call giving its real name.\n") 194 sys.stderr.write("Please repeat the call giving its real name.\n")
209 if os.path.isdir(filename): 212 if os.path.isdir(filename):
210 files = [] 213 files = []
211 for ext in supportedExtensions: 214 for ext in supportedExtensions:
212 files.extend(glob.glob(os.path.join(filename, 215 files.extend(glob.glob(os.path.join(filename,
213 Utilities.joinext("*", ext)))) 216 Utilities.joinext("*", ext))))
214 initFile = os.path.join(filename, 217 initFile = os.path.join(filename,
215 Utilities.joinext("__init__", ext)) 218 Utilities.joinext("__init__", ext))
216 if initFile in files: 219 if initFile in files:
217 inpackage = True 220 inpackage = True
218 files.remove(initFile) 221 files.remove(initFile)
219 files.insert(0, initFile) 222 files.insert(0, initFile)
234 break 237 break
235 if skipIt: 238 if skipIt:
236 continue 239 continue
237 240
238 try: 241 try:
239 module = Utilities.ModuleParser.readModule(file, 242 module = Utilities.ModuleParser.readModule(file,
240 basename = basename, inpackage = inpackage) 243 basename=basename, inpackage=inpackage)
241 apiGenerator = APIGenerator(module) 244 apiGenerator = APIGenerator(module)
242 api = apiGenerator.genAPI(True, basePackage, includePrivate) 245 api = apiGenerator.genAPI(True, basePackage, includePrivate)
243 except IOError as v: 246 except IOError as v:
244 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) 247 sys.stderr.write("{0} error: {1}\n".format(file, v[1]))
245 continue 248 continue
254 257
255 outdir = os.path.dirname(outputFile) 258 outdir = os.path.dirname(outputFile)
256 if outdir and not os.path.exists(outdir): 259 if outdir and not os.path.exists(outdir):
257 os.makedirs(outdir) 260 os.makedirs(outdir)
258 try: 261 try:
259 out = open(outputFile, "w", encoding = "utf-8", newline = newline) 262 out = open(outputFile, "w", encoding="utf-8", newline=newline)
260 out.write("\n".join(sorted(apis)) + "\n") 263 out.write("\n".join(sorted(apis)) + "\n")
261 out.close() 264 out.close()
262 except IOError as v: 265 except IOError as v:
263 sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1])) 266 sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1]))
264 sys.exit(3) 267 sys.exit(3)

eric ide

mercurial