<s> """<STR_LIT>""" <EOL> import sys <EOL> from django . conf import settings <EOL> from django . core . management . base import CommandError <EOL> from django . core . management . color import color_style <EOL> from django_extensions . compat import CompatibilityBaseCommand as BaseCommand <EOL> class Command ( BaseCommand ) : <EOL> help = """<STR_LIT>""" <EOL> requires_system_checks = False <EOL> can_import_settings = True <EOL> def add_arguments ( self , parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , default = '<STR_LIT:default>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT:all>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> def handle ( self , * args , ** options ) : <EOL> self . style = color_style ( ) <EOL> all_routers = options . get ( '<STR_LIT:all>' ) <EOL> if all_routers : <EOL> routers = settings . DATABASES . keys ( ) <EOL> else : <EOL> routers = [ options . get ( '<STR_LIT>' ) ] <EOL> for i , router in enumerate ( routers ) : <EOL> if i != <NUM_LIT:0> : <EOL> sys . stdout . write ( "<STR_LIT:\n>" ) <EOL> self . show_dsn ( router , options ) <EOL> def show_dsn ( self , router , options ) : <EOL> dbinfo = settings . DATABASES . get ( router ) <EOL> quiet = options . get ( '<STR_LIT>' ) <EOL> dsn_style = options . get ( '<STR_LIT>' ) <EOL> if dbinfo is None : <EOL> raise CommandError ( "<STR_LIT>" % router ) <EOL> engine = dbinfo . get ( '<STR_LIT>' ) . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> dbuser = dbinfo . get ( '<STR_LIT>' ) <EOL> dbpass = dbinfo . get ( '<STR_LIT>' ) <EOL> dbname = dbinfo . get ( '<STR_LIT>' ) <EOL> dbhost = dbinfo . get ( '<STR_LIT>' ) <EOL> dbport = dbinfo . get ( '<STR_LIT>' ) <EOL> dsn = [ ] <EOL> if engine == '<STR_LIT>' : <EOL> dsnstr = '<STR_LIT>' <EOL> if dbport is not None : <EOL> dsnstr += '<STR_LIT>' <EOL> dsn . append ( dsnstr . format ( dbhost , <EOL> dbport , <EOL> dbname , <EOL> dbuser , <EOL> dbpass ) ) <EOL> elif engine in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> dsn = self . postgresql ( dbhost , dbport , dbname , dbuser , dbpass , dsn_style = dsn_style ) <EOL> elif engine == '<STR_LIT>' : <EOL> dsn . append ( '<STR_LIT:{}>' . format ( dbname ) ) <EOL> else : <EOL> dsn . append ( self . style . ERROR ( '<STR_LIT>' '<STR_LIT>' ) ) <EOL> if not quiet : <EOL> sys . stdout . write ( self . style . SQL_TABLE ( "<STR_LIT>" % ( router , engine ) ) ) <EOL> for output in dsn : <EOL> sys . stdout . write ( "<STR_LIT>" . format ( output ) ) <EOL> def postgresql ( self , dbhost , dbport , dbname , dbuser , dbpass , dsn_style = None ) : <EOL> """<STR_LIT>""" <EOL> dsn = [ ] <EOL> if dsn_style is None or dsn_style == '<STR_LIT:all>' or dsn_style == '<STR_LIT>' : <EOL> dsnstr = "<STR_LIT>" <EOL> if dbport is not None : <EOL> dsnstr += "<STR_LIT>" <EOL> dsn . append ( dsnstr . format ( dbhost , <EOL> dbport , <EOL> dbname , <EOL> dbuser , <EOL> dbpass , ) ) <EOL> if dsn_style == '<STR_LIT:all>' or dsn_style == '<STR_LIT>' : <EOL> dsnstr = "<STR_LIT>" <EOL> if dbport is not None : <EOL> dsnstr += "<STR_LIT>" <EOL> dsn . append ( dsnstr . format ( dbhost , <EOL> dbport , <EOL> dbname , <EOL> dbuser , <EOL> dbpass ) ) <EOL> if dsn_style == '<STR_LIT:all>' or dsn_style == '<STR_LIT>' : <EOL> if dbport is not None : <EOL> dsnstr = "<STR_LIT>" <EOL> else : <EOL> dsnstr = "<STR_LIT>" <EOL> dsn . append ( dsnstr . format ( dbhost , <EOL> dbport , <EOL> dbname , <EOL> dbuser , <EOL> dbpass , ) ) <EOL> if dsn_style == '<STR_LIT:all>' or dsn_style == '<STR_LIT>' : <EOL> if dbport is not None : <EOL> dbport = <NUM_LIT> <EOL> dsn . append ( '<STR_LIT>' . format ( dbhost , <EOL> dbport , <EOL> dbname , <EOL> dbuser , <EOL> dbpass ) ) <EOL> return dsn </s>
