@@ -423,7 +423,7 @@ def get_sql_all(app):
423
423
get_sql_all .help_doc = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)."
424
424
get_sql_all .args = APP_ARGS
425
425
426
- def syncdb ():
426
+ def syncdb (verbosity = 2 , interactive = True ):
427
427
"Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
428
428
from django .db import connection , transaction , models , get_creation_module
429
429
from django .db .models import signals
@@ -471,7 +471,8 @@ def syncdb():
471
471
except KeyError :
472
472
pending_references [refto ] = refs
473
473
sql .extend (_get_sql_for_pending_references (model , pending_references ))
474
- print "Creating table %s" % model ._meta .db_table
474
+ if verbosity >= 2 :
475
+ print "Creating table %s" % model ._meta .db_table
475
476
for statement in sql :
476
477
cursor .execute (statement )
477
478
table_list .append (model ._meta .db_table )
@@ -480,7 +481,8 @@ def syncdb():
480
481
if model in created_models :
481
482
sql = _get_many_to_many_sql_for_model (model )
482
483
if sql :
483
- print "Creating many-to-many tables for %s model" % model .__name__
484
+ if verbosity >= 2 :
485
+ print "Creating many-to-many tables for %s model" % model .__name__
484
486
for statement in sql :
485
487
cursor .execute (statement )
486
488
@@ -490,7 +492,8 @@ def syncdb():
490
492
# to do at this point.
491
493
for app in models .get_apps ():
492
494
dispatcher .send (signal = signals .post_syncdb , sender = app ,
493
- app = app , created_models = created_models )
495
+ app = app , created_models = created_models ,
496
+ verbosity = verbosity , interactive = interactive )
494
497
495
498
# Install initial data for the app (but only if this is a model we've
496
499
# just created)
@@ -1154,6 +1157,29 @@ def runfcgi(args):
1154
1157
runfastcgi (args )
1155
1158
runfcgi .args = '[various KEY=val options, use `runfcgi help` for help]'
1156
1159
1160
+ def test (verbosity , app_labels ):
1161
+ "Runs the test suite for the specified applications"
1162
+ from django .conf import settings
1163
+ from django .db .models import get_app , get_apps
1164
+
1165
+ if len (app_labels ) == 0 :
1166
+ app_list = get_apps ()
1167
+ else :
1168
+ app_list = [get_app (app_label ) for app_label in app_labels ]
1169
+
1170
+ test_path = settings .TEST_RUNNER .split ('.' )
1171
+ # Allow for Python 2.5 relative paths
1172
+ if len (test_path ) > 1 :
1173
+ test_module_name = '.' .join (test_path [:- 1 ])
1174
+ else :
1175
+ test_module_name = '.'
1176
+ test_module = __import__ (test_module_name , [],[],test_path [- 1 ])
1177
+ test_runner = getattr (test_module , test_path [- 1 ])
1178
+
1179
+ test_runner (app_list , verbosity )
1180
+ test .help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
1181
+ test .args = '[--verbosity] ' + APP_ARGS
1182
+
1157
1183
# Utilities for command-line script
1158
1184
1159
1185
DEFAULT_ACTION_MAPPING = {
@@ -1178,6 +1204,7 @@ def runfcgi(args):
1178
1204
'startproject' : startproject ,
1179
1205
'syncdb' : syncdb ,
1180
1206
'validate' : validate ,
1207
+ 'test' :test ,
1181
1208
}
1182
1209
1183
1210
NO_SQL_TRANSACTION = (
@@ -1228,8 +1255,14 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
1228
1255
help = 'Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".' )
1229
1256
parser .add_option ('--plain' , action = 'store_true' , dest = 'plain' ,
1230
1257
help = 'Tells Django to use plain Python, not IPython, for "shell" command.' )
1258
+ parser .add_option ('--noinput' , action = 'store_false' , dest = 'interactive' , default = True ,
1259
+ help = 'Tells Django to NOT prompt the user for input of any kind.' )
1231
1260
parser .add_option ('--noreload' , action = 'store_false' , dest = 'use_reloader' , default = True ,
1232
1261
help = 'Tells Django to NOT use the auto-reloader when running the development server.' )
1262
+ parser .add_option ('--verbosity' , action = 'store' , dest = 'verbosity' , default = '2' ,
1263
+ type = 'choice' , choices = ['0' , '1' , '2' ],
1264
+ help = 'Verbosity level; 0=minimal output, 1=normal output, 2=all output' )
1265
+
1233
1266
options , args = parser .parse_args (argv [1 :])
1234
1267
1235
1268
# Take care of options.
@@ -1256,8 +1289,10 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
1256
1289
1257
1290
if action == 'shell' :
1258
1291
action_mapping [action ](options .plain is True )
1259
- elif action in ('syncdb' , ' validate' , 'diffsettings' , 'dbshell' ):
1292
+ elif action in ('validate' , 'diffsettings' , 'dbshell' ):
1260
1293
action_mapping [action ]()
1294
+ elif action == 'syncdb' :
1295
+ action_mapping [action ](int (options .verbosity ), options .interactive )
1261
1296
elif action == 'inspectdb' :
1262
1297
try :
1263
1298
for line in action_mapping [action ]():
@@ -1270,6 +1305,11 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
1270
1305
action_mapping [action ](args [1 ])
1271
1306
except IndexError :
1272
1307
parser .print_usage_and_exit ()
1308
+ elif action == 'test' :
1309
+ try :
1310
+ action_mapping [action ](int (options .verbosity ), args [1 :])
1311
+ except IndexError :
1312
+ parser .print_usage_and_exit ()
1273
1313
elif action in ('startapp' , 'startproject' ):
1274
1314
try :
1275
1315
name = args [1 ]
0 commit comments