<s> from __future__ import unicode_literals <EOL> import django <EOL> from django . conf import settings <EOL> from django . core . cache import InvalidCacheBackendError , caches <EOL> from django . core . management import BaseCommand , CommandError <EOL> from django_mysql . cache import MySQLCache <EOL> from django_mysql . utils import collapse_spaces <EOL> class Command ( BaseCommand ) : <EOL> args = "<STR_LIT>" <EOL> help = collapse_spaces ( """<STR_LIT>""" ) <EOL> if django . VERSION [ : <NUM_LIT:2> ] >= ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> def add_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> def handle ( self , * args , ** options ) : <EOL> if django . VERSION [ : <NUM_LIT:2> ] >= ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> aliases = set ( options [ '<STR_LIT>' ] ) <EOL> else : <EOL> aliases = set ( args ) <EOL> if not aliases : <EOL> aliases = settings . CACHES <EOL> tables = set ( ) <EOL> for alias in aliases : <EOL> try : <EOL> cache = caches [ alias ] <EOL> except InvalidCacheBackendError : <EOL> raise CommandError ( "<STR_LIT>" . format ( alias ) ) <EOL> if not isinstance ( cache , MySQLCache ) : <EOL> continue <EOL> tables . add ( cache . _table ) <EOL> if not tables : <EOL> self . stderr . write ( "<STR_LIT>" ) <EOL> return <EOL> migration = self . render_migration ( tables ) <EOL> self . stdout . write ( migration ) <EOL> def render_migration ( self , tables ) : <EOL> out = [ header ] <EOL> for table in tables : <EOL> out . append ( <EOL> table_operation . replace ( '<STR_LIT>' , table ) <EOL> ) <EOL> out . append ( footer ) <EOL> return '<STR_LIT>' . join ( out ) <EOL> header = '''<STR_LIT>''' . strip ( ) <EOL> create_table_sql = '<STR_LIT:\n>' . join ( <EOL> '<STR_LIT:U+0020>' * <NUM_LIT:3> + line <EOL> for line in MySQLCache . create_table_sql . splitlines ( ) <EOL> ) . format ( table_name = '<STR_LIT>' ) <EOL> table_operation = '''<STR_LIT>''' + create_table_sql + '''<STR_LIT>''' . rstrip ( ) <EOL> footer = '''<STR_LIT>''' </s>
