<s> import django <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> import os , re , shutil , sys , textwrap <EOL> from optparse import OptionParser <EOL> from django . utils import termcolors <EOL> if not hasattr ( __builtins__ , '<STR_LIT>' ) : <EOL> from sets import Set as set <EOL> MODULE_TEMPLATE = '''<STR_LIT>''' <EOL> APP_ARGS = '<STR_LIT>' <EOL> PROJECT_TEMPLATE_DIR = os . path . join ( django . __path__ [ <NUM_LIT:0> ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> INVALID_PROJECT_NAMES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> class dummy : pass <EOL> style = dummy ( ) <EOL> style . ERROR = termcolors . make_style ( fg = '<STR_LIT>' , opts = ( '<STR_LIT>' , ) ) <EOL> style . ERROR_OUTPUT = termcolors . make_style ( fg = '<STR_LIT>' , opts = ( '<STR_LIT>' , ) ) <EOL> style . NOTICE = termcolors . make_style ( fg = '<STR_LIT>' ) <EOL> style . SQL_FIELD = termcolors . make_style ( fg = '<STR_LIT>' , opts = ( '<STR_LIT>' , ) ) <EOL> style . SQL_COLTYPE = termcolors . make_style ( fg = '<STR_LIT>' ) <EOL> style . SQL_KEYWORD = termcolors . make_style ( fg = '<STR_LIT>' ) <EOL> style . SQL_TABLE = termcolors . make_style ( opts = ( '<STR_LIT>' , ) ) <EOL> del dummy <EOL> def disable_termcolors ( ) : <EOL> class dummy : <EOL> def __getattr__ ( self , attr ) : <EOL> return lambda x : x <EOL> global style <EOL> style = dummy ( ) <EOL> if sys . platform == '<STR_LIT:win32>' or sys . platform == '<STR_LIT>' or not sys . stdout . isatty ( ) : <EOL> disable_termcolors ( ) <EOL> def _is_valid_dir_name ( s ) : <EOL> return bool ( re . search ( r'<STR_LIT>' , s ) ) <EOL> def _get_installed_models ( table_list ) : <EOL> "<STR_LIT>" <EOL> from django . db import models <EOL> all_models = [ ] <EOL> for app in models . get_apps ( ) : <EOL> for model in models . get_models ( app ) : <EOL> all_models . append ( model ) <EOL> return set ( [ m for m in all_models if m . _meta . db_table in table_list ] ) <EOL> def _get_table_list ( ) : <EOL> "<STR_LIT>" <EOL> from django . db import connection , get_introspection_module <EOL> cursor = connection . cursor ( ) <EOL> return get_introspection_module ( ) . get_table_list ( cursor ) <EOL> def _get_sequence_list ( ) : <EOL> "<STR_LIT>" <EOL> from django . db import models <EOL> apps = models . get_apps ( ) <EOL> sequence_list = [ ] <EOL> for app in apps : <EOL> for model in models . get_models ( app ) : <EOL> for f in model . _meta . fields : <EOL> if isinstance ( f , models . AutoField ) : <EOL> sequence_list . append ( { '<STR_LIT>' : model . _meta . db_table , '<STR_LIT>' : f . column , } ) <EOL> break <EOL> for f in model . _meta . many_to_many : <EOL> sequence_list . append ( { '<STR_LIT>' : f . m2m_db_table ( ) , '<STR_LIT>' : None , } ) <EOL> return sequence_list <EOL> get_rel_data_type = lambda f : ( f . get_internal_type ( ) in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) and '<STR_LIT>' or f . get_internal_type ( ) <EOL> def get_version ( ) : <EOL> "<STR_LIT>" <EOL> from django import VERSION <EOL> v = '<STR_LIT:.>' . join ( [ str ( i ) for i in VERSION [ : - <NUM_LIT:1> ] ] ) <EOL> if VERSION [ - <NUM_LIT:1> ] : <EOL> v += '<STR_LIT:->' + VERSION [ - <NUM_LIT:1> ] <EOL> return v <EOL> def get_sql_create ( app ) : <EOL> "<STR_LIT>" <EOL> from django . db import get_creation_module , models <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> if not data_types : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> app_models = models . get_models ( app ) <EOL> final_output = [ ] <EOL> known_models = set ( [ model for model in _get_installed_models ( _get_table_list ( ) ) if model not in app_models ] ) <EOL> pending_references = { } <EOL> for model in app_models : <EOL> output , references = _get_sql_model_create ( model , known_models ) <EOL> final_output . extend ( output ) <EOL> for refto , refs in references . items ( ) : <EOL> pending_references . setdefault ( refto , [ ] ) . extend ( refs ) <EOL> final_output . extend ( _get_sql_for_pending_references ( model , pending_references ) ) <EOL> known_models . add ( model ) <EOL> for model in app_models : <EOL> final_output . extend ( _get_many_to_many_sql_for_model ( model ) ) <EOL> not_installed_models = set ( pending_references . keys ( ) ) <EOL> if not_installed_models : <EOL> alter_sql = [ ] <EOL> for model in not_installed_models : <EOL> alter_sql . extend ( [ '<STR_LIT>' + sql for sql in <EOL> _get_sql_for_pending_references ( model , pending_references ) ] ) <EOL> if alter_sql : <EOL> final_output . append ( '<STR_LIT>' ) <EOL> final_output . extend ( alter_sql ) <EOL> return final_output <EOL> get_sql_create . help_doc = "<STR_LIT>" <EOL> get_sql_create . args = APP_ARGS <EOL> def _get_sql_model_create ( model , known_models = set ( ) ) : <EOL> """<STR_LIT>""" <EOL> from django . db import backend , get_creation_module , models <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> opts = model . _meta <EOL> final_output = [ ] <EOL> table_output = [ ] <EOL> pending_references = { } <EOL> for f in opts . fields : <EOL> if isinstance ( f , ( models . ForeignKey , models . OneToOneField ) ) : <EOL> rel_field = f . rel . get_related_field ( ) <EOL> data_type = get_rel_data_type ( rel_field ) <EOL> else : <EOL> rel_field = f <EOL> data_type = f . get_internal_type ( ) <EOL> col_type = data_types [ data_type ] <EOL> if col_type is not None : <EOL> field_output = [ style . SQL_FIELD ( backend . quote_name ( f . column ) ) , <EOL> style . SQL_COLTYPE ( col_type % rel_field . __dict__ ) ] <EOL> field_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' % ( not f . null and '<STR_LIT>' or '<STR_LIT>' ) ) ) <EOL> if f . unique : <EOL> field_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' ) ) <EOL> if f . primary_key : <EOL> field_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' ) ) <EOL> if f . rel : <EOL> if f . rel . to in known_models : <EOL> field_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT:U+0020>' + style . SQL_TABLE ( backend . quote_name ( f . rel . to . _meta . db_table ) ) + '<STR_LIT>' + style . SQL_FIELD ( backend . quote_name ( f . rel . to . _meta . get_field ( f . rel . field_name ) . column ) ) + '<STR_LIT:)>' + <EOL> backend . get_deferrable_sql ( ) <EOL> ) <EOL> else : <EOL> pr = pending_references . setdefault ( f . rel . to , [ ] ) . append ( ( model , f ) ) <EOL> table_output . append ( '<STR_LIT:U+0020>' . join ( field_output ) ) <EOL> if opts . order_with_respect_to : <EOL> table_output . append ( style . SQL_FIELD ( backend . quote_name ( '<STR_LIT>' ) ) + '<STR_LIT:U+0020>' + style . SQL_COLTYPE ( data_types [ '<STR_LIT>' ] ) + '<STR_LIT:U+0020>' + style . SQL_KEYWORD ( '<STR_LIT>' ) ) <EOL> for field_constraints in opts . unique_together : <EOL> table_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT>' % "<STR_LIT:U+002CU+0020>" . join ( [ backend . quote_name ( style . SQL_FIELD ( opts . get_field ( f ) . column ) ) for f in field_constraints ] ) ) <EOL> full_statement = [ style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT:U+0020>' + style . SQL_TABLE ( backend . quote_name ( opts . db_table ) ) + '<STR_LIT>' ] <EOL> for i , line in enumerate ( table_output ) : <EOL> full_statement . append ( '<STR_LIT>' % ( line , i < len ( table_output ) - <NUM_LIT:1> and '<STR_LIT:U+002C>' or '<STR_LIT>' ) ) <EOL> full_statement . append ( '<STR_LIT>' ) <EOL> final_output . append ( '<STR_LIT:\n>' . join ( full_statement ) ) <EOL> return final_output , pending_references <EOL> def _get_sql_for_pending_references ( model , pending_references ) : <EOL> """<STR_LIT>""" <EOL> from django . db import backend , get_creation_module <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> final_output = [ ] <EOL> if backend . supports_constraints : <EOL> opts = model . _meta <EOL> if model in pending_references : <EOL> for rel_class , f in pending_references [ model ] : <EOL> rel_opts = rel_class . _meta <EOL> r_table = rel_opts . db_table <EOL> r_col = f . column <EOL> table = opts . db_table <EOL> col = opts . get_field ( f . rel . field_name ) . column <EOL> r_name = '<STR_LIT>' % ( r_col , col , abs ( hash ( ( r_table , table ) ) ) ) <EOL> final_output . append ( style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT>' % ( backend . quote_name ( r_table ) , r_name , <EOL> backend . quote_name ( r_col ) , backend . quote_name ( table ) , backend . quote_name ( col ) , <EOL> backend . get_deferrable_sql ( ) ) ) <EOL> del pending_references [ model ] <EOL> return final_output <EOL> def _get_many_to_many_sql_for_model ( model ) : <EOL> from django . db import backend , get_creation_module <EOL> from django . db . models import GenericRel <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> opts = model . _meta <EOL> final_output = [ ] <EOL> for f in opts . many_to_many : <EOL> if not isinstance ( f . rel , GenericRel ) : <EOL> table_output = [ style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT:U+0020>' + style . SQL_TABLE ( backend . quote_name ( f . m2m_db_table ( ) ) ) + '<STR_LIT>' ] <EOL> table_output . append ( '<STR_LIT>' % ( style . SQL_FIELD ( backend . quote_name ( '<STR_LIT:id>' ) ) , <EOL> style . SQL_COLTYPE ( data_types [ '<STR_LIT>' ] ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) ) ) <EOL> table_output . append ( '<STR_LIT>' % ( style . SQL_FIELD ( backend . quote_name ( f . m2m_column_name ( ) ) ) , <EOL> style . SQL_COLTYPE ( data_types [ get_rel_data_type ( opts . pk ) ] % opts . pk . __dict__ ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( opts . db_table ) ) , <EOL> style . SQL_FIELD ( backend . quote_name ( opts . pk . column ) ) , <EOL> backend . get_deferrable_sql ( ) ) ) <EOL> table_output . append ( '<STR_LIT>' % ( style . SQL_FIELD ( backend . quote_name ( f . m2m_reverse_name ( ) ) ) , <EOL> style . SQL_COLTYPE ( data_types [ get_rel_data_type ( f . rel . to . _meta . pk ) ] % f . rel . to . _meta . pk . __dict__ ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( f . rel . to . _meta . db_table ) ) , <EOL> style . SQL_FIELD ( backend . quote_name ( f . rel . to . _meta . pk . column ) ) , <EOL> backend . get_deferrable_sql ( ) ) ) <EOL> table_output . append ( '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( backend . quote_name ( f . m2m_column_name ( ) ) ) , <EOL> style . SQL_FIELD ( backend . quote_name ( f . m2m_reverse_name ( ) ) ) ) ) <EOL> table_output . append ( '<STR_LIT>' ) <EOL> final_output . append ( '<STR_LIT:\n>' . join ( table_output ) ) <EOL> return final_output <EOL> def get_sql_delete ( app ) : <EOL> "<STR_LIT>" <EOL> from django . db import backend , connection , models , get_introspection_module <EOL> introspection = get_introspection_module ( ) <EOL> try : <EOL> cursor = connection . cursor ( ) <EOL> except : <EOL> cursor = None <EOL> if cursor : <EOL> table_names = introspection . get_table_list ( cursor ) <EOL> else : <EOL> table_names = [ ] <EOL> output = [ ] <EOL> to_delete = set ( ) <EOL> references_to_delete = { } <EOL> app_models = models . get_models ( app ) <EOL> for model in app_models : <EOL> if cursor and model . _meta . db_table in table_names : <EOL> opts = model . _meta <EOL> for f in opts . fields : <EOL> if f . rel and f . rel . to not in to_delete : <EOL> references_to_delete . setdefault ( f . rel . to , [ ] ) . append ( ( model , f ) ) <EOL> to_delete . add ( model ) <EOL> for model in app_models : <EOL> if cursor and model . _meta . db_table in table_names : <EOL> output . append ( '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( model . _meta . db_table ) ) ) ) <EOL> if backend . supports_constraints and references_to_delete . has_key ( model ) : <EOL> for rel_class , f in references_to_delete [ model ] : <EOL> table = rel_class . _meta . db_table <EOL> col = f . column <EOL> r_table = model . _meta . db_table <EOL> r_col = model . _meta . get_field ( f . rel . field_name ) . column <EOL> output . append ( '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( table ) ) , <EOL> style . SQL_KEYWORD ( backend . get_drop_foreignkey_sql ( ) ) , <EOL> style . SQL_FIELD ( backend . quote_name ( '<STR_LIT>' % ( col , r_col , abs ( hash ( ( table , r_table ) ) ) ) ) ) ) ) <EOL> del references_to_delete [ model ] <EOL> for model in app_models : <EOL> opts = model . _meta <EOL> for f in opts . many_to_many : <EOL> if cursor and f . m2m_db_table ( ) in table_names : <EOL> output . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( f . m2m_db_table ( ) ) ) ) ) <EOL> app_label = app_models [ <NUM_LIT:0> ] . _meta . app_label <EOL> if cursor : <EOL> cursor . close ( ) <EOL> connection . close ( ) <EOL> return output [ : : - <NUM_LIT:1> ] <EOL> get_sql_delete . help_doc = "<STR_LIT>" <EOL> get_sql_delete . args = APP_ARGS <EOL> def get_sql_reset ( app ) : <EOL> "<STR_LIT>" <EOL> return get_sql_delete ( app ) + get_sql_all ( app ) <EOL> get_sql_reset . help_doc = "<STR_LIT>" <EOL> get_sql_reset . args = APP_ARGS <EOL> def get_sql_flush ( ) : <EOL> "<STR_LIT>" <EOL> from django . db import backend <EOL> statements = backend . get_sql_flush ( style , _get_table_list ( ) , _get_sequence_list ( ) ) <EOL> return statements <EOL> get_sql_flush . help_doc = "<STR_LIT>" <EOL> get_sql_flush . args = '<STR_LIT>' <EOL> def get_custom_sql_for_model ( model ) : <EOL> from django . db import models <EOL> from django . conf import settings <EOL> opts = model . _meta <EOL> app_dir = os . path . normpath ( os . path . join ( os . path . dirname ( models . get_app ( model . _meta . app_label ) . __file__ ) , '<STR_LIT>' ) ) <EOL> output = [ ] <EOL> statements = re . compile ( r"<STR_LIT>" , re . M ) <EOL> sql_files = [ os . path . join ( app_dir , "<STR_LIT>" % ( opts . object_name . lower ( ) , settings . DATABASE_ENGINE ) ) , <EOL> os . path . join ( app_dir , "<STR_LIT>" % opts . object_name . lower ( ) ) ] <EOL> for sql_file in sql_files : <EOL> if os . path . exists ( sql_file ) : <EOL> fp = open ( sql_file , '<STR_LIT>' ) <EOL> for statement in statements . split ( fp . read ( ) ) : <EOL> statement = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , statement ) <EOL> if statement . strip ( ) : <EOL> output . append ( statement + "<STR_LIT:;>" ) <EOL> fp . close ( ) <EOL> return output <EOL> def get_custom_sql ( app ) : <EOL> "<STR_LIT>" <EOL> from django . db . models import get_models <EOL> output = [ ] <EOL> app_models = get_models ( app ) <EOL> app_dir = os . path . normpath ( os . path . join ( os . path . dirname ( app . __file__ ) , '<STR_LIT>' ) ) <EOL> for model in app_models : <EOL> output . extend ( get_custom_sql_for_model ( model ) ) <EOL> return output <EOL> get_custom_sql . help_doc = "<STR_LIT>" <EOL> get_custom_sql . args = APP_ARGS <EOL> def get_sql_initial_data ( apps ) : <EOL> "<STR_LIT>" <EOL> return style . ERROR ( "<STR_LIT>" % '<STR_LIT:U+0020>' . join ( apps and apps or [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> get_sql_initial_data . help_doc = "<STR_LIT>" <EOL> get_sql_initial_data . args = '<STR_LIT>' <EOL> def get_sql_sequence_reset ( app ) : <EOL> "<STR_LIT>" <EOL> from django . db import backend , models <EOL> output = [ ] <EOL> for model in models . get_models ( app ) : <EOL> for f in model . _meta . fields : <EOL> if isinstance ( f , models . AutoField ) : <EOL> output . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( '<STR_LIT>' % ( model . _meta . db_table , f . column ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( backend . quote_name ( f . column ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( backend . quote_name ( model . _meta . db_table ) ) ) ) <EOL> break <EOL> for f in model . _meta . many_to_many : <EOL> output . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( '<STR_LIT>' % f . m2m_db_table ( ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( backend . quote_name ( '<STR_LIT:id>' ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( f . m2m_db_table ( ) ) ) ) <EOL> return output <EOL> get_sql_sequence_reset . help_doc = "<STR_LIT>" <EOL> get_sql_sequence_reset . args = APP_ARGS <EOL> def get_sql_indexes ( app ) : <EOL> "<STR_LIT>" <EOL> from django . db import models <EOL> output = [ ] <EOL> for model in models . get_models ( app ) : <EOL> output . extend ( get_sql_indexes_for_model ( model ) ) <EOL> return output <EOL> get_sql_indexes . help_doc = "<STR_LIT>" <EOL> get_sql_indexes . args = APP_ARGS <EOL> def get_sql_indexes_for_model ( model ) : <EOL> "<STR_LIT>" <EOL> from django . db import backend <EOL> output = [ ] <EOL> for f in model . _meta . fields : <EOL> if f . db_index : <EOL> unique = f . unique and '<STR_LIT>' or '<STR_LIT>' <EOL> output . append ( <EOL> style . SQL_KEYWORD ( '<STR_LIT>' % unique ) + '<STR_LIT:U+0020>' + style . SQL_TABLE ( '<STR_LIT>' % ( model . _meta . db_table , f . column ) ) + '<STR_LIT:U+0020>' + style . SQL_KEYWORD ( '<STR_LIT>' ) + '<STR_LIT:U+0020>' + style . SQL_TABLE ( backend . quote_name ( model . _meta . db_table ) ) + '<STR_LIT:U+0020>' + "<STR_LIT>" % style . SQL_FIELD ( backend . quote_name ( f . column ) ) <EOL> ) <EOL> return output <EOL> def get_sql_all ( app ) : <EOL> "<STR_LIT>" <EOL> return get_sql_create ( app ) + get_custom_sql ( app ) + get_sql_indexes ( app ) <EOL> get_sql_all . help_doc = "<STR_LIT>" <EOL> get_sql_all . args = APP_ARGS <EOL> def _emit_post_sync_signal ( created_models , verbosity , interactive ) : <EOL> from django . db import models <EOL> from django . dispatch import dispatcher <EOL> for app in models . get_apps ( ) : <EOL> app_name = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> if verbosity >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" , app_name <EOL> dispatcher . send ( signal = models . signals . post_syncdb , sender = app , <EOL> app = app , created_models = created_models , <EOL> verbosity = verbosity , interactive = interactive ) <EOL> def syncdb ( verbosity = <NUM_LIT:1> , interactive = True ) : <EOL> "<STR_LIT>" <EOL> from django . db import connection , transaction , models , get_creation_module <EOL> from django . conf import settings <EOL> disable_termcolors ( ) <EOL> _check_for_validation_errors ( ) <EOL> for app_name in settings . INSTALLED_APPS : <EOL> try : <EOL> __import__ ( app_name + '<STR_LIT>' , { } , { } , [ '<STR_LIT>' ] ) <EOL> except ImportError : <EOL> pass <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> cursor = connection . cursor ( ) <EOL> table_list = _get_table_list ( ) <EOL> seen_models = _get_installed_models ( table_list ) <EOL> created_models = set ( ) <EOL> pending_references = { } <EOL> for app in models . get_apps ( ) : <EOL> app_name = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> model_list = models . get_models ( app ) <EOL> for model in model_list : <EOL> if verbosity >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" % ( app_name , model . _meta . object_name ) <EOL> if model . _meta . db_table in table_list : <EOL> continue <EOL> sql , references = _get_sql_model_create ( model , seen_models ) <EOL> seen_models . add ( model ) <EOL> created_models . add ( model ) <EOL> for refto , refs in references . items ( ) : <EOL> pending_references . setdefault ( refto , [ ] ) . extend ( refs ) <EOL> sql . extend ( _get_sql_for_pending_references ( model , pending_references ) ) <EOL> if verbosity >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % model . _meta . db_table <EOL> for statement in sql : <EOL> cursor . execute ( statement ) <EOL> table_list . append ( model . _meta . db_table ) <EOL> for app in models . get_apps ( ) : <EOL> app_name = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> model_list = models . get_models ( app ) <EOL> for model in model_list : <EOL> if model in created_models : <EOL> sql = _get_many_to_many_sql_for_model ( model ) <EOL> if sql : <EOL> if verbosity >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" % ( app_name , model . _meta . object_name ) <EOL> for statement in sql : <EOL> cursor . execute ( statement ) <EOL> transaction . commit_unless_managed ( ) <EOL> _emit_post_sync_signal ( created_models , verbosity , interactive ) <EOL> for app in models . get_apps ( ) : <EOL> for model in models . get_models ( app ) : <EOL> if model in created_models : <EOL> custom_sql = get_custom_sql_for_model ( model ) <EOL> if custom_sql : <EOL> if verbosity >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( app_name , model . _meta . object_name ) <EOL> try : <EOL> for sql in custom_sql : <EOL> cursor . execute ( sql ) <EOL> except Exception , e : <EOL> sys . stderr . write ( "<STR_LIT>" % ( app_name , model . _meta . object_name , e ) ) <EOL> transaction . rollback_unless_managed ( ) <EOL> else : <EOL> transaction . commit_unless_managed ( ) <EOL> for app in models . get_apps ( ) : <EOL> app_name = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> for model in models . get_models ( app ) : <EOL> if model in created_models : <EOL> index_sql = get_sql_indexes_for_model ( model ) <EOL> if index_sql : <EOL> if verbosity >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( app_name , model . _meta . object_name ) <EOL> try : <EOL> for sql in index_sql : <EOL> cursor . execute ( sql ) <EOL> except Exception , e : <EOL> sys . stderr . write ( "<STR_LIT>" % ( app_name , model . _meta . object_name , e ) ) <EOL> transaction . rollback_unless_managed ( ) <EOL> else : <EOL> transaction . commit_unless_managed ( ) <EOL> load_data ( [ '<STR_LIT>' ] , verbosity = verbosity ) <EOL> syncdb . help_doc = "<STR_LIT>" <EOL> syncdb . args = '<STR_LIT>' <EOL> def get_admin_index ( app ) : <EOL> "<STR_LIT>" <EOL> from django . utils . text import capfirst <EOL> from django . db . models import get_models <EOL> output = [ ] <EOL> app_models = get_models ( app ) <EOL> app_label = app_models [ <NUM_LIT:0> ] . _meta . app_label <EOL> output . append ( '<STR_LIT>' % app_label ) <EOL> output . append ( '<STR_LIT>' % app_label . title ( ) ) <EOL> for model in app_models : <EOL> if model . _meta . admin : <EOL> output . append ( MODULE_TEMPLATE % { <EOL> '<STR_LIT>' : app_label , <EOL> '<STR_LIT>' : model . _meta . module_name , <EOL> '<STR_LIT:name>' : capfirst ( model . _meta . verbose_name_plural ) , <EOL> '<STR_LIT>' : model . _meta . get_add_permission ( ) , <EOL> '<STR_LIT>' : model . _meta . get_change_permission ( ) , <EOL> } ) <EOL> output . append ( '<STR_LIT>' ) <EOL> output . append ( '<STR_LIT>' ) <EOL> return output <EOL> get_admin_index . help_doc = "<STR_LIT>" <EOL> get_admin_index . args = APP_ARGS <EOL> def _module_to_dict ( module , omittable = lambda k : k . startswith ( '<STR_LIT:_>' ) ) : <EOL> "<STR_LIT>" <EOL> return dict ( [ ( k , repr ( v ) ) for k , v in module . __dict__ . items ( ) if not omittable ( k ) ] ) <EOL> def diffsettings ( ) : <EOL> """<STR_LIT>""" <EOL> from django . conf import settings , global_settings <EOL> user_settings = _module_to_dict ( settings . _target ) <EOL> default_settings = _module_to_dict ( global_settings ) <EOL> output = [ ] <EOL> keys = user_settings . keys ( ) <EOL> keys . sort ( ) <EOL> for key in keys : <EOL> if key not in default_settings : <EOL> output . append ( "<STR_LIT>" % ( key , user_settings [ key ] ) ) <EOL> elif user_settings [ key ] != default_settings [ key ] : <EOL> output . append ( "<STR_LIT>" % ( key , user_settings [ key ] ) ) <EOL> print '<STR_LIT:\n>' . join ( output ) <EOL> diffsettings . args = "<STR_LIT>" <EOL> def reset ( app , interactive = True ) : <EOL> "<STR_LIT>" <EOL> from django . db import connection , transaction <EOL> from django . conf import settings <EOL> app_name = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> disable_termcolors ( ) <EOL> _check_for_validation_errors ( app ) <EOL> sql_list = get_sql_reset ( app ) <EOL> if interactive : <EOL> confirm = raw_input ( """<STR_LIT>""" % ( app_name , settings . DATABASE_NAME ) ) <EOL> else : <EOL> confirm = '<STR_LIT:yes>' <EOL> if confirm == '<STR_LIT:yes>' : <EOL> try : <EOL> cursor = connection . cursor ( ) <EOL> for sql in sql_list : <EOL> cursor . execute ( sql ) <EOL> except Exception , e : <EOL> sys . stderr . write ( style . ERROR ( """<STR_LIT>""" % ( app_name , app_name ) ) + style . ERROR_OUTPUT ( str ( e ) ) + '<STR_LIT:\n>' ) <EOL> transaction . rollback_unless_managed ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> transaction . commit_unless_managed ( ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> reset . help_doc = "<STR_LIT>" <EOL> reset . args = '<STR_LIT>' + APP_ARGS <EOL> def flush ( verbosity = <NUM_LIT:1> , interactive = True ) : <EOL> "<STR_LIT>" <EOL> from django . conf import settings <EOL> from django . db import connection , transaction , models <EOL> from django . dispatch import dispatcher <EOL> disable_termcolors ( ) <EOL> _check_for_validation_errors ( ) <EOL> for app_name in settings . INSTALLED_APPS : <EOL> try : <EOL> __import__ ( app_name + '<STR_LIT>' , { } , { } , [ '<STR_LIT>' ] ) <EOL> except ImportError : <EOL> pass <EOL> sql_list = get_sql_flush ( ) <EOL> if interactive : <EOL> confirm = raw_input ( """<STR_LIT>""" ) <EOL> else : <EOL> confirm = '<STR_LIT:yes>' <EOL> if confirm == '<STR_LIT:yes>' : <EOL> try : <EOL> cursor = connection . cursor ( ) <EOL> for sql in sql_list : <EOL> cursor . execute ( sql ) <EOL> except Exception , e : <EOL> sys . stderr . write ( style . ERROR ( """<STR_LIT>""" % settings . DATABASE_NAME + style . ERROR_OUTPUT ( str ( e ) ) + '<STR_LIT:\n>' ) ) <EOL> transaction . rollback_unless_managed ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> transaction . commit_unless_managed ( ) <EOL> _emit_post_sync_signal ( models . get_models ( ) , verbosity , interactive ) <EOL> load_data ( [ '<STR_LIT>' ] , verbosity = verbosity ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> flush . help_doc = "<STR_LIT>" <EOL> flush . args = '<STR_LIT>' <EOL> def _start_helper ( app_or_project , name , directory , other_name = '<STR_LIT>' ) : <EOL> other = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } [ app_or_project ] <EOL> if not _is_valid_dir_name ( name ) : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % ( name , app_or_project ) ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> top_dir = os . path . join ( directory , name ) <EOL> try : <EOL> os . mkdir ( top_dir ) <EOL> except OSError , e : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % e ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> template_dir = PROJECT_TEMPLATE_DIR % app_or_project <EOL> for d , subdirs , files in os . walk ( template_dir ) : <EOL> relative_dir = d [ len ( template_dir ) + <NUM_LIT:1> : ] . replace ( '<STR_LIT>' % app_or_project , name ) <EOL> if relative_dir : <EOL> os . mkdir ( os . path . join ( top_dir , relative_dir ) ) <EOL> for i , subdir in enumerate ( subdirs ) : <EOL> if subdir . startswith ( '<STR_LIT:.>' ) : <EOL> del subdirs [ i ] <EOL> for f in files : <EOL> if f . endswith ( '<STR_LIT>' ) : <EOL> continue <EOL> path_old = os . path . join ( d , f ) <EOL> path_new = os . path . join ( top_dir , relative_dir , f . replace ( '<STR_LIT>' % app_or_project , name ) ) <EOL> fp_old = open ( path_old , '<STR_LIT:r>' ) <EOL> fp_new = open ( path_new , '<STR_LIT:w>' ) <EOL> fp_new . write ( fp_old . read ( ) . replace ( '<STR_LIT>' % app_or_project , name ) . replace ( '<STR_LIT>' % other , other_name ) ) <EOL> fp_old . close ( ) <EOL> fp_new . close ( ) <EOL> try : <EOL> shutil . copymode ( path_old , path_new ) <EOL> except OSError : <EOL> sys . stderr . write ( style . NOTICE ( "<STR_LIT>" % path_new ) ) <EOL> def startproject ( project_name , directory ) : <EOL> "<STR_LIT>" <EOL> from random import choice <EOL> if project_name in INVALID_PROJECT_NAMES : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % project_name ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> _start_helper ( '<STR_LIT>' , project_name , directory ) <EOL> main_settings_file = os . path . join ( directory , project_name , '<STR_LIT>' ) <EOL> settings_contents = open ( main_settings_file , '<STR_LIT:r>' ) . read ( ) <EOL> fp = open ( main_settings_file , '<STR_LIT:w>' ) <EOL> secret_key = '<STR_LIT>' . join ( [ choice ( '<STR_LIT>' ) for i in range ( <NUM_LIT:50> ) ] ) <EOL> settings_contents = re . sub ( r"<STR_LIT>" , secret_key + "<STR_LIT:'>" , settings_contents ) <EOL> fp . write ( settings_contents ) <EOL> fp . close ( ) <EOL> startproject . help_doc = "<STR_LIT>" <EOL> startproject . args = "<STR_LIT>" <EOL> def startapp ( app_name , directory ) : <EOL> "<STR_LIT>" <EOL> project_dir = os . path . normpath ( os . path . join ( directory , '<STR_LIT:..>' ) ) <EOL> project_name = os . path . basename ( project_dir ) <EOL> if app_name == os . path . basename ( directory ) : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % app_name ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> _start_helper ( '<STR_LIT>' , app_name , directory , project_name ) <EOL> startapp . help_doc = "<STR_LIT>" <EOL> startapp . args = "<STR_LIT>" <EOL> def inspectdb ( ) : <EOL> "<STR_LIT>" <EOL> from django . db import connection , get_introspection_module <EOL> import keyword <EOL> introspection_module = get_introspection_module ( ) <EOL> table2model = lambda table_name : table_name . title ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> cursor = connection . cursor ( ) <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT:#>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> for table_name in introspection_module . get_table_list ( cursor ) : <EOL> yield '<STR_LIT>' % table2model ( table_name ) <EOL> try : <EOL> relations = introspection_module . get_relations ( cursor , table_name ) <EOL> except NotImplementedError : <EOL> relations = { } <EOL> try : <EOL> indexes = introspection_module . get_indexes ( cursor , table_name ) <EOL> except NotImplementedError : <EOL> indexes = { } <EOL> for i , row in enumerate ( introspection_module . get_table_description ( cursor , table_name ) ) : <EOL> att_name = row [ <NUM_LIT:0> ] <EOL> comment_notes = [ ] <EOL> extra_params = { } <EOL> if '<STR_LIT:U+0020>' in att_name : <EOL> extra_params [ '<STR_LIT>' ] = att_name <EOL> att_name = att_name . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if keyword . iskeyword ( att_name ) : <EOL> extra_params [ '<STR_LIT>' ] = att_name <EOL> att_name += '<STR_LIT>' <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if relations . has_key ( i ) : <EOL> rel_to = relations [ i ] [ <NUM_LIT:1> ] == table_name and "<STR_LIT>" or table2model ( relations [ i ] [ <NUM_LIT:1> ] ) <EOL> field_type = '<STR_LIT>' % rel_to <EOL> if att_name . endswith ( '<STR_LIT>' ) : <EOL> att_name = att_name [ : - <NUM_LIT:3> ] <EOL> else : <EOL> extra_params [ '<STR_LIT>' ] = att_name <EOL> else : <EOL> try : <EOL> field_type = introspection_module . DATA_TYPES_REVERSE [ row [ <NUM_LIT:1> ] ] <EOL> except KeyError : <EOL> field_type = '<STR_LIT>' <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if type ( field_type ) is tuple : <EOL> field_type , new_params = field_type <EOL> extra_params . update ( new_params ) <EOL> if field_type == '<STR_LIT>' and row [ <NUM_LIT:3> ] : <EOL> extra_params [ '<STR_LIT>' ] = row [ <NUM_LIT:3> ] <EOL> if field_type == '<STR_LIT>' : <EOL> extra_params [ '<STR_LIT>' ] = row [ <NUM_LIT:4> ] <EOL> extra_params [ '<STR_LIT>' ] = row [ <NUM_LIT:5> ] <EOL> column_name = extra_params . get ( '<STR_LIT>' , att_name ) <EOL> if column_name in indexes : <EOL> if indexes [ column_name ] [ '<STR_LIT:primary_key>' ] : <EOL> extra_params [ '<STR_LIT:primary_key>' ] = True <EOL> elif indexes [ column_name ] [ '<STR_LIT>' ] : <EOL> extra_params [ '<STR_LIT>' ] = True <EOL> field_type += '<STR_LIT:(>' <EOL> if att_name == '<STR_LIT:id>' and field_type == '<STR_LIT>' and extra_params == { '<STR_LIT:primary_key>' : True } : <EOL> continue <EOL> if row [ <NUM_LIT:6> ] : <EOL> extra_params [ '<STR_LIT:blank>' ] = True <EOL> if not field_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> extra_params [ '<STR_LIT:null>' ] = True <EOL> field_desc = '<STR_LIT>' % ( att_name , field_type ) <EOL> if extra_params : <EOL> if not field_desc . endswith ( '<STR_LIT:(>' ) : <EOL> field_desc += '<STR_LIT:U+002CU+0020>' <EOL> field_desc += '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for k , v in extra_params . items ( ) ] ) <EOL> field_desc += '<STR_LIT:)>' <EOL> if comment_notes : <EOL> field_desc += '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( comment_notes ) <EOL> yield '<STR_LIT>' % field_desc <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % table_name <EOL> yield '<STR_LIT>' <EOL> inspectdb . help_doc = "<STR_LIT>" <EOL> inspectdb . args = "<STR_LIT>" <EOL> class ModelErrorCollection : <EOL> def __init__ ( self , outfile = sys . stdout ) : <EOL> self . errors = [ ] <EOL> self . outfile = outfile <EOL> def add ( self , context , error ) : <EOL> self . errors . append ( ( context , error ) ) <EOL> self . outfile . write ( style . ERROR ( "<STR_LIT>" % ( context , error ) ) ) <EOL> def get_validation_errors ( outfile , app = None ) : <EOL> """<STR_LIT>""" <EOL> from django . conf import settings <EOL> from django . db import models , connection <EOL> from django . db . models . loading import get_app_errors <EOL> from django . db . models . fields . related import RelatedObject <EOL> e = ModelErrorCollection ( outfile ) <EOL> for ( app_name , error ) in get_app_errors ( ) . items ( ) : <EOL> e . add ( app_name , error ) <EOL> for cls in models . get_models ( app ) : <EOL> opts = cls . _meta <EOL> for f in opts . fields : <EOL> if f . name == '<STR_LIT:id>' and not f . primary_key and opts . pk . name == '<STR_LIT:id>' : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if isinstance ( f , models . CharField ) and f . maxlength in ( None , <NUM_LIT:0> ) : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if isinstance ( f , models . FloatField ) : <EOL> if f . decimal_places is None : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if f . max_digits is None : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if isinstance ( f , models . FileField ) and not f . upload_to : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if isinstance ( f , models . ImageField ) : <EOL> try : <EOL> from PIL import Image <EOL> except ImportError : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if f . prepopulate_from is not None and type ( f . prepopulate_from ) not in ( list , tuple ) : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if f . choices : <EOL> if not hasattr ( f . choices , '<STR_LIT>' ) : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> else : <EOL> for c in f . choices : <EOL> if not type ( c ) in ( tuple , list ) or len ( c ) != <NUM_LIT:2> : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if f . db_index not in ( None , True , False ) : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> if settings . DATABASE_ENGINE == '<STR_LIT>' : <EOL> db_version = connection . get_server_version ( ) <EOL> if db_version < ( <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:3> ) and isinstance ( f , ( models . CharField , models . CommaSeparatedIntegerField , models . SlugField ) ) and f . maxlength > <NUM_LIT:255> : <EOL> e . add ( opts , '<STR_LIT>' % ( f . name , f . __class__ . __name__ , '<STR_LIT:.>' . join ( [ str ( n ) for n in db_version [ : <NUM_LIT:3> ] ] ) ) ) <EOL> if f . rel : <EOL> rel_opts = f . rel . to . _meta <EOL> if f . rel . to not in models . get_models ( ) : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name ) ) <EOL> rel_name = RelatedObject ( f . rel . to , cls , f ) . get_accessor_name ( ) <EOL> rel_query_name = f . related_query_name ( ) <EOL> for r in rel_opts . fields : <EOL> if r . name == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> if r . name == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> for r in rel_opts . many_to_many : <EOL> if r . name == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> if r . name == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> for r in rel_opts . get_all_related_many_to_many_objects ( ) : <EOL> if r . get_accessor_name ( ) == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> if r . get_accessor_name ( ) == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> for r in rel_opts . get_all_related_objects ( ) : <EOL> if r . field is not f : <EOL> if r . get_accessor_name ( ) == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> if r . get_accessor_name ( ) == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> for i , f in enumerate ( opts . many_to_many ) : <EOL> rel_opts = f . rel . to . _meta <EOL> if f . rel . to not in models . get_models ( ) : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name ) ) <EOL> rel_name = RelatedObject ( f . rel . to , cls , f ) . get_accessor_name ( ) <EOL> rel_query_name = f . related_query_name ( ) <EOL> if rel_name is not None : <EOL> for r in rel_opts . fields : <EOL> if r . name == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> if r . name == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> for r in rel_opts . many_to_many : <EOL> if r . name == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> if r . name == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . name , f . name ) ) <EOL> for r in rel_opts . get_all_related_many_to_many_objects ( ) : <EOL> if r . field is not f : <EOL> if r . get_accessor_name ( ) == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> if r . get_accessor_name ( ) == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> for r in rel_opts . get_all_related_objects ( ) : <EOL> if r . get_accessor_name ( ) == rel_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> if r . get_accessor_name ( ) == rel_query_name : <EOL> e . add ( opts , "<STR_LIT>" % ( f . name , rel_opts . object_name , r . get_accessor_name ( ) , f . name ) ) <EOL> if opts . admin is not None : <EOL> if not isinstance ( opts . admin , models . AdminOptions ) : <EOL> e . add ( opts , '<STR_LIT>' ) <EOL> else : <EOL> if not isinstance ( opts . admin . list_display , ( list , tuple ) ) : <EOL> e . add ( opts , '<STR_LIT>' ) <EOL> else : <EOL> for fn in opts . admin . list_display : <EOL> try : <EOL> f = opts . get_field ( fn ) <EOL> except models . FieldDoesNotExist : <EOL> if not hasattr ( cls , fn ) : <EOL> e . add ( opts , '<STR_LIT>' % fn ) <EOL> else : <EOL> if isinstance ( f , models . ManyToManyField ) : <EOL> e . add ( opts , '<STR_LIT>' % fn ) <EOL> if opts . admin . list_display_links and not opts . admin . list_display : <EOL> e . add ( opts , '<STR_LIT>' ) <EOL> if not isinstance ( opts . admin . list_display_links , ( list , tuple ) ) : <EOL> e . add ( opts , '<STR_LIT>' ) <EOL> else : <EOL> for fn in opts . admin . list_display_links : <EOL> try : <EOL> f = opts . get_field ( fn ) <EOL> except models . FieldDoesNotExist : <EOL> if not hasattr ( cls , fn ) : <EOL> e . add ( opts , '<STR_LIT>' % fn ) <EOL> if fn not in opts . admin . list_display : <EOL> e . add ( opts , '<STR_LIT>' % fn ) <EOL> if not isinstance ( opts . admin . list_filter , ( list , tuple ) ) : <EOL> e . add ( opts , '<STR_LIT>' ) <EOL> else : <EOL> for fn in opts . admin . list_filter : <EOL> try : <EOL> f = opts . get_field ( fn ) <EOL> except models . FieldDoesNotExist : <EOL> e . add ( opts , '<STR_LIT>' % fn ) <EOL> if opts . admin . date_hierarchy : <EOL> try : <EOL> f = opts . get_field ( opts . admin . date_hierarchy ) <EOL> except models . FieldDoesNotExist : <EOL> e . add ( opts , '<STR_LIT>' % opts . admin . date_hierarchy ) <EOL> if opts . ordering : <EOL> for field_name in opts . ordering : <EOL> if field_name == '<STR_LIT:?>' : continue <EOL> if field_name . startswith ( '<STR_LIT:->' ) : <EOL> field_name = field_name [ <NUM_LIT:1> : ] <EOL> if opts . order_with_respect_to and field_name == '<STR_LIT>' : <EOL> continue <EOL> if '<STR_LIT:.>' in field_name : continue <EOL> try : <EOL> opts . get_field ( field_name , many_to_many = False ) <EOL> except models . FieldDoesNotExist : <EOL> e . add ( opts , '<STR_LIT>' % field_name ) <EOL> for related in opts . get_followed_related_objects ( ) : <EOL> if not related . edit_inline : <EOL> continue <EOL> try : <EOL> for f in related . opts . fields : <EOL> if f . core : <EOL> raise StopIteration <EOL> e . add ( related . opts , "<STR_LIT>" % ( related . opts . object_name , opts . module_name , opts . object_name ) ) <EOL> except StopIteration : <EOL> pass <EOL> for ut in opts . unique_together : <EOL> for field_name in ut : <EOL> try : <EOL> f = opts . get_field ( field_name , many_to_many = True ) <EOL> except models . FieldDoesNotExist : <EOL> e . add ( opts , '<STR_LIT>' % field_name ) <EOL> else : <EOL> if isinstance ( f . rel , models . ManyToManyRel ) : <EOL> e . add ( opts , '<STR_LIT>' % f . name ) <EOL> return len ( e . errors ) <EOL> def validate ( outfile = sys . stdout , silent_success = False ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> num_errors = get_validation_errors ( outfile ) <EOL> if silent_success and num_errors == <NUM_LIT:0> : <EOL> return <EOL> outfile . write ( '<STR_LIT>' % ( num_errors , num_errors != <NUM_LIT:1> and '<STR_LIT:s>' or '<STR_LIT>' ) ) <EOL> except ImproperlyConfigured : <EOL> outfile . write ( "<STR_LIT>" ) <EOL> validate . args = '<STR_LIT>' <EOL> def _check_for_validation_errors ( app = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> s = StringIO ( ) <EOL> num_errors = get_validation_errors ( s , app ) <EOL> if num_errors : <EOL> if app : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % app ) ) <EOL> else : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" ) ) <EOL> s . seek ( <NUM_LIT:0> ) <EOL> sys . stderr . write ( s . read ( ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def runserver ( addr , port , use_reloader = True , admin_media_dir = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> from django . core . servers . basehttp import run , AdminMediaHandler , WSGIServerException <EOL> from django . core . handlers . wsgi import WSGIHandler <EOL> if not addr : <EOL> addr = '<STR_LIT:127.0.0.1>' <EOL> if not port . isdigit ( ) : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % port ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> quit_command = sys . platform == '<STR_LIT:win32>' and '<STR_LIT>' or '<STR_LIT>' <EOL> def inner_run ( ) : <EOL> from django . conf import settings <EOL> print "<STR_LIT>" <EOL> validate ( ) <EOL> print "<STR_LIT>" % ( get_version ( ) , settings . SETTINGS_MODULE ) <EOL> print "<STR_LIT>" % ( addr , port ) <EOL> print "<STR_LIT>" % quit_command <EOL> try : <EOL> handler = AdminMediaHandler ( WSGIHandler ( ) , admin_media_path ) <EOL> run ( addr , int ( port ) , handler ) <EOL> except WSGIServerException , e : <EOL> ERRORS = { <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> } <EOL> try : <EOL> error_text = ERRORS [ e . args [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] ] <EOL> except ( AttributeError , KeyError ) : <EOL> error_text = str ( e ) <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % error_text ) + '<STR_LIT:\n>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> except KeyboardInterrupt : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if use_reloader : <EOL> from django . utils import autoreload <EOL> autoreload . main ( inner_run ) <EOL> else : <EOL> inner_run ( ) <EOL> runserver . args = '<STR_LIT>' <EOL> def createcachetable ( tablename ) : <EOL> "<STR_LIT>" <EOL> from django . db import backend , connection , transaction , get_creation_module , models <EOL> data_types = get_creation_module ( ) . DATA_TYPES <EOL> fields = ( <EOL> models . CharField ( name = '<STR_LIT>' , maxlength = <NUM_LIT:255> , unique = True , primary_key = True ) , <EOL> models . TextField ( name = '<STR_LIT:value>' ) , <EOL> models . DateTimeField ( name = '<STR_LIT>' , db_index = True ) , <EOL> ) <EOL> table_output = [ ] <EOL> index_output = [ ] <EOL> for f in fields : <EOL> field_output = [ backend . quote_name ( f . name ) , data_types [ f . get_internal_type ( ) ] % f . __dict__ ] <EOL> field_output . append ( "<STR_LIT>" % ( not f . null and "<STR_LIT>" or "<STR_LIT>" ) ) <EOL> if f . unique : <EOL> field_output . append ( "<STR_LIT>" ) <EOL> if f . primary_key : <EOL> field_output . append ( "<STR_LIT>" ) <EOL> if f . db_index : <EOL> unique = f . unique and "<STR_LIT>" or "<STR_LIT>" <EOL> index_output . append ( "<STR_LIT>" % ( unique , tablename , f . name , backend . quote_name ( tablename ) , <EOL> backend . quote_name ( f . name ) ) ) <EOL> table_output . append ( "<STR_LIT:U+0020>" . join ( field_output ) ) <EOL> full_statement = [ "<STR_LIT>" % backend . quote_name ( tablename ) ] <EOL> for i , line in enumerate ( table_output ) : <EOL> full_statement . append ( '<STR_LIT>' % ( line , i < len ( table_output ) - <NUM_LIT:1> and '<STR_LIT:U+002C>' or '<STR_LIT>' ) ) <EOL> full_statement . append ( '<STR_LIT>' ) <EOL> curs = connection . cursor ( ) <EOL> curs . execute ( "<STR_LIT:\n>" . join ( full_statement ) ) <EOL> for statement in index_output : <EOL> curs . execute ( statement ) <EOL> transaction . commit_unless_managed ( ) <EOL> createcachetable . args = "<STR_LIT>" <EOL> def run_shell ( use_plain = False ) : <EOL> "<STR_LIT>" <EOL> from django . db . models . loading import get_models <EOL> loaded_models = get_models ( ) <EOL> try : <EOL> if use_plain : <EOL> raise ImportError <EOL> import IPython <EOL> shell = IPython . Shell . IPShell ( argv = [ ] ) <EOL> shell . mainloop ( ) <EOL> except ImportError : <EOL> import code <EOL> try : <EOL> import readline <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> import rlcompleter <EOL> readline . parse_and_bind ( "<STR_LIT>" ) <EOL> code . interact ( ) <EOL> run_shell . args = '<STR_LIT>' <EOL> def dbshell ( ) : <EOL> "<STR_LIT>" <EOL> from django . db import runshell <EOL> runshell ( ) <EOL> dbshell . args = "<STR_LIT>" <EOL> def runfcgi ( args ) : <EOL> "<STR_LIT>" <EOL> from django . conf import settings <EOL> from django . utils import translation <EOL> try : <EOL> translation . activate ( settings . LANGUAGE_CODE ) <EOL> except AttributeError : <EOL> pass <EOL> from django . core . servers . fastcgi import runfastcgi <EOL> runfastcgi ( args ) <EOL> runfcgi . args = '<STR_LIT>' <EOL> def test ( app_labels , verbosity = <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> from django . conf import settings <EOL> from django . db . models import get_app , get_apps <EOL> if len ( app_labels ) == <NUM_LIT:0> : <EOL> app_list = get_apps ( ) <EOL> else : <EOL> app_list = [ get_app ( app_label ) for app_label in app_labels ] <EOL> test_path = settings . TEST_RUNNER . split ( '<STR_LIT:.>' ) <EOL> if len ( test_path ) > <NUM_LIT:1> : <EOL> test_module_name = '<STR_LIT:.>' . join ( test_path [ : - <NUM_LIT:1> ] ) <EOL> else : <EOL> test_module_name = '<STR_LIT:.>' <EOL> test_module = __import__ ( test_module_name , { } , { } , test_path [ - <NUM_LIT:1> ] ) <EOL> test_runner = getattr ( test_module , test_path [ - <NUM_LIT:1> ] ) <EOL> failures = test_runner ( app_list , verbosity ) <EOL> if failures : <EOL> sys . exit ( failures ) <EOL> test . help_doc = '<STR_LIT>' <EOL> test . args = '<STR_LIT>' + APP_ARGS <EOL> def load_data ( fixture_labels , verbosity = <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> from django . db . models import get_apps <EOL> from django . core import serializers <EOL> from django . db import connection , transaction <EOL> from django . conf import settings <EOL> import sys <EOL> count = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> humanize = lambda dirname : dirname and "<STR_LIT>" % dirname or '<STR_LIT>' <EOL> cursor = connection . cursor ( ) <EOL> transaction . commit_unless_managed ( ) <EOL> transaction . enter_transaction_management ( ) <EOL> transaction . managed ( True ) <EOL> app_fixtures = [ os . path . join ( os . path . dirname ( app . __file__ ) , '<STR_LIT>' ) for app in get_apps ( ) ] <EOL> for fixture_label in fixture_labels : <EOL> if verbosity > <NUM_LIT:0> : <EOL> print "<STR_LIT>" % fixture_label <EOL> for fixture_dir in app_fixtures + list ( settings . FIXTURE_DIRS ) + [ '<STR_LIT>' ] : <EOL> if verbosity > <NUM_LIT:1> : <EOL> print "<STR_LIT>" % humanize ( fixture_dir ) <EOL> parts = fixture_label . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> fixture_name = fixture_label <EOL> formats = serializers . get_serializer_formats ( ) <EOL> else : <EOL> fixture_name , format = '<STR_LIT:.>' . join ( parts [ : - <NUM_LIT:1> ] ) , parts [ - <NUM_LIT:1> ] <EOL> formats = [ format ] <EOL> label_found = False <EOL> for format in formats : <EOL> serializer = serializers . get_serializer ( format ) <EOL> if verbosity > <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( humanize ( fixture_dir ) , format , fixture_name ) <EOL> try : <EOL> full_path = os . path . join ( fixture_dir , '<STR_LIT:.>' . join ( [ fixture_name , format ] ) ) <EOL> fixture = open ( full_path , '<STR_LIT:r>' ) <EOL> if label_found : <EOL> fixture . close ( ) <EOL> print style . ERROR ( "<STR_LIT>" % <EOL> ( fixture_name , humanize ( fixture_dir ) ) ) <EOL> transaction . rollback ( ) <EOL> transaction . leave_transaction_management ( ) <EOL> return <EOL> else : <EOL> count [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> if verbosity > <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( format , fixture_name , humanize ( fixture_dir ) ) <EOL> try : <EOL> objects = serializers . deserialize ( format , fixture ) <EOL> for obj in objects : <EOL> count [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> obj . save ( ) <EOL> label_found = True <EOL> except Exception , e : <EOL> fixture . close ( ) <EOL> sys . stderr . write ( <EOL> style . ERROR ( "<STR_LIT>" % <EOL> ( full_path , str ( e ) ) ) ) <EOL> transaction . rollback ( ) <EOL> transaction . leave_transaction_management ( ) <EOL> return <EOL> fixture . close ( ) <EOL> except : <EOL> if verbosity > <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( format , fixture_name , humanize ( fixture_dir ) ) <EOL> if count [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> if verbosity > <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> else : <EOL> if verbosity > <NUM_LIT:0> : <EOL> print "<STR_LIT>" % tuple ( count ) <EOL> transaction . commit ( ) <EOL> transaction . leave_transaction_management ( ) <EOL> load_data . help_doc = '<STR_LIT>' <EOL> load_data . args = "<STR_LIT>" <EOL> def dump_data ( app_labels , format = '<STR_LIT>' , indent = None ) : <EOL> "<STR_LIT>" <EOL> from django . db . models import get_app , get_apps , get_models <EOL> from django . core import serializers <EOL> if len ( app_labels ) == <NUM_LIT:0> : <EOL> app_list = get_apps ( ) <EOL> else : <EOL> app_list = [ get_app ( app_label ) for app_label in app_labels ] <EOL> try : <EOL> serializers . get_serializer ( format ) <EOL> except KeyError : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % format ) ) <EOL> objects = [ ] <EOL> for app in app_list : <EOL> for model in get_models ( app ) : <EOL> objects . extend ( model . objects . all ( ) ) <EOL> try : <EOL> return serializers . serialize ( format , objects , indent = indent ) <EOL> except Exception , e : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % e ) ) <EOL> dump_data . help_doc = '<STR_LIT>' <EOL> dump_data . args = '<STR_LIT>' + APP_ARGS <EOL> DEFAULT_ACTION_MAPPING = { <EOL> '<STR_LIT>' : get_admin_index , <EOL> '<STR_LIT>' : createcachetable , <EOL> '<STR_LIT>' : dbshell , <EOL> '<STR_LIT>' : diffsettings , <EOL> '<STR_LIT>' : dump_data , <EOL> '<STR_LIT>' : flush , <EOL> '<STR_LIT>' : inspectdb , <EOL> '<STR_LIT>' : load_data , <EOL> '<STR_LIT>' : reset , <EOL> '<STR_LIT>' : runfcgi , <EOL> '<STR_LIT>' : runserver , <EOL> '<STR_LIT>' : run_shell , <EOL> '<STR_LIT>' : get_sql_create , <EOL> '<STR_LIT>' : get_sql_all , <EOL> '<STR_LIT>' : get_sql_delete , <EOL> '<STR_LIT>' : get_custom_sql , <EOL> '<STR_LIT>' : get_sql_flush , <EOL> '<STR_LIT>' : get_sql_indexes , <EOL> '<STR_LIT>' : get_sql_initial_data , <EOL> '<STR_LIT>' : get_sql_reset , <EOL> '<STR_LIT>' : get_sql_sequence_reset , <EOL> '<STR_LIT>' : startapp , <EOL> '<STR_LIT>' : startproject , <EOL> '<STR_LIT>' : syncdb , <EOL> '<STR_LIT>' : validate , <EOL> '<STR_LIT:test>' : test , <EOL> } <EOL> NO_SQL_TRANSACTION = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> class DjangoOptionParser ( OptionParser ) : <EOL> def print_usage_and_exit ( self ) : <EOL> self . print_help ( sys . stderr ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def get_usage ( action_mapping ) : <EOL> """<STR_LIT>""" <EOL> usage = [ "<STR_LIT>" ] <EOL> available_actions = action_mapping . keys ( ) <EOL> available_actions . sort ( ) <EOL> for a in available_actions : <EOL> func = action_mapping [ a ] <EOL> usage . append ( "<STR_LIT>" % ( a , func . args ) ) <EOL> usage . extend ( textwrap . wrap ( getattr ( func , '<STR_LIT>' , textwrap . dedent ( func . __doc__ . strip ( ) ) ) , initial_indent = '<STR_LIT:U+0020>' , subsequent_indent = '<STR_LIT:U+0020>' ) ) <EOL> usage . append ( "<STR_LIT>" ) <EOL> return '<STR_LIT:\n>' . join ( usage [ : - <NUM_LIT:1> ] ) <EOL> def print_error ( msg , cmd ) : <EOL> sys . stderr . write ( style . ERROR ( '<STR_LIT>' % msg ) + '<STR_LIT>' % cmd ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def execute_from_command_line ( action_mapping = DEFAULT_ACTION_MAPPING , argv = None ) : <EOL> if argv is None : <EOL> argv = sys . argv <EOL> parser = DjangoOptionParser ( usage = get_usage ( action_mapping ) , version = get_version ( ) ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , default = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , default = None , dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:int>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , default = '<STR_LIT:1>' , <EOL> type = '<STR_LIT>' , choices = [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] , <EOL> help = '<STR_LIT>' ) , <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) , <EOL> options , args = parser . parse_args ( argv [ <NUM_LIT:1> : ] ) <EOL> if options . settings : <EOL> os . environ [ '<STR_LIT>' ] = options . settings <EOL> if options . pythonpath : <EOL> sys . path . insert ( <NUM_LIT:0> , options . pythonpath ) <EOL> try : <EOL> action = args [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> parser . print_usage_and_exit ( ) <EOL> if not action_mapping . has_key ( action ) : <EOL> print_error ( "<STR_LIT>" % action , argv [ <NUM_LIT:0> ] ) <EOL> if action not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> from django . utils import translation <EOL> translation . activate ( '<STR_LIT>' ) <EOL> if action == '<STR_LIT>' : <EOL> action_mapping [ action ] ( options . plain is True ) <EOL> elif action in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> action_mapping [ action ] ( ) <EOL> elif action in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> action_mapping [ action ] ( int ( options . verbosity ) , options . interactive ) <EOL> elif action == '<STR_LIT>' : <EOL> try : <EOL> for line in action_mapping [ action ] ( ) : <EOL> print line <EOL> except NotImplementedError : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % action ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif action == '<STR_LIT>' : <EOL> try : <EOL> action_mapping [ action ] ( args [ <NUM_LIT:1> ] ) <EOL> except IndexError : <EOL> parser . print_usage_and_exit ( ) <EOL> elif action in ( '<STR_LIT:test>' , '<STR_LIT>' ) : <EOL> try : <EOL> action_mapping [ action ] ( args [ <NUM_LIT:1> : ] , int ( options . verbosity ) ) <EOL> except IndexError : <EOL> parser . print_usage_and_exit ( ) <EOL> elif action == '<STR_LIT>' : <EOL> try : <EOL> print action_mapping [ action ] ( args [ <NUM_LIT:1> : ] , options . format , options . indent ) <EOL> except IndexError : <EOL> parser . print_usage_and_exit ( ) <EOL> elif action in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> name = args [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> parser . print_usage_and_exit ( ) <EOL> action_mapping [ action ] ( name , os . getcwd ( ) ) <EOL> elif action == '<STR_LIT>' : <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> addr = '<STR_LIT>' <EOL> port = '<STR_LIT>' <EOL> else : <EOL> try : <EOL> addr , port = args [ <NUM_LIT:1> ] . split ( '<STR_LIT::>' ) <EOL> except ValueError : <EOL> addr , port = '<STR_LIT>' , args [ <NUM_LIT:1> ] <EOL> action_mapping [ action ] ( addr , port , options . use_reloader , options . admin_media_path ) <EOL> elif action == '<STR_LIT>' : <EOL> action_mapping [ action ] ( args [ <NUM_LIT:1> : ] ) <EOL> elif action == '<STR_LIT>' : <EOL> print action_mapping [ action ] ( args [ <NUM_LIT:1> : ] ) <EOL> elif action == '<STR_LIT>' : <EOL> print '<STR_LIT:\n>' . join ( action_mapping [ action ] ( ) ) <EOL> else : <EOL> from django . db import models <EOL> validate ( silent_success = True ) <EOL> try : <EOL> mod_list = [ models . get_app ( app_label ) for app_label in args [ <NUM_LIT:1> : ] ] <EOL> except ImportError , e : <EOL> sys . stderr . write ( style . ERROR ( "<STR_LIT>" % e ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not mod_list : <EOL> parser . print_usage_and_exit ( ) <EOL> if action not in NO_SQL_TRANSACTION : <EOL> print style . SQL_KEYWORD ( "<STR_LIT>" ) <EOL> for mod in mod_list : <EOL> if action == '<STR_LIT>' : <EOL> output = action_mapping [ action ] ( mod , options . interactive ) <EOL> else : <EOL> output = action_mapping [ action ] ( mod ) <EOL> if output : <EOL> print '<STR_LIT:\n>' . join ( output ) <EOL> if action not in NO_SQL_TRANSACTION : <EOL> print style . SQL_KEYWORD ( "<STR_LIT>" ) <EOL> def setup_environ ( settings_mod ) : <EOL> """<STR_LIT>""" <EOL> project_directory = os . path . dirname ( settings_mod . __file__ ) <EOL> project_name = os . path . basename ( project_directory ) <EOL> sys . path . append ( os . path . join ( project_directory , '<STR_LIT:..>' ) ) <EOL> project_module = __import__ ( project_name , { } , { } , [ '<STR_LIT>' ] ) <EOL> sys . path . pop ( ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' % project_name <EOL> return project_directory <EOL> def execute_manager ( settings_mod , argv = None ) : <EOL> project_directory = setup_environ ( settings_mod ) <EOL> action_mapping = DEFAULT_ACTION_MAPPING . copy ( ) <EOL> del action_mapping [ '<STR_LIT>' ] <EOL> action_mapping [ '<STR_LIT>' ] = lambda app_name , directory : startapp ( app_name , project_directory ) <EOL> action_mapping [ '<STR_LIT>' ] . __doc__ = startapp . __doc__ <EOL> action_mapping [ '<STR_LIT>' ] . help_doc = startapp . help_doc <EOL> action_mapping [ '<STR_LIT>' ] . args = startapp . args <EOL> execute_from_command_line ( action_mapping , argv ) </s>
