Commit 72dc12ed authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Rationalized the verbosity levels (including introducing a new super-verbose...

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
parent 7e06065d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.'),
+8 −8
Original line number Diff line number Diff line
@@ -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
+10 −4
Original line number Diff line number Diff line
@@ -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:
+5 −4
Original line number Diff line number Diff line
@@ -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)
+1 −5
Original line number Diff line number Diff line
@@ -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)
Loading