<s> from django . conf import settings <EOL> from django . db import connection <EOL> from south import migration <EOL> from south . migration . base import Migrations <EOL> from south . management . commands . migrate import Command as MigrateCommand <EOL> from tenant_schemas . management . commands import SyncCommon <EOL> from tenant_schemas . utils import get_tenant_model , get_public_schema_name <EOL> class Command ( SyncCommon ) : <EOL> help = "<STR_LIT>" <EOL> option_list = MigrateCommand . option_list + SyncCommon . option_list <EOL> def handle ( self , * args , ** options ) : <EOL> super ( Command , self ) . handle ( * args , ** options ) <EOL> if self . sync_public : <EOL> self . migrate_public_apps ( ) <EOL> if self . sync_tenant : <EOL> self . migrate_tenant_apps ( self . schema_name ) <EOL> def _set_managed_apps ( self , included_apps , excluded_apps ) : <EOL> """<STR_LIT>""" <EOL> ignored_apps = [ ] <EOL> if excluded_apps : <EOL> for item in excluded_apps : <EOL> if item not in included_apps : <EOL> ignored_apps . append ( item ) <EOL> for app in ignored_apps : <EOL> app_label = app . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> settings . SOUTH_MIGRATION_MODULES [ app_label ] = '<STR_LIT:ignore>' <EOL> self . _clear_south_cache ( ) <EOL> def _save_south_settings ( self ) : <EOL> self . _old_south_modules = None <EOL> if hasattr ( settings , "<STR_LIT>" ) and settings . SOUTH_MIGRATION_MODULES is not None : <EOL> self . _old_south_modules = settings . SOUTH_MIGRATION_MODULES . copy ( ) <EOL> else : <EOL> settings . SOUTH_MIGRATION_MODULES = dict ( ) <EOL> def _restore_south_settings ( self ) : <EOL> settings . SOUTH_MIGRATION_MODULES = self . _old_south_modules <EOL> def _clear_south_cache ( self ) : <EOL> for mig in list ( migration . all_migrations ( ) ) : <EOL> delattr ( mig . _application , "<STR_LIT>" ) <EOL> Migrations . _clear_cache ( ) <EOL> def _migrate_schema ( self , tenant ) : <EOL> connection . set_tenant ( tenant , include_public = True ) <EOL> MigrateCommand ( ) . execute ( * self . args , ** self . options ) <EOL> def migrate_tenant_apps ( self , schema_name = None ) : <EOL> self . _save_south_settings ( ) <EOL> apps = self . tenant_apps or self . installed_apps <EOL> self . _set_managed_apps ( included_apps = apps , excluded_apps = self . shared_apps ) <EOL> if schema_name : <EOL> self . _notice ( "<STR_LIT>" % schema_name ) <EOL> connection . set_schema_to_public ( ) <EOL> tenant = get_tenant_model ( ) . objects . get ( schema_name = schema_name ) <EOL> self . _migrate_schema ( tenant ) <EOL> else : <EOL> all_tenants = get_tenant_model ( ) . objects . exclude ( schema_name = get_public_schema_name ( ) ) <EOL> if not all_tenants : <EOL> self . _notice ( "<STR_LIT>" ) <EOL> for tenant in all_tenants : <EOL> Migrations . _dependencies_done = False <EOL> self . _notice ( "<STR_LIT>" % tenant . schema_name ) <EOL> self . _migrate_schema ( tenant ) <EOL> self . _restore_south_settings ( ) <EOL> def migrate_public_apps ( self ) : <EOL> self . _save_south_settings ( ) <EOL> apps = self . shared_apps or self . installed_apps <EOL> self . _set_managed_apps ( included_apps = apps , excluded_apps = self . tenant_apps ) <EOL> self . _notice ( "<STR_LIT>" ) <EOL> MigrateCommand ( ) . execute ( * self . args , ** self . options ) <EOL> self . _clear_south_cache ( ) <EOL> self . _restore_south_settings ( ) </s>
