<s> """<STR_LIT>""" <EOL> import logging <EOL> from optparse import make_option <EOL> from django . conf import settings <EOL> from django . core . management . base import CommandError , BaseCommand <EOL> from six . moves import input , configparser <EOL> from django_extensions . management . utils import signalcommand <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT:user>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT:password>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , default = '<STR_LIT:default>' , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> @ signalcommand <EOL> def handle ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> if args : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> router = options . get ( '<STR_LIT>' ) <EOL> dbinfo = settings . DATABASES . get ( router ) <EOL> if dbinfo is None : <EOL> raise CommandError ( "<STR_LIT>" % router ) <EOL> engine = dbinfo . get ( '<STR_LIT>' ) . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> user = password = database_name = '<STR_LIT>' <EOL> if engine == '<STR_LIT>' : <EOL> read_default_file = dbinfo . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> if read_default_file : <EOL> config = configparser . ConfigParser ( ) <EOL> config . read ( read_default_file ) <EOL> user = config . get ( '<STR_LIT>' , '<STR_LIT:user>' ) <EOL> password = config . get ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> database_name = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> user = options . get ( '<STR_LIT:user>' ) or dbinfo . get ( '<STR_LIT>' ) or user <EOL> password = options . get ( '<STR_LIT:password>' ) or dbinfo . get ( '<STR_LIT>' ) or password <EOL> owner = options . get ( '<STR_LIT>' ) or user <EOL> database_name = options . get ( '<STR_LIT>' ) or dbinfo . get ( '<STR_LIT>' ) or database_name <EOL> if database_name == '<STR_LIT>' : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> database_host = dbinfo . get ( '<STR_LIT>' ) <EOL> database_port = dbinfo . get ( '<STR_LIT>' ) <EOL> verbosity = int ( options . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> if options . get ( '<STR_LIT>' ) : <EOL> confirm = input ( """<STR_LIT>""" % ( database_name , ) ) <EOL> else : <EOL> confirm = '<STR_LIT:yes>' <EOL> if confirm != '<STR_LIT:yes>' : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> if engine in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> import os <EOL> try : <EOL> logging . info ( "<STR_LIT>" % engine ) <EOL> os . unlink ( database_name ) <EOL> except OSError : <EOL> pass <EOL> elif engine in ( '<STR_LIT>' , ) : <EOL> import MySQLdb as Database <EOL> kwargs = { <EOL> '<STR_LIT:user>' : user , <EOL> '<STR_LIT>' : password , <EOL> } <EOL> if database_host . startswith ( '<STR_LIT:/>' ) : <EOL> kwargs [ '<STR_LIT>' ] = database_host <EOL> else : <EOL> kwargs [ '<STR_LIT:host>' ] = database_host <EOL> if database_port : <EOL> kwargs [ '<STR_LIT:port>' ] = int ( database_port ) <EOL> connection = Database . connect ( ** kwargs ) <EOL> drop_query = '<STR_LIT>' % database_name <EOL> utf8_support = options . get ( '<STR_LIT>' , False ) and '<STR_LIT>' or '<STR_LIT>' <EOL> create_query = '<STR_LIT>' % ( database_name , utf8_support ) <EOL> logging . info ( '<STR_LIT>' + drop_query + '<STR_LIT:">' ) <EOL> connection . query ( drop_query ) <EOL> logging . info ( '<STR_LIT>' + create_query + '<STR_LIT:">' ) <EOL> connection . query ( create_query ) <EOL> elif engine in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if engine == '<STR_LIT>' : <EOL> import psycopg as Database <EOL> elif engine in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> import psycopg2 as Database <EOL> conn_string = "<STR_LIT>" <EOL> if user : <EOL> conn_string += "<STR_LIT>" % user <EOL> if password : <EOL> conn_string += "<STR_LIT>" % password <EOL> if database_host : <EOL> conn_string += "<STR_LIT>" % database_host <EOL> if database_port : <EOL> conn_string += "<STR_LIT>" % database_port <EOL> connection = Database . connect ( conn_string ) <EOL> connection . set_isolation_level ( <NUM_LIT:0> ) <EOL> cursor = connection . cursor ( ) <EOL> drop_query = "<STR_LIT>" % database_name <EOL> logging . info ( '<STR_LIT>' + drop_query + '<STR_LIT:">' ) <EOL> try : <EOL> cursor . execute ( drop_query ) <EOL> except Database . ProgrammingError as e : <EOL> logging . exception ( "<STR_LIT>" % str ( e ) ) <EOL> create_query = "<STR_LIT>" % database_name <EOL> if owner : <EOL> create_query += "<STR_LIT>" % owner <EOL> create_query += "<STR_LIT>" <EOL> if engine == '<STR_LIT>' : <EOL> from django . contrib . gis . db . backends . postgis . creation import PostGISCreation <EOL> postgis_template = PostGISCreation ( connection ) . template_postgis <EOL> if postgis_template is not None : <EOL> create_query += '<STR_LIT>' % postgis_template <EOL> if settings . DEFAULT_TABLESPACE : <EOL> create_query += '<STR_LIT>' % settings . DEFAULT_TABLESPACE <EOL> else : <EOL> create_query += '<STR_LIT:;>' <EOL> logging . info ( '<STR_LIT>' + create_query + '<STR_LIT:">' ) <EOL> cursor . execute ( create_query ) <EOL> else : <EOL> raise CommandError ( "<STR_LIT>" % engine ) <EOL> if verbosity >= <NUM_LIT:2> or options . get ( '<STR_LIT>' ) : <EOL> print ( "<STR_LIT>" ) </s>
