eric5-api.py

changeset 253
3ccdf551bde7
parent 245
de5c4effc747
child 433
988006cb898f
child 792
a13346916170
equal deleted inserted replaced
252:05692e3d37bf 253:3ccdf551bde7
41 print("where files can be either python modules, package") 41 print("where files can be either python modules, package")
42 print("directories or ordinary directories.") 42 print("directories or ordinary directories.")
43 print() 43 print()
44 print("Options:") 44 print("Options:")
45 print() 45 print()
46 print(" -b name or --base name") 46 print(" -b name or --base=name")
47 print(" Use the given name as the name of the base package.") 47 print(" Use the given name as the name of the base package.")
48 print(" -e eol-type or --eol=eol-type")
49 print(" Use the given eol type to terminate lines.")
50 print(" Valid values are 'cr', 'lf' and 'crlf'.")
51 print(" --exclude-file=pattern")
52 print(" Specify a filename pattern of files to be excluded.")
53 print(" This option may be repeated multiple times.")
48 print(" -h or --help") 54 print(" -h or --help")
49 print(" Show this help and exit.") 55 print(" Show this help and exit.")
56 print(" -l language or --language=language")
57 print(" Generate an API file for the given programming language.")
58 print(" Supported programming languages are:")
50 print(" -o filename or --output=filename") 59 print(" -o filename or --output=filename")
51 print(" Write the API information to the named file. A '%L' placeholder") 60 print(" Write the API information to the named file. A '%L' placeholder")
52 print(" is replaced by the language of the API file (see --language).") 61 print(" is replaced by the language of the API file (see --language).")
53 print(" --oldstyle")
54 print(" Generate API files for QScintilla prior to 1.7.")
55 print(" -p or --private") 62 print(" -p or --private")
56 print(" Include private methods and functions.") 63 print(" Include private methods and functions.")
57 print(" -R, -r or --recursive") 64 print(" -R, -r or --recursive")
58 print(" Perform a recursive search for source files.") 65 print(" Perform a recursive search for source files.")
59 print(" -t ext or --extension=ext") 66 print(" -t ext or --extension=ext")
62 print(" -V or --version") 69 print(" -V or --version")
63 print(" Show version information and exit.") 70 print(" Show version information and exit.")
64 print(" -x directory or --exclude=directory") 71 print(" -x directory or --exclude=directory")
65 print(" Specify a directory basename to be excluded.") 72 print(" Specify a directory basename to be excluded.")
66 print(" This option may be repeated multiple times.") 73 print(" This option may be repeated multiple times.")
67 print(" --exclude-file=pattern")
68 print(" Specify a filename pattern of files to be excluded.")
69 print(" This option may be repeated multiple times.")
70 print(" -l language or --language=language")
71 print(" Generate an API file for the given programming language.")
72 print(" Supported programming languages are:")
73 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()): 74 for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()):
74 print(" * %s" % lang) 75 print(" * %s" % lang)
75 print(" The default is 'Python'.") 76 print(" The default is 'Python'.")
76 print(" This option may be repeated multiple times.") 77 print(" This option may be repeated multiple times.")
77 sys.exit(1) 78 sys.exit(1)
97 global supportedExtensions 98 global supportedExtensions
98 99
99 import getopt 100 import getopt
100 101
101 try: 102 try:
102 opts, args = getopt.getopt(sys.argv[1:], "b:hl:o:pRrt:Vx:", 103 opts, args = getopt.getopt(sys.argv[1:], "b:e:hl:o:pRrt:Vx:",
103 ["base=", "exclude=", "exclude-file=", "extension=", "help", 104 ["base=", "eol=", "exclude=", "exclude-file=", "extension=", "help",
104 "language=", "oldstyle", "output=", "private", "recursive", 105 "language=", "output=", "private", "recursive",
105 "version", ]) 106 "version", ])
106 except getopt.error: 107 except getopt.error:
107 usage() 108 usage()
108 109
109 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject", 110 excludeDirs = ["CVS", ".svn", "_svn", ".ropeproject", "_ropeproject",
110 ".eric5project", "_eric5project", "dist", "build", "doc", "docs"] 111 ".eric5project", "_eric5project", "dist", "build", "doc", "docs"]
111 excludePatterns = [] 112 excludePatterns = []
112 outputFileName = "" 113 outputFileName = ""
113 recursive = False 114 recursive = False
114 newStyle = True
115 basePackage = "" 115 basePackage = ""
116 includePrivate = False 116 includePrivate = False
117 progLanguages = [] 117 progLanguages = []
118 extensions = [] 118 extensions = []
119 newline = None
119 120
120 for k, v in opts: 121 for k, v in opts:
121 if k in ["-o", "--output"]: 122 if k in ["-o", "--output"]:
122 outputFileName = v 123 outputFileName = v
123 elif k in ["-R", "-r", "--recursive"]: 124 elif k in ["-R", "-r", "--recursive"]:
132 version() 133 version()
133 elif k in ["-t", "--extension"]: 134 elif k in ["-t", "--extension"]:
134 if not v.startswith("."): 135 if not v.startswith("."):
135 v = ".%s" % v 136 v = ".%s" % v
136 extensions.append(v) 137 extensions.append(v)
137 elif k in ["--oldstyle"]:
138 newStyle = False
139 elif k in ["-b", "--base"]: 138 elif k in ["-b", "--base"]:
140 basePackage = v 139 basePackage = v
141 elif k in ["-p", "--private"]: 140 elif k in ["-p", "--private"]:
142 includePrivate = True 141 includePrivate = True
143 elif k in ["-l", "--language"]: 142 elif k in ["-l", "--language"]:
144 if v not in progLanguages: 143 if v not in progLanguages:
145 if v not in list(DocumentationTools.supportedExtensionsDictForApis.keys()): 144 if v not in \
145 list(DocumentationTools.supportedExtensionsDictForApis.keys()):
146 sys.stderr.write("Wrong language given: %s. Aborting\n" % v) 146 sys.stderr.write("Wrong language given: %s. Aborting\n" % 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"]:
151 if v.lower() == "cr":
152 newline = '\r'
153 elif v.lower() == "lf":
154 newline = '\n'
155 elif v.lower() == "crlf":
156 newline = '\r\n'
150 157
151 if not args: 158 if not args:
152 usage() 159 usage()
153 160
154 if outputFileName == "": 161 if outputFileName == "":
230 237
231 try: 238 try:
232 module = Utilities.ModuleParser.readModule(file, 239 module = Utilities.ModuleParser.readModule(file,
233 basename = basename, inpackage = inpackage) 240 basename = basename, inpackage = inpackage)
234 apiGenerator = APIGenerator(module) 241 apiGenerator = APIGenerator(module)
235 api = apiGenerator.genAPI(newStyle, basePackage, includePrivate) 242 api = apiGenerator.genAPI(True, basePackage, includePrivate)
236 except IOError as v: 243 except IOError as v:
237 sys.stderr.write("%s error: %s\n" % (file, v[1])) 244 sys.stderr.write("%s error: %s\n" % (file, v[1]))
238 continue 245 continue
239 except ImportError as v: 246 except ImportError as v:
240 sys.stderr.write("%s error: %s\n" % (file, v)) 247 sys.stderr.write("%s error: %s\n" % (file, v))
247 254
248 outdir = os.path.dirname(outputFile) 255 outdir = os.path.dirname(outputFile)
249 if outdir and not os.path.exists(outdir): 256 if outdir and not os.path.exists(outdir):
250 os.makedirs(outdir) 257 os.makedirs(outdir)
251 try: 258 try:
252 out = open(outputFile, "w", encoding = "utf-8") 259 out = open(outputFile, "w", encoding = "utf-8", newline = newline)
253 out.write("\n".join(sorted(apis))) 260 out.write("\n".join(sorted(apis)) + "\n")
254 out.close() 261 out.close()
255 except IOError as v: 262 except IOError as v:
256 sys.stderr.write("%s error: %s\n" % (outputFile, v[1])) 263 sys.stderr.write("%s error: %s\n" % (outputFile, v[1]))
257 sys.exit(3) 264 sys.exit(3)
258 265

eric ide

mercurial