Skip to content

Commit c34d069

Browse files
committed
Removed direct print statements from django management commands.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17941 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 8aca3d1 commit c34d069

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

django/core/management/commands/flush.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ def handle_noargs(self, **options):
8282
call_command('loaddata', 'initial_data', **kwargs)
8383

8484
else:
85-
print "Flush cancelled."
85+
self.stdout.write("Flush cancelled.\n")

django/core/management/commands/syncdb.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from optparse import make_option
2-
import sys
32
import traceback
43

54
from django.conf import settings
@@ -82,12 +81,12 @@ def model_installed(model):
8281

8382
# Create the tables for each model
8483
if verbosity >= 1:
85-
print "Creating tables ..."
84+
self.stdout.write("Creating tables ...\n")
8685
for app_name, model_list in manifest.items():
8786
for model in model_list:
8887
# Create the model's database table, if it doesn't already exist.
8988
if verbosity >= 3:
90-
print "Processing %s.%s model" % (app_name, model._meta.object_name)
89+
self.stdout.write("Processing %s.%s model\n" % (app_name, model._meta.object_name))
9190
sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
9291
seen_models.add(model)
9392
created_models.add(model)
@@ -97,7 +96,7 @@ def model_installed(model):
9796
sql.extend(connection.creation.sql_for_pending_references(refto, self.style, pending_references))
9897
sql.extend(connection.creation.sql_for_pending_references(model, self.style, pending_references))
9998
if verbosity >= 1 and sql:
100-
print "Creating table %s" % model._meta.db_table
99+
self.stdout.write("Creating table %s\n" % model._meta.db_table)
101100
for statement in sql:
102101
cursor.execute(statement)
103102
tables.append(connection.introspection.table_name_converter(model._meta.db_table))
@@ -115,19 +114,19 @@ def model_installed(model):
115114
# Install custom SQL for the app (but only if this
116115
# is a model we've just created)
117116
if verbosity >= 1:
118-
print "Installing custom SQL ..."
117+
self.stdout.write("Installing custom SQL ...\n")
119118
for app_name, model_list in manifest.items():
120119
for model in model_list:
121120
if model in created_models:
122121
custom_sql = custom_sql_for_model(model, self.style, connection)
123122
if custom_sql:
124123
if verbosity >= 2:
125-
print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
124+
self.stdout.write("Installing custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
126125
try:
127126
for sql in custom_sql:
128127
cursor.execute(sql)
129128
except Exception, e:
130-
sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
129+
self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
131130
(app_name, model._meta.object_name, e))
132131
if show_traceback:
133132
traceback.print_exc()
@@ -136,23 +135,23 @@ def model_installed(model):
136135
transaction.commit_unless_managed(using=db)
137136
else:
138137
if verbosity >= 3:
139-
print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
138+
self.stdout.write("No custom SQL for %s.%s model\n" % (app_name, model._meta.object_name))
140139

141140
if verbosity >= 1:
142-
print "Installing indexes ..."
141+
self.stdout.write("Installing indexes ...\n")
143142
# Install SQL indices for all newly created models
144143
for app_name, model_list in manifest.items():
145144
for model in model_list:
146145
if model in created_models:
147146
index_sql = connection.creation.sql_indexes_for_model(model, self.style)
148147
if index_sql:
149148
if verbosity >= 2:
150-
print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
149+
self.stdout.write("Installing index for %s.%s model\n" % (app_name, model._meta.object_name))
151150
try:
152151
for sql in index_sql:
153152
cursor.execute(sql)
154153
except Exception, e:
155-
sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
154+
self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
156155
(app_name, model._meta.object_name, e))
157156
transaction.rollback_unless_managed(using=db)
158157
else:

0 commit comments

Comments
 (0)