Removed direct print statements from django management commands.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17941 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Claude Paroz 2012-04-26 19:56:20 +00:00
parent 8aca3d1cc2
commit c34d069a75
2 changed files with 11 additions and 12 deletions

View File

@ -82,4 +82,4 @@ The full error: %s""" % (connection.settings_dict['NAME'], e))
call_command('loaddata', 'initial_data', **kwargs)
else:
print "Flush cancelled."
self.stdout.write("Flush cancelled.\n")

View File

@ -1,5 +1,4 @@
from optparse import make_option
import sys
import traceback
from django.conf import settings
@ -82,12 +81,12 @@ class Command(NoArgsCommand):
# 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)
@ -97,7 +96,7 @@ class Command(NoArgsCommand):
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))
@ -115,19 +114,19 @@ 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 ..."
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()
@ -136,10 +135,10 @@ class Command(NoArgsCommand):
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:
@ -147,12 +146,12 @@ class Command(NoArgsCommand):
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: