<s> from __future__ import unicode_literals <EOL> import sys <EOL> from importlib import import_module <EOL> from django . apps import apps <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . core . management . color import no_style <EOL> from django . core . management . sql import emit_post_migrate_signal , sql_flush <EOL> from django . db import DEFAULT_DB_ALIAS , connections , transaction <EOL> from django . utils import six <EOL> from django . utils . six . moves import input <EOL> class Command ( BaseCommand ) : <EOL> help = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def add_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT>' , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , default = DEFAULT_DB_ALIAS , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> def handle ( self , ** options ) : <EOL> database = options [ '<STR_LIT>' ] <EOL> connection = connections [ database ] <EOL> verbosity = options [ '<STR_LIT>' ] <EOL> interactive = options [ '<STR_LIT>' ] <EOL> reset_sequences = options . get ( '<STR_LIT>' , True ) <EOL> allow_cascade = options . get ( '<STR_LIT>' , False ) <EOL> inhibit_post_migrate = options . get ( '<STR_LIT>' , False ) <EOL> self . style = no_style ( ) <EOL> for app_config in apps . get_app_configs ( ) : <EOL> try : <EOL> import_module ( '<STR_LIT>' , app_config . name ) <EOL> except ImportError : <EOL> pass <EOL> sql_list = sql_flush ( self . style , connection , only_django = True , <EOL> reset_sequences = reset_sequences , <EOL> allow_cascade = allow_cascade ) <EOL> if interactive : <EOL> confirm = input ( """<STR_LIT>""" % connection . settings_dict [ '<STR_LIT>' ] ) <EOL> else : <EOL> confirm = '<STR_LIT:yes>' <EOL> if confirm == '<STR_LIT:yes>' : <EOL> try : <EOL> with transaction . atomic ( using = database , <EOL> savepoint = connection . features . can_rollback_ddl ) : <EOL> with connection . cursor ( ) as cursor : <EOL> for sql in sql_list : <EOL> cursor . execute ( sql ) <EOL> except Exception as e : <EOL> new_msg = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) % ( connection . settings_dict [ '<STR_LIT>' ] , e ) <EOL> six . reraise ( CommandError , CommandError ( new_msg ) , sys . exc_info ( ) [ <NUM_LIT:2> ] ) <EOL> if sql_list and not inhibit_post_migrate : <EOL> emit_post_migrate_signal ( verbosity , interactive , database ) <EOL> else : <EOL> self . stdout . write ( "<STR_LIT>" ) </s>
