Ticket #1549: diffsettings.patch

File diffsettings.patch, 2.5 KB (added by pb@…, 19 years ago)

patch to core/management.py

  • management.py

     
    483483get_admin_index.help_doc = "Prints the admin-index template snippet for the given app name(s)."
    484484get_admin_index.args = APP_ARGS
    485485
     486def _module_to_dict(module, omittable=lambda k: k.startswith('_')):
     487    "Converts a module namespace to a Python dictionary -- used by get_settings_diff"
     488    result = {}
     489    keys = (k for k in dir(module) if not omittable(k))
     490    for key in keys:
     491        # Use repr() so that strings are quoted etc., as in settings.py
     492        result[key] = repr(getattr(module, key))
     493    return result
     494
     495def get_settings_diff():
     496    """
     497    Displays differences between the current project's settings.py
     498    and Django's default settings. Setting names that do not appear
     499    in the defaults are followed by "###". Inspired by Postfix's
     500    "postconf -n".
     501    """
     502    from django.conf import settings
     503    from django.conf import global_settings
     504
     505    user_settings = _module_to_dict(settings)
     506    default_settings = _module_to_dict(global_settings)
     507
     508    output = ""
     509    for key in sorted(user_settings):   
     510        if key not in default_settings:
     511            output += "%s = %s  ###\n" % (key, user_settings[key])
     512        elif user_settings[key] != default_settings[key]:
     513            output += "%s = %s\n" % (key, user_settings[key])
     514    print output
     515get_settings_diff.args = ""
     516get_settings_diff.help_doc = "Displays differences between the current project's settings.py and Django's default settings. Settings with no corresponding default values are followed by '###'."
     517
    486518def install(app):
    487519    "Executes the equivalent of 'get_sql_all' in the current database."
    488520    from django.db import connection, transaction
     
    9821014DEFAULT_ACTION_MAPPING = {
    9831015    'adminindex': get_admin_index,
    9841016    'createcachetable' : createcachetable,
     1017    'diffsettings': get_settings_diff,
    9851018    'inspectdb': inspectdb,
    9861019    'install': install,
    9871020    'reset': reset,
     
    10031036NO_SQL_TRANSACTION = (
    10041037    'adminindex',
    10051038    'createcachetable',
     1039    'diffsettings',
    10061040    'install',
    10071041    'reset',
    10081042    'sqlindexes'
     
    10671101
    10681102    if action == 'shell':
    10691103        action_mapping[action](options.plain is True)
    1070     elif action in ('syncdb', 'validate'):
     1104    elif action in ('syncdb', 'validate', 'diffsettings'):
    10711105        action_mapping[action]()
    10721106    elif action == 'inspectdb':
    10731107        try:
Back to Top