Ticket #15107: use-self.diff

File use-self.diff, 9.8 KB (added by adamv, 4 years ago)

Use self.stderr|out instead of print or sys.

  • django/core/management/commands/flush.py

    diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py
    index bcadb96..93b7f83 100644
    a b The full error: %s""" % (connection.settings_dict['NAME'], e)) 
    7979            call_command('loaddata', 'initial_data', **kwargs)
    8080
    8181        else:
    82             print "Flush cancelled."
     82            return "Flush cancelled.\n"
  • django/core/management/commands/makemessages.py

    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    index a244a60..e80457c 100644
    a b def find_files(root, ignore_patterns, verbosity, symlinks=False): 
    7777            norm_filepath = os.path.normpath(os.path.join(dirpath, f))
    7878            if is_ignored(norm_filepath, ignore_patterns):
    7979                if verbosity > 1:
    80                     sys.stdout.write('ignoring file %s in %s\n' % (f, dirpath))
     80                    self.stdout.write('ignoring file %s in %s\n' % (f, dirpath))
    8181            else:
    8282                all_files.extend([(dirpath, f)])
    8383    all_files.sort()
    def copy_plural_forms(msgs, locale, domain, verbosity): 
    101101            m = plural_forms_re.search(open(django_po, 'rU').read())
    102102            if m:
    103103                if verbosity > 1:
    104                     sys.stderr.write("copying plural forms: %s\n" % m.group('value'))
     104                    self.stderr.write("copying plural forms: %s\n" % m.group('value'))
    105105                lines = []
    106106                seen = False
    107107                for line in msgs.split('\n'):
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    167167
    168168    for locale in languages:
    169169        if verbosity > 0:
    170             print "processing language", locale
     170            self.stdout.write('processing language %s\n' % locale)
    171171        basedir = os.path.join(localedir, locale, 'LC_MESSAGES')
    172172        if not os.path.isdir(basedir):
    173173            os.makedirs(basedir)
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    182182            file_base, file_ext = os.path.splitext(file)
    183183            if domain == 'djangojs' and file_ext in extensions:
    184184                if verbosity > 1:
    185                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
     185                    self.stdout.write('processing file %s in %s\n' % (file, dirpath))
    186186                src = open(os.path.join(dirpath, file), "rU").read()
    187187                src = pythonize_re.sub('\n#', src)
    188188                thefile = '%s.py' % file
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    234234                    finally:
    235235                        f.close()
    236236                if verbosity > 1:
    237                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
     237                    self.stdout.write('processing file %s in %s\n' % (file, dirpath))
    238238                cmd = (
    239239                    'xgettext -d %s -L Python %s --keyword=gettext_noop '
    240240                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
    class Command(NoArgsCommand): 
    359359            extensions = handle_extensions(extensions or ['html'])
    360360
    361361        if verbosity > 1:
    362             sys.stdout.write('examining files with the extensions: %s\n'
     362            self.stdout.write('examining files with the extensions: %s\n'
    363363                             % get_text_list(list(extensions), 'and'))
    364364
    365365        make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
  • django/core/management/commands/reset.py

    diff --git a/django/core/management/commands/reset.py b/django/core/management/commands/reset.py
    index 388045f..703a9d1 100644
    a b Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this c 
    6060The full error: %s""" % (app_name, app_name, e))
    6161            transaction.commit_unless_managed()
    6262        else:
    63             print "Reset cancelled."
     63            self.stdout.write("Reset cancelled.\n")
  • django/core/management/commands/runserver.py

    diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
    index b265740..520c5c9 100644
    a b class BaseRunserverCommand(BaseCommand): 
    116116                error_text = ERRORS[e.args[0].args[0]]
    117117            except (AttributeError, KeyError):
    118118                error_text = str(e)
    119             sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
     119            self.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
    120120            # Need to use an OS exit because sys.exit doesn't work in a thread
    121121            os._exit(1)
    122122        except KeyboardInterrupt:
  • django/core/management/commands/syncdb.py

    diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py
    index a5228a1..be4156f 100644
    a b class Command(NoArgsCommand): 
    8181
    8282        # Create the tables for each model
    8383        if verbosity >= 1:
    84             print "Creating tables ..."
     84            self.stdout.write("Creating tables ...\n")
    8585        for app_name, model_list in manifest.items():
    8686            for model in model_list:
    8787                # Create the model's database table, if it doesn't already exist.
    8888                if verbosity >= 3:
    89                     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))
    9090                sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
    9191                seen_models.add(model)
    9292                created_models.add(model)
    class Command(NoArgsCommand): 
    9696                        sql.extend(connection.creation.sql_for_pending_references(refto, self.style, pending_references))
    9797                sql.extend(connection.creation.sql_for_pending_references(model, self.style, pending_references))
    9898                if verbosity >= 1 and sql:
    99                     print "Creating table %s" % model._meta.db_table
     99                    self.stdout.write("Creating table %s\n" % model._meta.db_table)
    100100                for statement in sql:
    101101                    cursor.execute(statement)
    102102                tables.append(connection.introspection.table_name_converter(model._meta.db_table))
    class Command(NoArgsCommand): 
    114114        # Install custom SQL for the app (but only if this
    115115        # is a model we've just created)
    116116        if verbosity >= 1:
    117             print "Installing custom SQL ..."
     117            self.stdout.write("Installing custom SQL ...\n")
    118118        for app_name, model_list in manifest.items():
    119119            for model in model_list:
    120120                if model in created_models:
    121121                    custom_sql = custom_sql_for_model(model, self.style, connection)
    122122                    if custom_sql:
    123123                        if verbosity >= 2:
    124                             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" %
     125                                                (app_name, model._meta.object_name))
    125126                        try:
    126127                            for sql in custom_sql:
    127128                                cursor.execute(sql)
    128129                        except Exception, e:
    129                             sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
     130                            self.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" %
    130131                                                (app_name, model._meta.object_name, e))
    131132                            if show_traceback:
    132133                                import traceback
    class Command(NoArgsCommand): 
    136137                            transaction.commit_unless_managed(using=db)
    137138                    else:
    138139                        if verbosity >= 3:
    139                             print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
     140                            self.stdout.write("No custom SQL for %s.%s model\n" %
     141                                                (app_name, model._meta.object_name))
    140142
    141143        if verbosity >= 1:
    142             print "Installing indexes ..."
     144            self.stdout.write("Installing indexes ...\n")
    143145        # Install SQL indicies for all newly created models
    144146        for app_name, model_list in manifest.items():
    145147            for model in model_list:
    class Command(NoArgsCommand): 
    147149                    index_sql = connection.creation.sql_indexes_for_model(model, self.style)
    148150                    if index_sql:
    149151                        if verbosity >= 2:
    150                             print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
     152                            self.stdout.write("Installing index for %s.%s model\n" %
     153                                                (app_name, model._meta.object_name))
    151154                        try:
    152155                            for sql in index_sql:
    153156                                cursor.execute(sql)
    154157                        except Exception, e:
    155                             sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
     158                            self.stderr.write("Failed to install index for %s.%s model: %s\n" % \
    156159                                                (app_name, model._meta.object_name, e))
    157160                            transaction.rollback_unless_managed(using=db)
    158161                        else:
Back to Top