Loading django/contrib/auth/management/commands/createsuperuser.py +7 −7 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ class Command(BaseCommand): if default_username and username == '': username = default_username if not RE_VALID_USERNAME.match(username): sys.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.\n") self.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.") username = None continue try: Loading @@ -88,7 +88,7 @@ class Command(BaseCommand): except User.DoesNotExist: break else: sys.stderr.write("Error: That username is already taken.\n") self.stderr.write("Error: That username is already taken.") username = None # Get an email Loading @@ -98,7 +98,7 @@ class Command(BaseCommand): try: is_valid_email(email) except exceptions.ValidationError: sys.stderr.write("Error: That e-mail address is invalid.\n") self.stderr.write("Error: That e-mail address is invalid.") email = None else: break Loading @@ -109,19 +109,19 @@ class Command(BaseCommand): password = getpass.getpass() password2 = getpass.getpass('Password (again): ') if password != password2: sys.stderr.write("Error: Your passwords didn't match.\n") self.stderr.write("Error: Your passwords didn't match.") password = None continue if password.strip() == '': sys.stderr.write("Error: Blank passwords aren't allowed.\n") self.stderr.write("Error: Blank passwords aren't allowed.") password = None continue break except KeyboardInterrupt: sys.stderr.write("\nOperation cancelled.\n") self.stderr.write("\nOperation cancelled.") sys.exit(1) User.objects.db_manager(database).create_superuser(username, email, password) if verbosity >= 1: self.stdout.write("Superuser created successfully.\n") self.stdout.write("Superuser created successfully.") django/contrib/staticfiles/management/commands/collectstatic.py +2 −5 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ from optparse import make_option from django.core.files.storage import FileSystemStorage from django.core.management.base import CommandError, NoArgsCommand from django.utils.encoding import smart_str, smart_unicode from django.utils.encoding import smart_unicode from django.utils.datastructures import SortedDict from django.contrib.staticfiles import finders, storage Loading Loading @@ -178,15 +178,12 @@ Type 'yes' to continue, or 'no' to cancel: """ ', %s post-processed' % post_processed_count or ''), } self.stdout.write(smart_str(summary)) self.stdout.write(summary) def log(self, msg, level=2): """ Small log helper """ msg = smart_str(msg) if not msg.endswith("\n"): msg += "\n" if self.verbosity >= level: self.stdout.write(msg) Loading django/contrib/staticfiles/management/commands/findstatic.py +2 −4 Original line number Diff line number Diff line Loading @@ -23,9 +23,7 @@ class Command(LabelCommand): result = [result] output = u'\n '.join( (smart_unicode(os.path.realpath(path)) for path in result)) self.stdout.write( smart_str(u"Found '%s' here:\n %s\n" % (path, output))) self.stdout.write(u"Found '%s' here:\n %s" % (path, output)) else: if verbosity >= 1: self.stderr.write( smart_str("No matching file found for '%s'.\n" % path)) self.stderr.write("No matching file found for '%s'." % path) django/core/management/base.py +31 −7 Original line number Diff line number Diff line Loading @@ -45,6 +45,29 @@ def handle_default_options(options): sys.path.insert(0, options.pythonpath) class OutputWrapper(object): """ Wrapper around stdout/stderr """ def __init__(self, out, style_func=None): self._out = out self.style_func = None if hasattr(out, 'isatty') and out.isatty(): self.style_func = style_func def __getattr__(self, name): return getattr(self._out, name) def write(self, msg, style_func=None, ending='\n'): if ending and not msg.endswith(ending): msg += ending if style_func is not None: msg = style_func(msg) elif self.style_func is not None: msg = self.style_func(msg) self._out.write(smart_str(msg)) class BaseCommand(object): """ The base class from which all management commands ultimately Loading Loading @@ -210,6 +233,9 @@ class BaseCommand(object): # But only do this if we can assume we have a working settings file, # because django.utils.translation requires settings. saved_lang = None self.stdout = OutputWrapper(options.get('stdout', sys.stdout)) self.stderr = OutputWrapper(options.get('stderr', sys.stderr), self.style.ERROR) if self.can_import_settings: try: from django.utils import translation Loading @@ -221,12 +247,10 @@ class BaseCommand(object): if show_traceback: traceback.print_exc() else: sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) self.stderr.write('Error: %s' % e) sys.exit(1) try: self.stdout = options.get('stdout', sys.stdout) self.stderr = options.get('stderr', sys.stderr) if self.requires_model_validation and not options.get('skip_validation'): self.validate() output = self.handle(*args, **options) Loading @@ -237,15 +261,15 @@ class BaseCommand(object): from django.db import connections, DEFAULT_DB_ALIAS connection = connections[options.get('database', DEFAULT_DB_ALIAS)] if connection.ops.start_transaction_sql(): self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()) + '\n') self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())) self.stdout.write(output) if self.output_transaction: self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;") + '\n') self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;")) except CommandError as e: if show_traceback: traceback.print_exc() else: self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) self.stderr.write('Error: %s' % e) sys.exit(1) finally: if saved_lang is not None: Loading @@ -266,7 +290,7 @@ class BaseCommand(object): error_text = s.read() raise CommandError("One or more models did not validate:\n%s" % error_text) if display_num_errors: self.stdout.write("%s error%s found\n" % (num_errors, num_errors != 1 and 's' or '')) self.stdout.write("%s error%s found" % (num_errors, num_errors != 1 and 's' or '')) def handle(self, *args, **options): """ Loading django/core/management/commands/createcachetable.py +2 −2 Original line number Diff line number Diff line Loading @@ -56,8 +56,8 @@ class Command(LabelCommand): curs.execute("\n".join(full_statement)) except DatabaseError as e: self.stderr.write( self.style.ERROR("Cache table '%s' could not be created.\nThe error was: %s.\n" % (tablename, e))) "Cache table '%s' could not be created.\nThe error was: %s." % (tablename, e)) transaction.rollback_unless_managed(using=db) else: for statement in index_output: Loading Loading
django/contrib/auth/management/commands/createsuperuser.py +7 −7 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ class Command(BaseCommand): if default_username and username == '': username = default_username if not RE_VALID_USERNAME.match(username): sys.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.\n") self.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.") username = None continue try: Loading @@ -88,7 +88,7 @@ class Command(BaseCommand): except User.DoesNotExist: break else: sys.stderr.write("Error: That username is already taken.\n") self.stderr.write("Error: That username is already taken.") username = None # Get an email Loading @@ -98,7 +98,7 @@ class Command(BaseCommand): try: is_valid_email(email) except exceptions.ValidationError: sys.stderr.write("Error: That e-mail address is invalid.\n") self.stderr.write("Error: That e-mail address is invalid.") email = None else: break Loading @@ -109,19 +109,19 @@ class Command(BaseCommand): password = getpass.getpass() password2 = getpass.getpass('Password (again): ') if password != password2: sys.stderr.write("Error: Your passwords didn't match.\n") self.stderr.write("Error: Your passwords didn't match.") password = None continue if password.strip() == '': sys.stderr.write("Error: Blank passwords aren't allowed.\n") self.stderr.write("Error: Blank passwords aren't allowed.") password = None continue break except KeyboardInterrupt: sys.stderr.write("\nOperation cancelled.\n") self.stderr.write("\nOperation cancelled.") sys.exit(1) User.objects.db_manager(database).create_superuser(username, email, password) if verbosity >= 1: self.stdout.write("Superuser created successfully.\n") self.stdout.write("Superuser created successfully.")
django/contrib/staticfiles/management/commands/collectstatic.py +2 −5 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ from optparse import make_option from django.core.files.storage import FileSystemStorage from django.core.management.base import CommandError, NoArgsCommand from django.utils.encoding import smart_str, smart_unicode from django.utils.encoding import smart_unicode from django.utils.datastructures import SortedDict from django.contrib.staticfiles import finders, storage Loading Loading @@ -178,15 +178,12 @@ Type 'yes' to continue, or 'no' to cancel: """ ', %s post-processed' % post_processed_count or ''), } self.stdout.write(smart_str(summary)) self.stdout.write(summary) def log(self, msg, level=2): """ Small log helper """ msg = smart_str(msg) if not msg.endswith("\n"): msg += "\n" if self.verbosity >= level: self.stdout.write(msg) Loading
django/contrib/staticfiles/management/commands/findstatic.py +2 −4 Original line number Diff line number Diff line Loading @@ -23,9 +23,7 @@ class Command(LabelCommand): result = [result] output = u'\n '.join( (smart_unicode(os.path.realpath(path)) for path in result)) self.stdout.write( smart_str(u"Found '%s' here:\n %s\n" % (path, output))) self.stdout.write(u"Found '%s' here:\n %s" % (path, output)) else: if verbosity >= 1: self.stderr.write( smart_str("No matching file found for '%s'.\n" % path)) self.stderr.write("No matching file found for '%s'." % path)
django/core/management/base.py +31 −7 Original line number Diff line number Diff line Loading @@ -45,6 +45,29 @@ def handle_default_options(options): sys.path.insert(0, options.pythonpath) class OutputWrapper(object): """ Wrapper around stdout/stderr """ def __init__(self, out, style_func=None): self._out = out self.style_func = None if hasattr(out, 'isatty') and out.isatty(): self.style_func = style_func def __getattr__(self, name): return getattr(self._out, name) def write(self, msg, style_func=None, ending='\n'): if ending and not msg.endswith(ending): msg += ending if style_func is not None: msg = style_func(msg) elif self.style_func is not None: msg = self.style_func(msg) self._out.write(smart_str(msg)) class BaseCommand(object): """ The base class from which all management commands ultimately Loading Loading @@ -210,6 +233,9 @@ class BaseCommand(object): # But only do this if we can assume we have a working settings file, # because django.utils.translation requires settings. saved_lang = None self.stdout = OutputWrapper(options.get('stdout', sys.stdout)) self.stderr = OutputWrapper(options.get('stderr', sys.stderr), self.style.ERROR) if self.can_import_settings: try: from django.utils import translation Loading @@ -221,12 +247,10 @@ class BaseCommand(object): if show_traceback: traceback.print_exc() else: sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) self.stderr.write('Error: %s' % e) sys.exit(1) try: self.stdout = options.get('stdout', sys.stdout) self.stderr = options.get('stderr', sys.stderr) if self.requires_model_validation and not options.get('skip_validation'): self.validate() output = self.handle(*args, **options) Loading @@ -237,15 +261,15 @@ class BaseCommand(object): from django.db import connections, DEFAULT_DB_ALIAS connection = connections[options.get('database', DEFAULT_DB_ALIAS)] if connection.ops.start_transaction_sql(): self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()) + '\n') self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())) self.stdout.write(output) if self.output_transaction: self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;") + '\n') self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;")) except CommandError as e: if show_traceback: traceback.print_exc() else: self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) self.stderr.write('Error: %s' % e) sys.exit(1) finally: if saved_lang is not None: Loading @@ -266,7 +290,7 @@ class BaseCommand(object): error_text = s.read() raise CommandError("One or more models did not validate:\n%s" % error_text) if display_num_errors: self.stdout.write("%s error%s found\n" % (num_errors, num_errors != 1 and 's' or '')) self.stdout.write("%s error%s found" % (num_errors, num_errors != 1 and 's' or '')) def handle(self, *args, **options): """ Loading
django/core/management/commands/createcachetable.py +2 −2 Original line number Diff line number Diff line Loading @@ -56,8 +56,8 @@ class Command(LabelCommand): curs.execute("\n".join(full_statement)) except DatabaseError as e: self.stderr.write( self.style.ERROR("Cache table '%s' could not be created.\nThe error was: %s.\n" % (tablename, e))) "Cache table '%s' could not be created.\nThe error was: %s." % (tablename, e)) transaction.rollback_unless_managed(using=db) else: for statement in index_output: Loading