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:
parent
7e06065d8b
commit
72dc12ed06
|
@ -118,7 +118,7 @@ class BaseCommand(object):
|
|||
# Metadata about this command.
|
||||
option_list = (
|
||||
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'),
|
||||
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.'),
|
||||
|
|
|
@ -111,7 +111,7 @@ class Command(BaseCommand):
|
|||
formats = []
|
||||
|
||||
if formats:
|
||||
if verbosity > 1:
|
||||
if verbosity >= 2:
|
||||
self.stdout.write("Loading '%s' fixtures...\n" % fixture_name)
|
||||
else:
|
||||
sys.stderr.write(
|
||||
|
@ -127,7 +127,7 @@ class Command(BaseCommand):
|
|||
fixture_dirs = app_fixtures + list(settings.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))
|
||||
|
||||
label_found = False
|
||||
|
@ -140,7 +140,7 @@ class Command(BaseCommand):
|
|||
if p
|
||||
)
|
||||
|
||||
if verbosity > 1:
|
||||
if verbosity >= 3:
|
||||
self.stdout.write("Trying %s for %s fixture '%s'...\n" % \
|
||||
(humanize(fixture_dir), file_name, fixture_name))
|
||||
full_path = os.path.join(fixture_dir, file_name)
|
||||
|
@ -157,7 +157,7 @@ class Command(BaseCommand):
|
|||
else:
|
||||
fixture_count += 1
|
||||
objects_in_fixture = 0
|
||||
if verbosity > 0:
|
||||
if verbosity >= 2:
|
||||
self.stdout.write("Installing %s fixture '%s' from %s.\n" % \
|
||||
(format, fixture_name, humanize(fixture_dir)))
|
||||
try:
|
||||
|
@ -197,7 +197,7 @@ class Command(BaseCommand):
|
|||
return
|
||||
|
||||
except Exception, e:
|
||||
if verbosity > 1:
|
||||
if verbosity >= 2:
|
||||
self.stdout.write("No %s fixture '%s' in %s.\n" % \
|
||||
(format, fixture_name, humanize(fixture_dir)))
|
||||
|
||||
|
@ -206,7 +206,7 @@ class Command(BaseCommand):
|
|||
if object_count > 0:
|
||||
sequence_sql = connection.ops.sequence_reset_sql(self.style, models)
|
||||
if sequence_sql:
|
||||
if verbosity > 1:
|
||||
if verbosity >= 2:
|
||||
self.stdout.write("Resetting sequences\n")
|
||||
for line in sequence_sql:
|
||||
cursor.execute(line)
|
||||
|
@ -216,10 +216,10 @@ class Command(BaseCommand):
|
|||
transaction.leave_transaction_management(using=using)
|
||||
|
||||
if object_count == 0:
|
||||
if verbosity > 0:
|
||||
if verbosity >= 1:
|
||||
self.stdout.write("No fixtures found.\n")
|
||||
else:
|
||||
if verbosity > 0:
|
||||
if verbosity >= 1:
|
||||
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
|
||||
|
|
|
@ -76,10 +76,12 @@ class Command(NoArgsCommand):
|
|||
)
|
||||
|
||||
# Create the tables for each model
|
||||
if verbosity >= 1:
|
||||
print "Creating tables ..."
|
||||
for app_name, model_list in manifest.items():
|
||||
for model in model_list:
|
||||
# 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)
|
||||
sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
|
||||
seen_models.add(model)
|
||||
|
@ -107,12 +109,14 @@ class Command(NoArgsCommand):
|
|||
|
||||
# Install custom SQL for the app (but only if this
|
||||
# is a model we've just created)
|
||||
if verbosity >= 1:
|
||||
print "Installing custom SQL ..."
|
||||
for app_name, model_list in manifest.items():
|
||||
for model in model_list:
|
||||
if model in created_models:
|
||||
custom_sql = custom_sql_for_model(model, self.style, connection)
|
||||
if custom_sql:
|
||||
if verbosity >= 1:
|
||||
if verbosity >= 2:
|
||||
print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
|
||||
try:
|
||||
for sql in custom_sql:
|
||||
|
@ -127,16 +131,18 @@ class Command(NoArgsCommand):
|
|||
else:
|
||||
transaction.commit_unless_managed(using=db)
|
||||
else:
|
||||
if verbosity >= 2:
|
||||
if verbosity >= 3:
|
||||
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
|
||||
for app_name, model_list in manifest.items():
|
||||
for model in model_list:
|
||||
if model in created_models:
|
||||
index_sql = connection.creation.sql_indexes_for_model(model, self.style)
|
||||
if index_sql:
|
||||
if verbosity >= 1:
|
||||
if verbosity >= 2:
|
||||
print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
|
||||
try:
|
||||
for sql in index_sql:
|
||||
|
|
|
@ -350,7 +350,10 @@ class BaseDatabaseCreation(object):
|
|||
can_rollback = self._rollback_works()
|
||||
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://'):
|
||||
from django.core.cache import parse_backend_uri, cache
|
||||
|
@ -390,10 +393,8 @@ class BaseDatabaseCreation(object):
|
|||
if autoclobber or confirm == 'yes':
|
||||
try:
|
||||
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))
|
||||
if verbosity >= 1:
|
||||
print "Creating test database..."
|
||||
cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
|
||||
except Exception, e:
|
||||
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
|
||||
|
|
|
@ -61,8 +61,6 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||
|
||||
cursor = self.connection.cursor()
|
||||
if self._test_database_create():
|
||||
if verbosity >= 1:
|
||||
print 'Creating test database...'
|
||||
try:
|
||||
self._execute_test_db_creation(cursor, parameters, verbosity)
|
||||
except Exception, e:
|
||||
|
@ -72,10 +70,8 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||
if autoclobber or confirm == 'yes':
|
||||
try:
|
||||
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)
|
||||
if verbosity >= 1:
|
||||
print "Creating test database..."
|
||||
self._execute_test_db_creation(cursor, parameters, verbosity)
|
||||
except Exception, e:
|
||||
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
|
||||
|
|
|
@ -43,14 +43,12 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||
if test_database_name and test_database_name != ":memory:":
|
||||
# Erase the old test database
|
||||
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 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)
|
||||
if autoclobber or confirm == 'yes':
|
||||
try:
|
||||
if verbosity >= 1:
|
||||
print "Destroying old test database..."
|
||||
os.remove(test_database_name)
|
||||
except Exception, e:
|
||||
sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
|
||||
|
@ -58,8 +56,6 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||
else:
|
||||
print "Tests cancelled."
|
||||
sys.exit(1)
|
||||
if verbosity >= 1:
|
||||
print "Creating test database..."
|
||||
else:
|
||||
test_database_name = ":memory:"
|
||||
return test_database_name
|
||||
|
|
|
@ -962,6 +962,7 @@ that ``django-admin.py`` should print to the console.
|
|||
* ``0`` means no output.
|
||||
* ``1`` means normal output (default).
|
||||
* ``2`` means verbose output.
|
||||
* ``3`` means *very* verbose output.
|
||||
|
||||
Common options
|
||||
==============
|
||||
|
|
|
@ -128,7 +128,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
|
|||
# no models were named (i.e., run all), import
|
||||
# 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 verbosity >= 1:
|
||||
if verbosity >= 2:
|
||||
print "Importing model %s" % model_name
|
||||
mod = load_app(model_label)
|
||||
if mod:
|
||||
|
@ -187,8 +187,8 @@ if __name__ == "__main__":
|
|||
from optparse import OptionParser
|
||||
usage = "%prog [options] [model model model ...]"
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0',
|
||||
type='choice', choices=['0', '1', '2'],
|
||||
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',
|
||||
type='choice', choices=['0', '1', '2', '3'],
|
||||
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
|
||||
parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
|
||||
help='Tells Django to NOT prompt the user for input of any kind.')
|
||||
|
|
Loading…
Reference in New Issue