Commits

Anonymous committed 44f22b2

Removed direct print statements from django management commands.

Comments (0)

Files changed (2)

django/core/management/commands/flush.py

             call_command('loaddata', 'initial_data', **kwargs)
 
         else:
-            print "Flush cancelled."
+            self.stdout.write("Flush cancelled.\n")

django/core/management/commands/syncdb.py

 from optparse import make_option
-import sys
 import traceback
 
 from django.conf import settings
 
         # Create the tables for each model
         if verbosity >= 1:
-            print "Creating tables ..."
+            self.stdout.write("Creating tables ...\n")
         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 >= 3:
-                    print "Processing %s.%s model" % (app_name, model._meta.object_name)
+                    self.stdout.write("Processing %s.%s model\n" % (app_name, model._meta.object_name))
                 sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
                 seen_models.add(model)
                 created_models.add(model)
                         sql.extend(connection.creation.sql_for_pending_references(refto, self.style, pending_references))
                 sql.extend(connection.creation.sql_for_pending_references(model, self.style, pending_references))
                 if verbosity >= 1 and sql:
-                    print "Creating table %s" % model._meta.db_table
+                    self.stdout.write("Creating table %s\n" % model._meta.db_table)
                 for statement in sql:
                     cursor.execute(statement)
                 tables.append(connection.introspection.table_name_converter(model._meta.db_table))
         # Install custom SQL for the app (but only if this
         # is a model we've just created)
         if verbosity >= 1:
-            print "Installing custom SQL ..."
+            self.stdout.write("Installing custom SQL ...\n")
         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 >= 2:
-                            print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
+                            self.stdout.write("Installing custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
                         try:
                             for sql in custom_sql:
                                 cursor.execute(sql)
                         except Exception, e:
-                            sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
+                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
                                                 (app_name, model._meta.object_name, e))
                             if show_traceback:
                                 traceback.print_exc()
                             transaction.commit_unless_managed(using=db)
                     else:
                         if verbosity >= 3:
-                            print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
+                            self.stdout.write("No custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
 
         if verbosity >= 1:
-            print "Installing indexes ..."
+            self.stdout.write("Installing indexes ...\n")
         # Install SQL indices for all newly created models
         for app_name, model_list in manifest.items():
             for model in model_list:
                     index_sql = connection.creation.sql_indexes_for_model(model, self.style)
                     if index_sql:
                         if verbosity >= 2:
-                            print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
+                            self.stdout.write("Installing index for %s.%s model\n" % (app_name, model._meta.object_name))
                         try:
                             for sql in index_sql:
                                 cursor.execute(sql)
                         except Exception, e:
-                            sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
+                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
                                                 (app_name, model._meta.object_name, e))
                             transaction.rollback_unless_managed(using=db)
                         else: