eric4-api.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> 4 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
5 # 5 #
6 6
29 Function to print some usage information. 29 Function to print some usage information.
30 30
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 "eric4-api" 34 print("eric4-api")
35 print 35 print()
36 print "Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>." 36 print("Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>.")
37 print 37 print()
38 print "Usage:" 38 print("Usage:")
39 print 39 print()
40 print " eric4-api [options] files..." 40 print(" eric4-api [options] files...")
41 print 41 print()
42 print "where files can be either python modules, package" 42 print("where files can be either python modules, package")
43 print "directories or ordinary directories." 43 print("directories or ordinary directories.")
44 print 44 print()
45 print "Options:" 45 print("Options:")
46 print 46 print()
47 print " -b name or --base name" 47 print(" -b name or --base name")
48 print " Use the given name as the name of the base package." 48 print(" Use the given name as the name of the base package.")
49 print " -h or --help" 49 print(" -h or --help")
50 print " Show this help and exit." 50 print(" Show this help and exit.")
51 print " -o filename or --output=filename" 51 print(" -o filename or --output=filename")
52 print " Write the API information to the named file. A '%L' placeholder" 52 print(" Write the API information to the named file. A '%L' placeholder")
53 print " is replaced by the language of the API file (see --language)." 53 print(" is replaced by the language of the API file (see --language).")
54 print " --oldstyle" 54 print(" --oldstyle")
55 print " Generate API files for QScintilla prior to 1.7." 55 print(" Generate API files for QScintilla prior to 1.7.")
56 print " -p or --private" 56 print(" -p or --private")
57 print " Include private methods and functions." 57 print(" Include private methods and functions.")
58 print " -R, -r or --recursive" 58 print(" -R, -r or --recursive")
59 print " Perform a recursive search for source files." 59 print(" Perform a recursive search for source files.")
60 print " -t ext or --extension=ext" 60 print(" -t ext or --extension=ext")
61 print " Add the given extension to the list of file extensions." 61 print(" Add the given extension to the list of file extensions.")
62 print " This option may be given multiple times." 62 print(" This option may be given multiple times.")
63 print " -V or --version" 63 print(" -V or --version")
64 print " Show version information and exit." 64 print(" Show version information and exit.")
65 print " -x directory or --exclude=directory" 65 print(" -x directory or --exclude=directory")
66 print " Specify a directory basename to be excluded." 66 print(" Specify a directory basename to be excluded.")
67 print " This option may be repeated multiple times." 67 print(" This option may be repeated multiple times.")
68 print " --exclude-file=pattern" 68 print(" --exclude-file=pattern")
69 print " Specify a filename pattern of files to be excluded." 69 print(" Specify a filename pattern of files to be excluded.")
70 print " This option may be repeated multiple times." 70 print(" This option may be repeated multiple times.")
71 print " -l language or --language=language" 71 print(" -l language or --language=language")
72 print " Generate an API file for the given programming language." 72 print(" Generate an API file for the given programming language.")
73 print " Supported programming languages are:" 73 print(" Supported programming languages are:")
74 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()): 74 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()):
75 print " * %s" % lang 75 print(" * %s" % 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 \ 84 print("""eric4-api %s
85 """eric4-api %s
86 85
87 Eric4 API generator. 86 Eric4 API generator.
88 87
89 Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> 88 Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
90 This is free software; see the LICENSE.GPL3 for copying conditions. 89 This is free software; see the LICENSE.GPL3 for copying conditions.
91 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
92 PARTICULAR PURPOSE.""" % Version 91 PARTICULAR PURPOSE.""" % Version)
93 sys.exit(1) 92 sys.exit(1)
94 93
95 def main(): 94 def main():
96 """ 95 """
97 Main entry point into the application. 96 Main entry point into the application.
148 basePackage = v 147 basePackage = v
149 elif k in ["-p", "--private"]: 148 elif k in ["-p", "--private"]:
150 includePrivate = True 149 includePrivate = True
151 elif k in ["-l", "--language"]: 150 elif k in ["-l", "--language"]:
152 if v not in progLanguages: 151 if v not in progLanguages:
153 if v not in DocumentationTools.supportedExtensionsDictForApis.keys(): 152 if v not in list(DocumentationTools.supportedExtensionsDictForApis.keys()):
154 sys.stderr.write("Wrong language given: %s. Aborting\n" % v) 153 sys.stderr.write("Wrong language given: %s. Aborting\n" % v)
155 sys.exit(1) 154 sys.exit(1)
156 else: 155 else:
157 progLanguages.append(v) 156 progLanguages.append(v)
158 157
239 try: 238 try:
240 module = Utilities.ModuleParser.readModule(file, 239 module = Utilities.ModuleParser.readModule(file,
241 basename = basename, inpackage = inpackage) 240 basename = basename, inpackage = inpackage)
242 apiGenerator = APIGenerator(module) 241 apiGenerator = APIGenerator(module)
243 api = apiGenerator.genAPI(newStyle, basePackage, includePrivate) 242 api = apiGenerator.genAPI(newStyle, basePackage, includePrivate)
244 except IOError, v: 243 except IOError as v:
245 sys.stderr.write("%s error: %s\n" % (file, v[1])) 244 sys.stderr.write("%s error: %s\n" % (file, v[1]))
246 continue 245 continue
247 except ImportError, v: 246 except ImportError as v:
248 sys.stderr.write("%s error: %s\n" % (file, v)) 247 sys.stderr.write("%s error: %s\n" % (file, v))
249 continue 248 continue
250 249
251 for apiEntry in api: 250 for apiEntry in api:
252 if not apiEntry in apis: 251 if not apiEntry in apis:
255 254
256 outdir = os.path.dirname(outputFile) 255 outdir = os.path.dirname(outputFile)
257 if outdir and not os.path.exists(outdir): 256 if outdir and not os.path.exists(outdir):
258 os.makedirs(outdir) 257 os.makedirs(outdir)
259 try: 258 try:
260 out = open(outputFile, "wb") 259 out = open(outputFile, "w")
261 out.write(os.linesep.join(sorted(apis))) 260 out.write(os.linesep.join(sorted(apis)))
262 out.close() 261 out.close()
263 except IOError, v: 262 except IOError as v:
264 sys.stderr.write("%s error: %s\n" % (outputFile, v[1])) 263 sys.stderr.write("%s error: %s\n" % (outputFile, v[1]))
265 sys.exit(3) 264 sys.exit(3)
266 265
267 sys.stdout.write('\nDone.\n') 266 sys.stdout.write('\nDone.\n')
268 sys.exit(0) 267 sys.exit(0)

eric ide

mercurial