31 It prints a reference of all commandline parameters that may |
31 It prints a reference of all commandline parameters that may |
32 be used and ends the application. |
32 be used and ends the application. |
33 """ |
33 """ |
34 print("eric5_api") |
34 print("eric5_api") |
35 print() |
35 print() |
36 print("Copyright (c) 2004 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>.") |
36 print("Copyright (c) 2004 - 2013 Detlev Offenbach" |
|
37 " <detlev@die-offenbachs.de>.") |
37 print() |
38 print() |
38 print("Usage:") |
39 print("Usage:") |
39 print() |
40 print() |
40 print(" eric5_api [options] files...") |
41 print(" eric5_api [options] files...") |
41 print() |
42 print() |
55 print(" -h or --help") |
56 print(" -h or --help") |
56 print(" Show this help and exit.") |
57 print(" Show this help and exit.") |
57 print(" -l language or --language=language") |
58 print(" -l language or --language=language") |
58 print(" Generate an API file for the given programming language.") |
59 print(" Generate an API file for the given programming language.") |
59 print(" Supported programming languages are:") |
60 print(" Supported programming languages are:") |
60 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()): |
61 for lang in sorted( |
|
62 DocumentationTools.supportedExtensionsDictForApis.keys()): |
61 print(" * {0}".format(lang)) |
63 print(" * {0}".format(lang)) |
62 print(" The default is 'Python3'.") |
64 print(" The default is 'Python3'.") |
63 print(" This option may be repeated multiple times.") |
65 print(" This option may be repeated multiple times.") |
64 print(" -o filename or --output=filename") |
66 print(" -o filename or --output=filename") |
65 print(" Write the API information to the named file. A '%L' placeholder") |
67 print(" Write the API information to the named file." |
66 print(" is replaced by the language of the API file (see --language).") |
68 " A '%L' placeholder") |
|
69 print(" is replaced by the language of the API file" |
|
70 " (see --language).") |
67 print(" -p or --private") |
71 print(" -p or --private") |
68 print(" Include private methods and functions.") |
72 print(" Include private methods and functions.") |
69 print(" -R, -r or --recursive") |
73 print(" -R, -r or --recursive") |
70 print(" Perform a recursive search for source files.") |
74 print(" Perform a recursive search for source files.") |
71 print(" -t ext or --extension=ext") |
75 print(" -t ext or --extension=ext") |
109 "version", ]) |
113 "version", ]) |
110 except getopt.error: |
114 except getopt.error: |
111 usage() |
115 usage() |
112 |
116 |
113 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject", |
117 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject", |
114 ".eric5project", "_eric5project", "dist", "build", "doc", "docs"] |
118 ".eric5project", "_eric5project", "dist", "build", "doc", |
|
119 "docs"] |
115 excludePatterns = [] |
120 excludePatterns = [] |
116 outputFileName = "" |
121 outputFileName = "" |
117 recursive = False |
122 recursive = False |
118 basePackage = "" |
123 basePackage = "" |
119 includePrivate = False |
124 includePrivate = False |
143 elif k in ["-p", "--private"]: |
148 elif k in ["-p", "--private"]: |
144 includePrivate = True |
149 includePrivate = True |
145 elif k in ["-l", "--language"]: |
150 elif k in ["-l", "--language"]: |
146 if v not in progLanguages: |
151 if v not in progLanguages: |
147 if v not in \ |
152 if v not in \ |
148 list(DocumentationTools.supportedExtensionsDictForApis.keys()): |
153 DocumentationTools.supportedExtensionsDictForApis: |
149 sys.stderr.write("Wrong language given: {0}. Aborting\n".format(v)) |
154 sys.stderr.write( |
|
155 "Wrong language given: {0}. Aborting\n".format(v)) |
150 sys.exit(1) |
156 sys.exit(1) |
151 else: |
157 else: |
152 progLanguages.append(v) |
158 progLanguages.append(v) |
153 elif k in ["-e", "--eol"]: |
159 elif k in ["-e", "--eol"]: |
154 if v.lower() == "cr": |
160 if v.lower() == "cr": |
181 else: |
187 else: |
182 if len(progLanguages) == 1: |
188 if len(progLanguages) == 1: |
183 outputFile = outputFileName |
189 outputFile = outputFileName |
184 else: |
190 else: |
185 root, ext = os.path.splitext(outputFileName) |
191 root, ext = os.path.splitext(outputFileName) |
186 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext) |
192 outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), |
|
193 ext) |
187 basesFile = os.path.splitext(outputFile)[0] + '.bas' |
194 basesFile = os.path.splitext(outputFile)[0] + '.bas' |
188 |
195 |
189 for arg in args: |
196 for arg in args: |
190 if os.path.isdir(arg): |
197 if os.path.isdir(arg): |
191 if os.path.exists(os.path.join(arg, |
198 if os.path.exists(os.path.join(arg, |
192 Utilities.joinext("__init__", ".py"))): |
199 Utilities.joinext("__init__", ".py"))): |
193 basename = os.path.dirname(arg) |
200 basename = os.path.dirname(arg) |
194 if arg == '.': |
201 if arg == '.': |
195 sys.stderr.write("The directory '.' is a package.\n") |
202 sys.stderr.write("The directory '.' is a package.\n") |
196 sys.stderr.write("Please repeat the call giving its real name.\n") |
203 sys.stderr.write( |
|
204 "Please repeat the call giving its real name.\n") |
197 sys.stderr.write("Ignoring the directory.\n") |
205 sys.stderr.write("Ignoring the directory.\n") |
198 continue |
206 continue |
199 else: |
207 else: |
200 basename = arg |
208 basename = arg |
201 if basename: |
209 if basename: |
212 for filename in sorted(names): |
220 for filename in sorted(names): |
213 inpackage = False |
221 inpackage = False |
214 if os.path.isdir(filename): |
222 if os.path.isdir(filename): |
215 files = [] |
223 files = [] |
216 for ext in supportedExtensions: |
224 for ext in supportedExtensions: |
217 files.extend(glob.glob(os.path.join(filename, |
225 files.extend(glob.glob(os.path.join( |
218 Utilities.joinext("*", ext)))) |
226 filename, Utilities.joinext("*", ext)))) |
219 initFile = os.path.join(filename, |
227 initFile = os.path.join( |
220 Utilities.joinext("__init__", ext)) |
228 filename, Utilities.joinext("__init__", ext)) |
221 if initFile in files: |
229 if initFile in files: |
222 inpackage = True |
230 inpackage = True |
223 files.remove(initFile) |
231 files.remove(initFile) |
224 files.insert(0, initFile) |
232 files.insert(0, initFile) |
225 elif progLanguage != "Python3": |
233 elif progLanguage != "Python3": |
226 # assume package |
234 # assume package |
227 inpackage = True |
235 inpackage = True |
228 else: |
236 else: |
229 if Utilities.isWindowsPlatform() and glob.has_magic(filename): |
237 if Utilities.isWindowsPlatform() and \ |
|
238 glob.has_magic(filename): |
230 files = glob.glob(filename) |
239 files = glob.glob(filename) |
231 else: |
240 else: |
232 files = [filename] |
241 files = [filename] |
233 |
242 |
234 for file in files: |
243 for file in files: |
242 |
251 |
243 try: |
252 try: |
244 module = Utilities.ModuleParser.readModule(file, |
253 module = Utilities.ModuleParser.readModule(file, |
245 basename=basename, inpackage=inpackage) |
254 basename=basename, inpackage=inpackage) |
246 apiGenerator = APIGenerator(module) |
255 apiGenerator = APIGenerator(module) |
247 api = apiGenerator.genAPI(True, basePackage, includePrivate) |
256 api = apiGenerator.genAPI(True, basePackage, |
|
257 includePrivate) |
248 bases = apiGenerator.genBases(includePrivate) |
258 bases = apiGenerator.genBases(includePrivate) |
249 except IOError as v: |
259 except IOError as v: |
250 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) |
260 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) |
251 continue |
261 continue |
252 except ImportError as v: |
262 except ImportError as v: |
257 if not apiEntry in apis: |
267 if not apiEntry in apis: |
258 apis.append(apiEntry) |
268 apis.append(apiEntry) |
259 for basesEntry in bases: |
269 for basesEntry in bases: |
260 if bases[basesEntry]: |
270 if bases[basesEntry]: |
261 basesDict[basesEntry] = bases[basesEntry][:] |
271 basesDict[basesEntry] = bases[basesEntry][:] |
262 sys.stdout.write("-- {0} -- {1} ok\n".format(progLanguage, file)) |
272 sys.stdout.write("-- {0} -- {1} ok\n".format( |
|
273 progLanguage, file)) |
263 |
274 |
264 outdir = os.path.dirname(outputFile) |
275 outdir = os.path.dirname(outputFile) |
265 if outdir and not os.path.exists(outdir): |
276 if outdir and not os.path.exists(outdir): |
266 os.makedirs(outdir) |
277 os.makedirs(outdir) |
267 try: |
278 try: |