~grupoesoc/cubicerp-addons/7.0

« back to all changes in this revision

Viewing changes to report_geraldo/lib/geraldo/site/newsite/django_1_0/django/core/management/commands/diffsettings.py

  • Committer: Cubic ERP
  • Date: 2014-01-07 15:38:09 UTC
  • Revision ID: info@cubicerp.com-20140107153809-4jmif3zoi8rcveve
[ADD] cubicReport

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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._import_settings()
 
20
 
 
21
        user_settings = module_to_dict(settings._target)
 
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)