<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import re <EOL> from optparse import make_option <EOL> try : <EOL> set <EOL> except NameError : <EOL> from sets import Set as set <EOL> from django . core . management . base import BaseCommand <EOL> from django . core . management . color import no_style <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from south . migration import Migrations <EOL> from south . exceptions import NoMigrations <EOL> from south . creator import freezer <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , type = '<STR_LIT:string>' , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> usage_str = "<STR_LIT>" <EOL> def handle ( self , app = None , name = "<STR_LIT>" , freeze_list = None , stdout = False , verbosity = <NUM_LIT:1> , ** options ) : <EOL> verbosity = int ( verbosity ) <EOL> freeze_list = freeze_list or [ ] <EOL> if stdout : <EOL> name = "<STR_LIT:->" <EOL> if re . search ( '<STR_LIT>' , name ) and name != "<STR_LIT:->" : <EOL> self . error ( "<STR_LIT>" ) <EOL> if not name : <EOL> self . error ( "<STR_LIT>" + self . usage_str ) <EOL> if not app : <EOL> self . error ( "<STR_LIT>" + self . usage_str ) <EOL> try : <EOL> verbosity = int ( verbosity ) <EOL> except ValueError : <EOL> self . error ( "<STR_LIT>" + self . usage_str ) <EOL> migrations = Migrations ( app , force_creation = True , verbose_creation = verbosity > <NUM_LIT:0> ) <EOL> new_filename = migrations . next_filename ( name ) <EOL> apps_to_freeze = self . calc_frozen_apps ( migrations , freeze_list ) <EOL> file_contents = self . get_migration_template ( ) % { <EOL> "<STR_LIT>" : freezer . freeze_apps_to_string ( apps_to_freeze ) , <EOL> "<STR_LIT>" : apps_to_freeze and "<STR_LIT>" % ( "<STR_LIT:U+002CU+0020>" . join ( map ( repr , apps_to_freeze ) ) ) or "<STR_LIT>" <EOL> } <EOL> if name == "<STR_LIT:->" : <EOL> print ( file_contents ) <EOL> else : <EOL> fp = open ( os . path . join ( migrations . migrations_dir ( ) , new_filename ) , "<STR_LIT:w>" ) <EOL> fp . write ( file_contents ) <EOL> fp . close ( ) <EOL> print ( "<STR_LIT>" % new_filename , file = sys . stderr ) <EOL> def calc_frozen_apps ( self , migrations , freeze_list ) : <EOL> """<STR_LIT>""" <EOL> apps_to_freeze = [ ] <EOL> for to_freeze in freeze_list : <EOL> if "<STR_LIT:.>" in to_freeze : <EOL> self . error ( "<STR_LIT>" % to_freeze ) <EOL> if not models . get_app ( to_freeze ) : <EOL> self . error ( "<STR_LIT>" % to_freeze ) <EOL> apps_to_freeze . append ( to_freeze ) <EOL> if getattr ( settings , '<STR_LIT>' , True ) : <EOL> apps_to_freeze . append ( migrations . app_label ( ) ) <EOL> return apps_to_freeze <EOL> def error ( self , message , code = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> print ( message , file = sys . stderr ) <EOL> sys . exit ( code ) <EOL> def get_migration_template ( self ) : <EOL> return MIGRATION_TEMPLATE <EOL> MIGRATION_TEMPLATE = """<STR_LIT>""" </s>
