diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-08-17 15:05:54 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-08-17 15:05:54 +0000 |
| commit | fcec755f01cfaba2a85bfc9511876debbce98631 (patch) | |
| tree | e990effbcd90e4d405b0f9dcc70cb38e47b6f3dc /django/core/management/commands/diffsettings.py | |
| parent | 0f92ac52cbf81fb2ac01755c558e2e6ad54700e8 (diff) | |
newforms-admin: Merged from trunk up to [5916]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/management/commands/diffsettings.py')
| -rw-r--r-- | django/core/management/commands/diffsettings.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/django/core/management/commands/diffsettings.py b/django/core/management/commands/diffsettings.py new file mode 100644 index 0000000000..2459f11700 --- /dev/null +++ b/django/core/management/commands/diffsettings.py @@ -0,0 +1,32 @@ +from django.core.management.base import NoArgsCommand + +def module_to_dict(module, omittable=lambda k: k.startswith('_')): + "Converts a module namespace to a Python dictionary. Used by get_settings_diff." + return dict([(k, repr(v)) for k, v in module.__dict__.items() if not omittable(k)]) + +class Command(NoArgsCommand): + help = """Displays differences between the current settings.py and Django's + default settings. Settings that don't appear in the defaults are + followed by "###".""" + + requires_model_validation = False + + def handle_noargs(self, **options): + # Inspired by Postfix's "postconf -n". + from django.conf import settings, global_settings + + # Because settings are imported lazily, we need to explicitly load them. + settings._import_settings() + + user_settings = module_to_dict(settings._target) + default_settings = module_to_dict(global_settings) + + output = [] + keys = user_settings.keys() + keys.sort() + for key in keys: + 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])) + print '\n'.join(output) |
