|
0
|
1 |
from django.core.management.base import NoArgsCommand |
|
|
2 |
|
|
|
3 |
def module_to_dict(module, omittable=lambda k: k.startswith('_')): |
|
|
4 |
"Converts a module namespace to a Python dictionary. Used by get_settings_diff." |
|
|
5 |
return dict([(k, repr(v)) for k, v in module.__dict__.items() if not omittable(k)]) |
|
|
6 |
|
|
|
7 |
class Command(NoArgsCommand): |
|
|
8 |
help = """Displays differences between the current settings.py and Django's |
|
|
9 |
default settings. Settings that don't appear in the defaults are |
|
|
10 |
followed by "###".""" |
|
|
11 |
|
|
|
12 |
requires_model_validation = False |
|
|
13 |
|
|
|
14 |
def handle_noargs(self, **options): |
|
|
15 |
# Inspired by Postfix's "postconf -n". |
|
|
16 |
from django.conf import settings, global_settings |
|
|
17 |
|
|
|
18 |
# Because settings are imported lazily, we need to explicitly load them. |
|
|
19 |
settings._setup() |
|
|
20 |
|
|
|
21 |
user_settings = module_to_dict(settings._wrapped) |
|
|
22 |
default_settings = module_to_dict(global_settings) |
|
|
23 |
|
|
|
24 |
output = [] |
|
|
25 |
keys = user_settings.keys() |
|
|
26 |
keys.sort() |
|
|
27 |
for key in keys: |
|
|
28 |
if key not in default_settings: |
|
|
29 |
output.append("%s = %s ###" % (key, user_settings[key])) |
|
|
30 |
elif user_settings[key] != default_settings[key]: |
|
|
31 |
output.append("%s = %s" % (key, user_settings[key])) |
|
|
32 |
print '\n'.join(output) |