Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 72dc12ed06ae45e49c79b8fd257e1b1589b3fad2 1 parent 7e06065
Russell Keith-Magee authored August 07, 2010
2  django/core/management/base.py
@@ -118,7 +118,7 @@ class BaseCommand(object):
118 118
     # Metadata about this command.
119 119
     option_list = (
120 120
         make_option('-v', '--verbosity', action='store', dest='verbosity', default='1',
121  
-            type='choice', choices=['0', '1', '2'],
  121
+            type='choice', choices=['0', '1', '2', '3'],
122 122
             help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
123 123
         make_option('--settings',
124 124
             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.'),
16  django/core/management/commands/loaddata.py
@@ -111,7 +111,7 @@ def read(self):
111 111
                     formats = []
112 112
 
113 113
             if formats:
114  
-                if verbosity > 1:
  114
+                if verbosity >= 2:
115 115
                     self.stdout.write("Loading '%s' fixtures...\n" % fixture_name)
116 116
             else:
117 117
                 sys.stderr.write(
@@ -127,7 +127,7 @@ def read(self):
127 127
                 fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + ['']
128 128
 
129 129
             for fixture_dir in fixture_dirs:
130  
-                if verbosity > 1:
  130
+                if verbosity >= 2:
131 131
                     self.stdout.write("Checking %s for fixtures...\n" % humanize(fixture_dir))
132 132
 
133 133
                 label_found = False
@@ -140,7 +140,7 @@ def read(self):
140 140
                         if p
141 141
                     )
142 142
 
143  
-                    if verbosity > 1:
  143
+                    if verbosity >= 3:
144 144
                         self.stdout.write("Trying %s for %s fixture '%s'...\n" % \
145 145
                             (humanize(fixture_dir), file_name, fixture_name))
146 146
                     full_path = os.path.join(fixture_dir, file_name)
@@ -157,7 +157,7 @@ def read(self):
157 157
                         else:
158 158
                             fixture_count += 1
159 159
                             objects_in_fixture = 0
160  
-                            if verbosity > 0:
  160
+                            if verbosity >= 2:
161 161
                                 self.stdout.write("Installing %s fixture '%s' from %s.\n" % \
162 162
                                     (format, fixture_name, humanize(fixture_dir)))
163 163
                             try:
@@ -197,7 +197,7 @@ def read(self):
197 197
                                 return
198 198
 
199 199
                     except Exception, e:
200  
-                        if verbosity > 1:
  200
+                        if verbosity >= 2:
201 201
                             self.stdout.write("No %s fixture '%s' in %s.\n" % \
202 202
                                 (format, fixture_name, humanize(fixture_dir)))
203 203
 
@@ -206,7 +206,7 @@ def read(self):
206 206
         if object_count > 0:
207 207
             sequence_sql = connection.ops.sequence_reset_sql(self.style, models)
208 208
             if sequence_sql:
209  
-                if verbosity > 1:
  209
+                if verbosity >= 2:
210 210
                     self.stdout.write("Resetting sequences\n")
211 211
                 for line in sequence_sql:
212 212
                     cursor.execute(line)
@@ -216,10 +216,10 @@ def read(self):
216 216
             transaction.leave_transaction_management(using=using)
217 217
 
218 218
         if object_count == 0:
219  
-            if verbosity > 0:
  219
+            if verbosity >= 1:
220 220
                 self.stdout.write("No fixtures found.\n")
221 221
         else:
222  
-            if verbosity > 0:
  222
+            if verbosity >= 1:
223 223
                 self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (object_count, fixture_count))
224 224
 
225 225
         # Close the DB connection. This is required as a workaround for an
14  django/core/management/commands/syncdb.py
@@ -76,10 +76,12 @@ def model_installed(model):
76 76
         )
77 77
 
78 78
         # Create the tables for each model
  79
+        if verbosity >= 1:
  80
+            print "Creating tables ..."
79 81
         for app_name, model_list in manifest.items():
80 82
             for model in model_list:
81 83
                 # Create the model's database table, if it doesn't already exist.
82  
-                if verbosity >= 2:
  84
+                if verbosity >= 3:
83 85
                     print "Processing %s.%s model" % (app_name, model._meta.object_name)
84 86
                 sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
85 87
                 seen_models.add(model)
@@ -107,12 +109,14 @@ def model_installed(model):
107 109
 
108 110
         # Install custom SQL for the app (but only if this
109 111
         # is a model we've just created)
  112
+        if verbosity >= 1:
  113
+            print "Installing custom SQL ..."
110 114
         for app_name, model_list in manifest.items():
111 115
             for model in model_list:
112 116
                 if model in created_models:
113 117
                     custom_sql = custom_sql_for_model(model, self.style, connection)
114 118
                     if custom_sql:
115  
-                        if verbosity >= 1:
  119
+                        if verbosity >= 2:
116 120
                             print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
117 121
                         try:
118 122
                             for sql in custom_sql:
@@ -127,16 +131,18 @@ def model_installed(model):
127 131
                         else:
128 132
                             transaction.commit_unless_managed(using=db)
129 133
                     else:
130  
-                        if verbosity >= 2:
  134
+                        if verbosity >= 3:
131 135
                             print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
132 136
 
  137
+        if verbosity >= 1:
  138
+            print "Installing indexes ..."
133 139
         # Install SQL indicies for all newly created models
134 140
         for app_name, model_list in manifest.items():
135 141
             for model in model_list:
136 142
                 if model in created_models:
137 143
                     index_sql = connection.creation.sql_indexes_for_model(model, self.style)
138 144
                     if index_sql:
139  
-                        if verbosity >= 1:
  145
+                        if verbosity >= 2:
140 146
                             print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
141 147
                         try:
142 148
                             for sql in index_sql:
9  django/db/backends/creation.py
@@ -350,7 +350,10 @@ def create_test_db(self, verbosity=1, autoclobber=False):
350 350
         can_rollback = self._rollback_works()
351 351
         self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
352 352
 
353  
-        call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
  353
+        # Report syncdb messages at one level lower than that requested.
  354
+        # This ensures we don't get flooded with messages during testing
  355
+        # (unless you really ask to be flooded)
  356
+        call_command('syncdb', verbosity=max(verbosity - 1, 0), interactive=False, database=self.connection.alias)
354 357
 
355 358
         if settings.CACHE_BACKEND.startswith('db://'):
356 359
             from django.core.cache import parse_backend_uri, cache
@@ -390,10 +393,8 @@ def _create_test_db(self, verbosity, autoclobber):
390 393
             if autoclobber or confirm == 'yes':
391 394
                 try:
392 395
                     if verbosity >= 1:
393  
-                        print "Destroying old test database..."
  396
+                        print "Destroying old test database '%s'..." % self.connection.alias
394 397
                     cursor.execute("DROP DATABASE %s" % qn(test_database_name))
395  
-                    if verbosity >= 1:
396  
-                        print "Creating test database..."
397 398
                     cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
398 399
                 except Exception, e:
399 400
                     sys.stderr.write("Got an error recreating the test database: %s\n" % e)
6  django/db/backends/oracle/creation.py
@@ -61,8 +61,6 @@ def _create_test_db(self, verbosity=1, autoclobber=False):
61 61
 
62 62
         cursor = self.connection.cursor()
63 63
         if self._test_database_create():
64  
-            if verbosity >= 1:
65  
-                print 'Creating test database...'
66 64
             try:
67 65
                 self._execute_test_db_creation(cursor, parameters, verbosity)
68 66
             except Exception, e:
@@ -72,10 +70,8 @@ def _create_test_db(self, verbosity=1, autoclobber=False):
72 70
                 if autoclobber or confirm == 'yes':
73 71
                     try:
74 72
                         if verbosity >= 1:
75  
-                            print "Destroying old test database..."
  73
+                            print "Destroying old test database '%s'..." % self.connection.alias
76 74
                         self._execute_test_db_destruction(cursor, parameters, verbosity)
77  
-                        if verbosity >= 1:
78  
-                            print "Creating test database..."
79 75
                         self._execute_test_db_creation(cursor, parameters, verbosity)
80 76
                     except Exception, e:
81 77
                         sys.stderr.write("Got an error recreating the test database: %s\n" % e)
6  django/db/backends/sqlite3/creation.py
@@ -43,14 +43,12 @@ def _create_test_db(self, verbosity, autoclobber):
43 43
         if test_database_name and test_database_name != ":memory:":
44 44
             # Erase the old test database
45 45
             if verbosity >= 1:
46  
-                print "Destroying old test database..."
  46
+                print "Destroying old test database '%s'..." % self.connection.alias
47 47
             if os.access(test_database_name, os.F_OK):
48 48
                 if not autoclobber:
49 49
                     confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name)
50 50
                 if autoclobber or confirm == 'yes':
51 51
                   try:
52  
-                      if verbosity >= 1:
53  
-                          print "Destroying old test database..."
54 52
                       os.remove(test_database_name)
55 53
                   except Exception, e:
56 54
                       sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
@@ -58,8 +56,6 @@ def _create_test_db(self, verbosity, autoclobber):
58 56
                 else:
59 57
                     print "Tests cancelled."
60 58
                     sys.exit(1)
61  
-            if verbosity >= 1:
62  
-                print "Creating test database..."
63 59
         else:
64 60
             test_database_name = ":memory:"
65 61
         return test_database_name
1  docs/ref/django-admin.txt
@@ -962,6 +962,7 @@ that ``django-admin.py`` should print to the console.
962 962
     * ``0`` means no output.
963 963
     * ``1`` means normal output (default).
964 964
     * ``2`` means verbose output.
  965
+    * ``3`` means *very* verbose output.
965 966
 
966 967
 Common options
967 968
 ==============
6  tests/runtests.py
@@ -128,7 +128,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
128 128
             # no models were named (i.e., run all), import
129 129
             # this model and add it to the list to test.
130 130
             if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]):
131  
-                if verbosity >= 1:
  131
+                if verbosity >= 2:
132 132
                     print "Importing model %s" % model_name
133 133
                 mod = load_app(model_label)
134 134
                 if mod:
@@ -187,8 +187,8 @@ def django_tests(verbosity, interactive, failfast, test_labels):
187 187
     from optparse import OptionParser
188 188
     usage = "%prog [options] [model model model ...]"
189 189
     parser = OptionParser(usage=usage)
190  
-    parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0',
191  
-        type='choice', choices=['0', '1', '2'],
  190
+    parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',
  191
+        type='choice', choices=['0', '1', '2', '3'],
192 192
         help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
193 193
     parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
194 194
         help='Tells Django to NOT prompt the user for input of any kind.')

0 notes on commit 72dc12e

Please sign in to comment.
Something went wrong with that request. Please try again.