2014-06-18 07:07:54 +08:00
|
|
|
from django.core.management.base import BaseCommand
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
def module_to_dict(module, omittable=lambda k: k.startswith('_')):
|
2013-03-18 03:48:30 +08:00
|
|
|
"""Converts a module namespace to a Python dictionary."""
|
2014-12-07 05:00:09 +08:00
|
|
|
return {k: repr(v) for k, v in module.__dict__.items() if not omittable(k)}
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-06-18 07:07:54 +08:00
|
|
|
class Command(BaseCommand):
|
2007-08-16 14:06:55 +08:00
|
|
|
help = """Displays differences between the current settings.py and Django's
|
|
|
|
default settings. Settings that don't appear in the defaults are
|
|
|
|
followed by "###"."""
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
requires_system_checks = False
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2014-06-07 04:39:33 +08:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument('--all', action='store_true', dest='all', default=False,
|
|
|
|
help='Display all settings, regardless of their value. '
|
|
|
|
'Default values are prefixed by "###".')
|
|
|
|
|
2014-06-18 07:07:54 +08:00
|
|
|
def handle(self, **options):
|
2007-08-16 14:06:55 +08:00
|
|
|
# Inspired by Postfix's "postconf -n".
|
|
|
|
from django.conf import settings, global_settings
|
|
|
|
|
|
|
|
# Because settings are imported lazily, we need to explicitly load them.
|
2009-03-03 10:48:02 +08:00
|
|
|
settings._setup()
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2009-03-03 10:48:02 +08:00
|
|
|
user_settings = module_to_dict(settings._wrapped)
|
2007-08-16 14:06:55 +08:00
|
|
|
default_settings = module_to_dict(global_settings)
|
|
|
|
|
|
|
|
output = []
|
2013-03-18 03:48:30 +08:00
|
|
|
for key in sorted(user_settings):
|
2007-08-16 14:06:55 +08:00
|
|
|
if key not in default_settings:
|
|
|
|
output.append("%s = %s ###" % (key, user_settings[key]))
|
|
|
|
elif user_settings[key] != default_settings[key]:
|
|
|
|
output.append("%s = %s" % (key, user_settings[key]))
|
2013-03-18 03:48:30 +08:00
|
|
|
elif options['all']:
|
|
|
|
output.append("### %s = %s" % (key, user_settings[key]))
|
2010-02-22 07:39:27 +08:00
|
|
|
return '\n'.join(output)
|