File: utils.py

package info (click to toggle)
django-guardian 2.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,732 kB
  • sloc: python: 5,987; javascript: 1,396; makefile: 91; sh: 12
file content (25 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def show_settings(settings, action):
    import guardian
    from django.utils.termcolors import colorize

    guardian_path = guardian.__path__[0]
    msg = "django-guardian module's path: %r" % guardian_path
    print(colorize(msg, fg='magenta'))
    db_conf = settings.DATABASES['default']
    output = []
    msg = "Starting {} for db backend: {}".format(action, db_conf['ENGINE'])
    embracer = '=' * len(msg)
    output.append(msg)
    for key in sorted(db_conf.keys()):
        if key == 'PASSWORD':
            value = '****************'
        else:
            value = db_conf[key]
        line = '    {}: "{}"'.format(key, value)
        output.append(line)
    embracer = colorize('=' * len(max(output, key=lambda s: len(s))),
                        fg='green', opts=['bold'])
    output = [colorize(line, fg='blue') for line in output]
    output.insert(0, embracer)
    output.append(embracer)
    print('\n'.join(output))