Ticket #2333: core.patch
File core.patch, 4.4 KB (added by , 18 years ago) |
---|
-
core/management.py
420 420 get_sql_all.help_doc = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)." 421 421 get_sql_all.args = APP_ARGS 422 422 423 def syncdb( ):423 def syncdb(verbosity=2, interactive=True): 424 424 "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 425 425 from django.db import connection, transaction, models, get_creation_module 426 426 from django.db.models import signals … … 468 468 except KeyError: 469 469 pending_references[refto] = refs 470 470 sql.extend(_get_sql_for_pending_references(model, pending_references)) 471 print "Creating table %s" % model._meta.db_table 471 if verbosity >= 2: 472 print "Creating table %s" % model._meta.db_table 472 473 for statement in sql: 473 474 cursor.execute(statement) 474 475 table_list.append(model._meta.db_table) … … 477 478 if model in created_models: 478 479 sql = _get_many_to_many_sql_for_model(model) 479 480 if sql: 480 print "Creating many-to-many tables for %s model" % model.__name__ 481 if verbosity >= 2: 482 print "Creating many-to-many tables for %s model" % model.__name__ 481 483 for statement in sql: 482 484 cursor.execute(statement) 483 485 … … 487 489 # to do at this point. 488 490 for app in models.get_apps(): 489 491 dispatcher.send(signal=signals.post_syncdb, sender=app, 490 app=app, created_models=created_models) 492 app=app, created_models=created_models, 493 verbosity=verbosity, interactive=interactive) 491 494 492 495 # Install initial data for the app (but only if this is a model we've 493 496 # just created) … … 1135 1138 runfastcgi(args) 1136 1139 runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 1137 1140 1141 def test(verbosity, app_labels): 1142 "Runs the test suite for the specified applications" 1143 from django.conf import settings 1144 from django.db.models import get_app, get_apps 1145 1146 if len(app_labels) == 0: 1147 app_list = get_apps() 1148 else: 1149 app_list = [get_app(app_label) for app_label in app_labels] 1150 1151 test_module = __import__(settings.TEST_MODULE, [],[],'*') 1152 test_runner = getattr(test_module, settings.TEST_RUNNER) 1153 1154 test_runner(app_list, verbosity) 1155 1156 test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 1157 test.args = '[--verbosity] ' + APP_ARGS 1158 1138 1159 # Utilities for command-line script 1139 1160 1140 1161 DEFAULT_ACTION_MAPPING = { … … 1159 1180 'startproject': startproject, 1160 1181 'syncdb': syncdb, 1161 1182 'validate': validate, 1183 'test':test, 1162 1184 } 1163 1185 1164 1186 NO_SQL_TRANSACTION = ( … … 1209 1231 help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".') 1210 1232 parser.add_option('--plain', action='store_true', dest='plain', 1211 1233 help='Tells Django to use plain Python, not IPython, for "shell" command.') 1234 parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1', 1235 type='choice', choices=['0', '1', '2'], 1236 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 1237 1212 1238 options, args = parser.parse_args(argv[1:]) 1213 1239 1214 1240 # Take care of options. … … 1235 1261 1236 1262 if action == 'shell': 1237 1263 action_mapping[action](options.plain is True) 1238 elif action in (' syncdb', 'validate', 'diffsettings', 'dbshell'):1264 elif action in ('validate', 'diffsettings', 'dbshell'): 1239 1265 action_mapping[action]() 1266 elif action == 'syncdb': 1267 action_mapping[action](int(options.verbosity)) 1240 1268 elif action == 'inspectdb': 1241 1269 try: 1242 1270 for line in action_mapping[action](): … … 1249 1277 action_mapping[action](args[1]) 1250 1278 except IndexError: 1251 1279 parser.print_usage_and_exit() 1280 elif action == 'test': 1281 try: 1282 action_mapping[action](int(options.verbosity), args[1:]) 1283 except IndexError: 1284 parser.print_usage_and_exit() 1252 1285 elif action in ('startapp', 'startproject'): 1253 1286 try: 1254 1287 name = args[1]