1414
1515
1616def main () -> None :
17- generators = {ep .name : ep for ep in entry_points (group = ' sqlacodegen.generators' )}
17+ generators = {ep .name : ep for ep in entry_points (group = " sqlacodegen.generators" )}
1818 parser = argparse .ArgumentParser (
19- description = 'Generates SQLAlchemy model code from an existing database.' )
20- parser .add_argument ('url' , nargs = '?' , help = 'SQLAlchemy url to the database' )
21- parser .add_argument ('--option' , nargs = '*' , help = "options passed to the generator class" )
22- parser .add_argument ('--version' , action = 'store_true' , help = "print the version number and exit" )
23- parser .add_argument ('--schemas' , help = 'load tables from the given schemas (comma separated)' )
24- parser .add_argument ('--generator' , choices = generators , default = 'declarative' ,
25- help = "generator class to use" )
26- parser .add_argument ('--tables' , help = 'tables to process (comma-separated, default: all)' )
27- parser .add_argument ('--noviews' , action = 'store_true' , help = "ignore views" )
28- parser .add_argument ('--outfile' , help = 'file to write output to (default: stdout)' )
19+ description = "Generates SQLAlchemy model code from an existing database."
20+ )
21+ parser .add_argument ("url" , nargs = "?" , help = "SQLAlchemy url to the database" )
22+ parser .add_argument (
23+ "--option" , nargs = "*" , help = "options passed to the generator class"
24+ )
25+ parser .add_argument (
26+ "--version" , action = "store_true" , help = "print the version number and exit"
27+ )
28+ parser .add_argument (
29+ "--schemas" , help = "load tables from the given schemas (comma separated)"
30+ )
31+ parser .add_argument (
32+ "--generator" ,
33+ choices = generators ,
34+ default = "declarative" ,
35+ help = "generator class to use" ,
36+ )
37+ parser .add_argument (
38+ "--tables" , help = "tables to process (comma-separated, default: all)"
39+ )
40+ parser .add_argument ("--noviews" , action = "store_true" , help = "ignore views" )
41+ parser .add_argument ("--outfile" , help = "file to write output to (default: stdout)" )
2942 args = parser .parse_args ()
3043
3144 if args .version :
32- print (version (' sqlacodegen' ))
45+ print (version (" sqlacodegen" ))
3346 return
3447 if not args .url :
35- print (' You must supply a url\n ' , file = sys .stderr )
48+ print (" You must supply a url\n " , file = sys .stderr )
3649 parser .print_help ()
3750 return
3851
3952 # Use reflection to fill in the metadata
4053 engine = create_engine (args .url )
4154 metadata = MetaData ()
42- tables = args .tables .split (',' ) if args .tables else None
43- schemas = args .schemas .split (',' ) if args .schemas else [None ]
55+ tables = args .tables .split ("," ) if args .tables else None
56+ schemas = args .schemas .split ("," ) if args .schemas else [None ]
4457 for schema in schemas :
4558 metadata .reflect (engine , schema , not args .noviews , tables )
4659
@@ -51,7 +64,7 @@ def main() -> None:
5164 # Open the target file (if given)
5265 with ExitStack () as stack :
5366 if args .outfile :
54- outfile = open (args .outfile , 'w' , encoding = ' utf-8' )
67+ outfile = open (args .outfile , "w" , encoding = " utf-8" )
5568 stack .enter_context (outfile )
5669 else :
5770 outfile = sys .stdout
0 commit comments