Ticket #7679: colorize_runserver.py.patch
File colorize_runserver.py.patch, 3.1 KB (added by , 16 years ago) |
---|
-
core/management/color.py
5 5 import sys 6 6 7 7 from django.utils import termcolors 8 from django.conf import settings 8 9 9 10 def supports_color(): 10 11 """ … … 21 22 22 23 def color_style(): 23 24 """Returns a Style object with the Django color scheme.""" 24 if not supports_color(): 25 color_enabled = getattr( settings, 'COLORIZE_CONSOLE', False ) 26 if False == color_enabled or not supports_color(): 25 27 return no_style() 26 28 class dummy: pass 27 29 style = dummy() 28 style.ERROR = termcolors.make_style(fg='red', opts=('bold',))30 style.ERROR = termcolors.make_style(fg='red', opts=('bold',)) 29 31 style.ERROR_OUTPUT = termcolors.make_style(fg='red', opts=('bold',)) 30 style.NOTICE = termcolors.make_style(fg='red') 31 style.SQL_FIELD = termcolors.make_style(fg='green', opts=('bold',)) 32 style.SQL_COLTYPE = termcolors.make_style(fg='green') 33 style.SQL_KEYWORD = termcolors.make_style(fg='yellow') 34 style.SQL_TABLE = termcolors.make_style(opts=('bold',)) 32 style.NOTICE = termcolors.make_style(fg='red') 33 style.SQL_FIELD = termcolors.make_style(fg='green', opts=('bold',)) 34 style.SQL_COLTYPE = termcolors.make_style(fg='green') 35 style.SQL_KEYWORD = termcolors.make_style(fg='yellow') 36 style.SQL_TABLE = termcolors.make_style(opts=('bold',)) 37 style.NOT_FOUND = termcolors.make_style(fg='yellow', opts=('bold',)) 38 style.UNAUTHORIZED = termcolors.make_style(fg='red', opts=('reverse',)) 35 39 return style 36 40 37 41 def no_style(): -
core/servers/basehttp.py
15 15 import urllib 16 16 17 17 from django.utils.http import http_date 18 from django.core.management.color import color_style 18 19 19 20 __version__ = "0.1" 20 21 __all__ = ['WSGIServer','WSGIRequestHandler'] … … 554 555 # We set self.path to avoid crashes in log_message() on unsupported 555 556 # requests (like "OPTIONS"). 556 557 self.path = '' 558 self.style = color_style() 557 559 BaseHTTPRequestHandler.__init__(self, *args, **kwargs) 558 560 559 561 def get_environ(self): … … 605 607 # Don't bother logging requests for admin images or the favicon. 606 608 if self.path.startswith(self.admin_media_prefix) or self.path == '/favicon.ico': 607 609 return 608 sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args))610 msg = "[%s] %s\n" % (self.log_date_time_string(), format % args) 609 611 612 # utilize terminal colors, if available 613 if '404' == args[1]: 614 msg = self.style.NOT_FOUND(msg) 615 if '401' == args[1]: 616 msg = self.style.UNAUTHORIZED(msg) 617 elif '500' == args[1]: 618 msg = self.style.ERROR(msg) 619 620 sys.stderr.write(msg) 621 610 622 class AdminMediaHandler(object): 611 623 """ 612 624 WSGI middleware that intercepts calls to the admin media directory, as