Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1549 -- Added 'manage.py diffsettings', which d…

…isplays differences between project settings and default settings. Thanks, Paul B.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d6863bede64caee22d059341c9aa092e8661f0a8 1 parent a3f8ab3
Adrian Holovaty authored April 11, 2006
32  django/core/management.py
@@ -514,6 +514,32 @@ def get_admin_index(app):
514 514
 get_admin_index.help_doc = "Prints the admin-index template snippet for the given app name(s)."
515 515
 get_admin_index.args = APP_ARGS
516 516
 
  517
+def _module_to_dict(module, omittable=lambda k: k.startswith('_')):
  518
+    "Converts a module namespace to a Python dictionary. Used by get_settings_diff."
  519
+    return dict([(k, repr(v)) for k, v in module.__dict__.items() if not omittable(k)])
  520
+
  521
+def diffsettings():
  522
+    """
  523
+    Displays differences between the current settings.py and Django's
  524
+    default settings. Settings that don't appear in the defaults are
  525
+    followed by "###".
  526
+    """
  527
+    # Inspired by Postfix's "postconf -n".
  528
+    from django.conf import settings
  529
+    from django.conf import global_settings
  530
+
  531
+    user_settings = _module_to_dict(settings)
  532
+    default_settings = _module_to_dict(global_settings)
  533
+
  534
+    output = []
  535
+    for key in sorted(user_settings):
  536
+        if key not in default_settings:
  537
+            output.append("%s = %s  ###" % (key, user_settings[key]))
  538
+        elif user_settings[key] != default_settings[key]:
  539
+            output.append("%s = %s" % (key, user_settings[key]))
  540
+    print '\n'.join(output)
  541
+diffsettings.args = ""
  542
+
517 543
 def install(app):
518 544
     "Executes the equivalent of 'get_sql_all' in the current database."
519 545
     from django.db import connection, transaction
@@ -1016,6 +1042,7 @@ def run_shell(use_plain=False):
1016 1042
 DEFAULT_ACTION_MAPPING = {
1017 1043
     'adminindex': get_admin_index,
1018 1044
     'createcachetable' : createcachetable,
  1045
+    'diffsettings': diffsettings,
1019 1046
     'inspectdb': inspectdb,
1020 1047
     'install': install,
1021 1048
     'reset': reset,
@@ -1037,6 +1064,7 @@ def run_shell(use_plain=False):
1037 1064
 NO_SQL_TRANSACTION = (
1038 1065
     'adminindex',
1039 1066
     'createcachetable',
  1067
+    'diffsettings',
1040 1068
     'install',
1041 1069
     'reset',
1042 1070
     'sqlindexes',
@@ -1059,7 +1087,7 @@ def get_usage(action_mapping):
1059 1087
     for a in available_actions:
1060 1088
         func = action_mapping[a]
1061 1089
         usage.append("  %s %s" % (a, func.args))
1062  
-        usage.extend(textwrap.wrap(getattr(func, 'help_doc', func.__doc__), initial_indent='    ', subsequent_indent='    '))
  1090
+        usage.extend(textwrap.wrap(getattr(func, 'help_doc', textwrap.dedent(func.__doc__.strip())), initial_indent='    ', subsequent_indent='    '))
1063 1091
         usage.append("")
1064 1092
     return '\n'.join(usage[:-1]) # Cut off last list element, an empty space.
1065 1093
 
@@ -1102,7 +1130,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
1102 1130
 
1103 1131
     if action == 'shell':
1104 1132
         action_mapping[action](options.plain is True)
1105  
-    elif action in ('syncdb', 'validate'):
  1133
+    elif action in ('syncdb', 'validate', 'diffsettings'):
1106 1134
         action_mapping[action]()
1107 1135
     elif action == 'inspectdb':
1108 1136
         try:
12  docs/django-admin.txt
@@ -64,6 +64,18 @@ backend.  See the `cache documentation`_ for more information.
64 64
 
65 65
 .. _cache documentation: http://www.djangoproject.com/documentation/cache/
66 66
 
  67
+diffsettings
  68
+------------
  69
+
  70
+Displays differences between the current settings file and Django's default
  71
+settings.
  72
+
  73
+Settings that don't appear in the defaults are followed by ``"###"``. For
  74
+example, the default settings don't define ``ROOT_URLCONF``, so
  75
+``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``.
  76
+
  77
+Note that Django's default settings live in ``django/conf/global_settings.py``.
  78
+
67 79
 inspectdb [dbname]
68 80
 ------------------
69 81
 
11  docs/settings.txt
@@ -93,6 +93,17 @@ Here's the algorithm Django uses in compiling settings:
93 93
 Note that a settings file should *not* import from ``global_settings``, because
94 94
 that's redundant.
95 95
 
  96
+Seeing which settings you've changed
  97
+------------------------------------
  98
+
  99
+There's an easy way to view which of your settings deviate from the default
  100
+settings. The command ``python manage.py diffsettings`` displays differences
  101
+between the current settings file and Django's default settings.
  102
+
  103
+For more, see the `diffsettings documentation`_.
  104
+
  105
+.. _diffsettings documentation: http://www.djangoproject.com/documentation/django_admin/#diffsettings
  106
+
96 107
 Using settings in Python code
97 108
 =============================
98 109
 

0 notes on commit d6863be

Please sign in to comment.
Something went wrong with that request. Please try again.