Rationalized the verbosity levels (including introducing a new super-verbose level) for syncdb, test and loaddata.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13539 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-08-07 06:58:14 +00:00
parent 7e06065d8b
commit 72dc12ed06
8 changed files with 30 additions and 30 deletions

View File

@ -118,7 +118,7 @@ class BaseCommand(object):
# Metadata about this command. # Metadata about this command.
option_list = ( option_list = (
make_option('-v', '--verbosity', action='store', dest='verbosity', default='1', make_option('-v', '--verbosity', action='store', dest='verbosity', default='1',
type='choice', choices=['0', '1', '2'], type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
make_option('--settings', make_option('--settings',
help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'), help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'),

View File

@ -111,7 +111,7 @@ class Command(BaseCommand):
formats = [] formats = []
if formats: if formats:
if verbosity > 1: if verbosity >= 2:
self.stdout.write("Loading '%s' fixtures...\n" % fixture_name) self.stdout.write("Loading '%s' fixtures...\n" % fixture_name)
else: else:
sys.stderr.write( sys.stderr.write(
@ -127,7 +127,7 @@ class Command(BaseCommand):
fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + [''] fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + ['']
for fixture_dir in fixture_dirs: for fixture_dir in fixture_dirs:
if verbosity > 1: if verbosity >= 2:
self.stdout.write("Checking %s for fixtures...\n" % humanize(fixture_dir)) self.stdout.write("Checking %s for fixtures...\n" % humanize(fixture_dir))
label_found = False label_found = False
@ -140,7 +140,7 @@ class Command(BaseCommand):
if p if p
) )
if verbosity > 1: if verbosity >= 3:
self.stdout.write("Trying %s for %s fixture '%s'...\n" % \ self.stdout.write("Trying %s for %s fixture '%s'...\n" % \
(humanize(fixture_dir), file_name, fixture_name)) (humanize(fixture_dir), file_name, fixture_name))
full_path = os.path.join(fixture_dir, file_name) full_path = os.path.join(fixture_dir, file_name)
@ -157,7 +157,7 @@ class Command(BaseCommand):
else: else:
fixture_count += 1 fixture_count += 1
objects_in_fixture = 0 objects_in_fixture = 0
if verbosity > 0: if verbosity >= 2:
self.stdout.write("Installing %s fixture '%s' from %s.\n" % \ self.stdout.write("Installing %s fixture '%s' from %s.\n" % \
(format, fixture_name, humanize(fixture_dir))) (format, fixture_name, humanize(fixture_dir)))
try: try:
@ -197,7 +197,7 @@ class Command(BaseCommand):
return return
except Exception, e: except Exception, e:
if verbosity > 1: if verbosity >= 2:
self.stdout.write("No %s fixture '%s' in %s.\n" % \ self.stdout.write("No %s fixture '%s' in %s.\n" % \
(format, fixture_name, humanize(fixture_dir))) (format, fixture_name, humanize(fixture_dir)))
@ -206,7 +206,7 @@ class Command(BaseCommand):
if object_count > 0: if object_count > 0:
sequence_sql = connection.ops.sequence_reset_sql(self.style, models) sequence_sql = connection.ops.sequence_reset_sql(self.style, models)
if sequence_sql: if sequence_sql:
if verbosity > 1: if verbosity >= 2:
self.stdout.write("Resetting sequences\n") self.stdout.write("Resetting sequences\n")
for line in sequence_sql: for line in sequence_sql:
cursor.execute(line) cursor.execute(line)
@ -216,10 +216,10 @@ class Command(BaseCommand):
transaction.leave_transaction_management(using=using) transaction.leave_transaction_management(using=using)
if object_count == 0: if object_count == 0:
if verbosity > 0: if verbosity >= 1:
self.stdout.write("No fixtures found.\n") self.stdout.write("No fixtures found.\n")
else: else:
if verbosity > 0: if verbosity >= 1:
self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (object_count, fixture_count)) self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (object_count, fixture_count))
# Close the DB connection. This is required as a workaround for an # Close the DB connection. This is required as a workaround for an

View File

@ -76,10 +76,12 @@ class Command(NoArgsCommand):
) )
# Create the tables for each model # Create the tables for each model
if verbosity >= 1:
print "Creating tables ..."
for app_name, model_list in manifest.items(): for app_name, model_list in manifest.items():
for model in model_list: for model in model_list:
# Create the model's database table, if it doesn't already exist. # Create the model's database table, if it doesn't already exist.
if verbosity >= 2: if verbosity >= 3:
print "Processing %s.%s model" % (app_name, model._meta.object_name) print "Processing %s.%s model" % (app_name, model._meta.object_name)
sql, references = connection.creation.sql_create_model(model, self.style, seen_models) sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
seen_models.add(model) seen_models.add(model)
@ -107,12 +109,14 @@ class Command(NoArgsCommand):
# Install custom SQL for the app (but only if this # Install custom SQL for the app (but only if this
# is a model we've just created) # is a model we've just created)
if verbosity >= 1:
print "Installing custom SQL ..."
for app_name, model_list in manifest.items(): for app_name, model_list in manifest.items():
for model in model_list: for model in model_list:
if model in created_models: if model in created_models:
custom_sql = custom_sql_for_model(model, self.style, connection) custom_sql = custom_sql_for_model(model, self.style, connection)
if custom_sql: if custom_sql:
if verbosity >= 1: if verbosity >= 2:
print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name) print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
try: try:
for sql in custom_sql: for sql in custom_sql:
@ -127,16 +131,18 @@ class Command(NoArgsCommand):
else: else:
transaction.commit_unless_managed(using=db) transaction.commit_unless_managed(using=db)
else: else:
if verbosity >= 2: if verbosity >= 3:
print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name) print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
if verbosity >= 1:
print "Installing indexes ..."
# Install SQL indicies for all newly created models # Install SQL indicies for all newly created models
for app_name, model_list in manifest.items(): for app_name, model_list in manifest.items():
for model in model_list: for model in model_list:
if model in created_models: if model in created_models:
index_sql = connection.creation.sql_indexes_for_model(model, self.style) index_sql = connection.creation.sql_indexes_for_model(model, self.style)
if index_sql: if index_sql:
if verbosity >= 1: if verbosity >= 2:
print "Installing index for %s.%s model" % (app_name, model._meta.object_name) print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
try: try:
for sql in index_sql: for sql in index_sql:

View File

@ -350,7 +350,10 @@ class BaseDatabaseCreation(object):
can_rollback = self._rollback_works() can_rollback = self._rollback_works()
self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias) # Report syncdb messages at one level lower than that requested.
# This ensures we don't get flooded with messages during testing
# (unless you really ask to be flooded)
call_command('syncdb', verbosity=max(verbosity - 1, 0), interactive=False, database=self.connection.alias)
if settings.CACHE_BACKEND.startswith('db://'): if settings.CACHE_BACKEND.startswith('db://'):
from django.core.cache import parse_backend_uri, cache from django.core.cache import parse_backend_uri, cache
@ -390,10 +393,8 @@ class BaseDatabaseCreation(object):
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
if verbosity >= 1: if verbosity >= 1:
print "Destroying old test database..." print "Destroying old test database '%s'..." % self.connection.alias
cursor.execute("DROP DATABASE %s" % qn(test_database_name)) cursor.execute("DROP DATABASE %s" % qn(test_database_name))
if verbosity >= 1:
print "Creating test database..."
cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix)) cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
except Exception, e: except Exception, e:
sys.stderr.write("Got an error recreating the test database: %s\n" % e) sys.stderr.write("Got an error recreating the test database: %s\n" % e)

View File

@ -61,8 +61,6 @@ class DatabaseCreation(BaseDatabaseCreation):
cursor = self.connection.cursor() cursor = self.connection.cursor()
if self._test_database_create(): if self._test_database_create():
if verbosity >= 1:
print 'Creating test database...'
try: try:
self._execute_test_db_creation(cursor, parameters, verbosity) self._execute_test_db_creation(cursor, parameters, verbosity)
except Exception, e: except Exception, e:
@ -72,10 +70,8 @@ class DatabaseCreation(BaseDatabaseCreation):
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
if verbosity >= 1: if verbosity >= 1:
print "Destroying old test database..." print "Destroying old test database '%s'..." % self.connection.alias
self._execute_test_db_destruction(cursor, parameters, verbosity) self._execute_test_db_destruction(cursor, parameters, verbosity)
if verbosity >= 1:
print "Creating test database..."
self._execute_test_db_creation(cursor, parameters, verbosity) self._execute_test_db_creation(cursor, parameters, verbosity)
except Exception, e: except Exception, e:
sys.stderr.write("Got an error recreating the test database: %s\n" % e) sys.stderr.write("Got an error recreating the test database: %s\n" % e)

View File

@ -43,14 +43,12 @@ class DatabaseCreation(BaseDatabaseCreation):
if test_database_name and test_database_name != ":memory:": if test_database_name and test_database_name != ":memory:":
# Erase the old test database # Erase the old test database
if verbosity >= 1: if verbosity >= 1:
print "Destroying old test database..." print "Destroying old test database '%s'..." % self.connection.alias
if os.access(test_database_name, os.F_OK): if os.access(test_database_name, os.F_OK):
if not autoclobber: if not autoclobber:
confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name) confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name)
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
if verbosity >= 1:
print "Destroying old test database..."
os.remove(test_database_name) os.remove(test_database_name)
except Exception, e: except Exception, e:
sys.stderr.write("Got an error deleting the old test database: %s\n" % e) sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
@ -58,8 +56,6 @@ class DatabaseCreation(BaseDatabaseCreation):
else: else:
print "Tests cancelled." print "Tests cancelled."
sys.exit(1) sys.exit(1)
if verbosity >= 1:
print "Creating test database..."
else: else:
test_database_name = ":memory:" test_database_name = ":memory:"
return test_database_name return test_database_name

View File

@ -962,6 +962,7 @@ that ``django-admin.py`` should print to the console.
* ``0`` means no output. * ``0`` means no output.
* ``1`` means normal output (default). * ``1`` means normal output (default).
* ``2`` means verbose output. * ``2`` means verbose output.
* ``3`` means *very* verbose output.
Common options Common options
============== ==============

View File

@ -128,7 +128,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
# no models were named (i.e., run all), import # no models were named (i.e., run all), import
# this model and add it to the list to test. # this model and add it to the list to test.
if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]): if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]):
if verbosity >= 1: if verbosity >= 2:
print "Importing model %s" % model_name print "Importing model %s" % model_name
mod = load_app(model_label) mod = load_app(model_label)
if mod: if mod:
@ -187,8 +187,8 @@ if __name__ == "__main__":
from optparse import OptionParser from optparse import OptionParser
usage = "%prog [options] [model model model ...]" usage = "%prog [options] [model model model ...]"
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0', parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',
type='choice', choices=['0', '1', '2'], type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
parser.add_option('--noinput', action='store_false', dest='interactive', default=True, parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind.') help='Tells Django to NOT prompt the user for input of any kind.')