116 |
116 |
117 def version(): |
117 def version(): |
118 """ |
118 """ |
119 Function to show the version information. |
119 Function to show the version information. |
120 """ |
120 """ |
121 print("""eric5-doc %s |
121 print("""eric5-doc {0} |
122 |
122 |
123 Eric5 API documentation generator. |
123 Eric5 API documentation generator. |
124 |
124 |
125 Copyright (c) 2003-2010 Detlev Offenbach <detlev@die-offenbachs.de> |
125 Copyright (c) 2003-2010 Detlev Offenbach <detlev@die-offenbachs.de> |
126 This is free software; see the LICENSE.GPL3 for copying conditions. |
126 This is free software; see the LICENSE.GPL3 for copying conditions. |
127 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A |
127 There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A |
128 PARTICULAR PURPOSE.""" % Version) |
128 PARTICULAR PURPOSE.""".format(Version)) |
129 sys.exit(1) |
129 sys.exit(1) |
130 |
130 |
131 def main(): |
131 def main(): |
132 """ |
132 """ |
133 Main entry point into the application. |
133 Main entry point into the application. |
192 version() |
192 version() |
193 elif k in ["-c", "--style-sheet"]: |
193 elif k in ["-c", "--style-sheet"]: |
194 stylesheetFile = v |
194 stylesheetFile = v |
195 elif k in ["-t", "--extension"]: |
195 elif k in ["-t", "--extension"]: |
196 if not v.startswith("."): |
196 if not v.startswith("."): |
197 v = ".%s" % v |
197 v = ".{0}".format(v) |
198 supportedExtensions.append(v) |
198 supportedExtensions.append(v) |
199 elif k == "--eol": |
199 elif k == "--eol": |
200 if v.lower() == "cr": |
200 if v.lower() == "cr": |
201 newline = '\r' |
201 newline = '\r' |
202 elif v.lower() == "lf": |
202 elif v.lower() == "lf": |
255 if outputDir: |
255 if outputDir: |
256 if not os.path.isdir(outputDir): |
256 if not os.path.isdir(outputDir): |
257 try: |
257 try: |
258 os.makedirs(outputDir) |
258 os.makedirs(outputDir) |
259 except EnvironmentError: |
259 except EnvironmentError: |
260 sys.stderr.write("Could not create output directory %s." % outputDir) |
260 sys.stderr.write( |
|
261 "Could not create output directory {0}.".format(outputDir)) |
261 sys.exit(2) |
262 sys.exit(2) |
262 else: |
263 else: |
263 outputDir = os.getcwd() |
264 outputDir = os.getcwd() |
264 outputDir = os.path.abspath(outputDir) |
265 outputDir = os.path.abspath(outputDir) |
265 |
266 |
267 try: |
268 try: |
268 sf = open(stylesheetFile, "r", encoding = "utf-8") |
269 sf = open(stylesheetFile, "r", encoding = "utf-8") |
269 stylesheet = sf.read() |
270 stylesheet = sf.read() |
270 sf.close() |
271 sf.close() |
271 except IOError: |
272 except IOError: |
272 sys.stderr.write("The CSS stylesheet '%s' does not exist\n" % stylesheetFile) |
273 sys.stderr.write( |
|
274 "The CSS stylesheet '{0}' does not exist\n".format(stylesheetFile)) |
273 sys.stderr.write("Disabling CSS usage.\n") |
275 sys.stderr.write("Disabling CSS usage.\n") |
274 stylesheet = None |
276 stylesheet = None |
275 else: |
277 else: |
276 stylesheet = None |
278 stylesheet = None |
277 |
279 |
281 if qtHelpOutputDir: |
283 if qtHelpOutputDir: |
282 if not os.path.isdir(qtHelpOutputDir): |
284 if not os.path.isdir(qtHelpOutputDir): |
283 try: |
285 try: |
284 os.makedirs(qtHelpOutputDir) |
286 os.makedirs(qtHelpOutputDir) |
285 except EnvironmentError: |
287 except EnvironmentError: |
286 sys.stderr.write("Could not create QtHelp output directory %s." % \ |
288 sys.stderr.write( |
287 qtHelpOutputDir) |
289 "Could not create QtHelp output directory {0}.".format( |
|
290 qtHelpOutputDir)) |
288 sys.exit(2) |
291 sys.exit(2) |
289 else: |
292 else: |
290 qtHelpOutputDir = os.getcwd() |
293 qtHelpOutputDir = os.getcwd() |
291 qtHelpOutputDir = os.path.abspath(qtHelpOutputDir) |
294 qtHelpOutputDir = os.path.abspath(qtHelpOutputDir) |
292 |
295 |
305 sys.stderr.write("Ignoring the directory.\n") |
308 sys.stderr.write("Ignoring the directory.\n") |
306 continue |
309 continue |
307 else: |
310 else: |
308 basename = arg |
311 basename = arg |
309 if basename: |
312 if basename: |
310 basename = "%s%s" % (basename, os.sep) |
313 basename = "{0}{1}".format(basename, os.sep) |
311 |
314 |
312 if recursive and not os.path.islink(arg): |
315 if recursive and not os.path.islink(arg): |
313 names = [arg] + Utilities.getDirs(arg, excludeDirs) |
316 names = [arg] + Utilities.getDirs(arg, excludeDirs) |
314 else: |
317 else: |
315 names = [arg] |
318 names = [arg] |
348 module = Utilities.ModuleParser.readModule(file, basename = basename, |
351 module = Utilities.ModuleParser.readModule(file, basename = basename, |
349 inpackage = inpackage, extensions = supportedExtensions) |
352 inpackage = inpackage, extensions = supportedExtensions) |
350 moduleDocument = ModuleDocument(module, colors, stylesheet) |
353 moduleDocument = ModuleDocument(module, colors, stylesheet) |
351 doc = moduleDocument.genDocument() |
354 doc = moduleDocument.genDocument() |
352 except IOError as v: |
355 except IOError as v: |
353 sys.stderr.write("%s error: %s\n" % (file, v[1])) |
356 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) |
354 continue |
357 continue |
355 except ImportError as v: |
358 except ImportError as v: |
356 sys.stderr.write("%s error: %s\n" % (file, v)) |
359 sys.stderr.write("{0} error: {1}\n".format(file, v)) |
357 continue |
360 continue |
358 |
361 |
359 input = input + 1 |
362 input = input + 1 |
360 |
363 |
361 f = Utilities.joinext(os.path.join(outputDir, moduleDocument.name()), |
364 f = Utilities.joinext(os.path.join(outputDir, moduleDocument.name()), |
376 try: |
379 try: |
377 out = open(f, "w", encoding = "utf-8", newline = newline) |
380 out = open(f, "w", encoding = "utf-8", newline = newline) |
378 out.write(doc) |
381 out.write(doc) |
379 out.close() |
382 out.close() |
380 except IOError as v: |
383 except IOError as v: |
381 sys.stderr.write("%s error: %s\n" % (file, v[1])) |
384 sys.stderr.write("{0} error: {1}\n".format(file, v[1])) |
382 else: |
385 else: |
383 sys.stdout.write("%s ok\n" % f) |
386 sys.stdout.write("{0} ok\n".format(f)) |
384 |
387 |
385 output = output + 1 |
388 output = output + 1 |
386 sys.stdout.flush() |
389 sys.stdout.flush() |
387 sys.stderr.flush() |
390 sys.stderr.flush() |
388 |
391 |