root / snf-astakos-app / astakos / im / management / commands / fix-superusers.py @ 4220c336
History | View | Annotate | Download (2.2 kB)
1 | a7752e95 | Sofia Papagiannaki | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | a7752e95 | Sofia Papagiannaki | #
|
3 | a7752e95 | Sofia Papagiannaki | # Redistribution and use in source and binary forms, with or
|
4 | a7752e95 | Sofia Papagiannaki | # without modification, are permitted provided that the following
|
5 | a7752e95 | Sofia Papagiannaki | # conditions are met:
|
6 | a7752e95 | Sofia Papagiannaki | #
|
7 | a7752e95 | Sofia Papagiannaki | # 1. Redistributions of source code must retain the above
|
8 | a7752e95 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
9 | a7752e95 | Sofia Papagiannaki | # disclaimer.
|
10 | a7752e95 | Sofia Papagiannaki | #
|
11 | a7752e95 | Sofia Papagiannaki | # 2. Redistributions in binary form must reproduce the above
|
12 | a7752e95 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
13 | a7752e95 | Sofia Papagiannaki | # disclaimer in the documentation and/or other materials
|
14 | a7752e95 | Sofia Papagiannaki | # provided with the distribution.
|
15 | a7752e95 | Sofia Papagiannaki | #
|
16 | a7752e95 | Sofia Papagiannaki | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a7752e95 | Sofia Papagiannaki | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a7752e95 | Sofia Papagiannaki | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a7752e95 | Sofia Papagiannaki | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a7752e95 | Sofia Papagiannaki | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a7752e95 | Sofia Papagiannaki | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a7752e95 | Sofia Papagiannaki | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a7752e95 | Sofia Papagiannaki | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a7752e95 | Sofia Papagiannaki | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a7752e95 | Sofia Papagiannaki | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a7752e95 | Sofia Papagiannaki | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a7752e95 | Sofia Papagiannaki | # POSSIBILITY OF SUCH DAMAGE.
|
28 | a7752e95 | Sofia Papagiannaki | #
|
29 | a7752e95 | Sofia Papagiannaki | # The views and conclusions contained in the software and
|
30 | a7752e95 | Sofia Papagiannaki | # documentation are those of the authors and should not be
|
31 | a7752e95 | Sofia Papagiannaki | # interpreted as representing official policies, either expressed
|
32 | a7752e95 | Sofia Papagiannaki | # or implied, of GRNET S.A.
|
33 | e47b76a5 | Georgios D. Tsoukalas | |
34 | a7752e95 | Sofia Papagiannaki | from optparse import make_option |
35 | a7752e95 | Sofia Papagiannaki | from datetime import datetime |
36 | a7752e95 | Sofia Papagiannaki | |
37 | 1808f7bc | Giorgos Korfiatis | from django.db import transaction |
38 | a7752e95 | Sofia Papagiannaki | from django.core.management.base import NoArgsCommand, CommandError |
39 | a7752e95 | Sofia Papagiannaki | |
40 | 1808f7bc | Giorgos Korfiatis | from astakos.im.auth import fix_superusers |
41 | a7752e95 | Sofia Papagiannaki | |
42 | a7752e95 | Sofia Papagiannaki | |
43 | a7752e95 | Sofia Papagiannaki | class Command(NoArgsCommand): |
44 | e47b76a5 | Georgios D. Tsoukalas | help = "Transform superusers created by syncdb into AstakosUser instances"
|
45 | a7752e95 | Sofia Papagiannaki | |
46 | 1808f7bc | Giorgos Korfiatis | @transaction.commit_on_success
|
47 | a7752e95 | Sofia Papagiannaki | def handle(self, **options): |
48 | a7752e95 | Sofia Papagiannaki | try:
|
49 | 1808f7bc | Giorgos Korfiatis | fixed = fix_superusers() |
50 | 1808f7bc | Giorgos Korfiatis | count = len(fixed)
|
51 | 1808f7bc | Giorgos Korfiatis | if count != 0: |
52 | 4220c336 | Giorgos Korfiatis | self.stderr.write("Fixed %s superuser(s).\n" % count) |
53 | 1808f7bc | Giorgos Korfiatis | else:
|
54 | 4220c336 | Giorgos Korfiatis | self.stderr.write("No superuser needed a fix.\n") |
55 | a7752e95 | Sofia Papagiannaki | except BaseException, e: |
56 | e47b76a5 | Georgios D. Tsoukalas | raise CommandError(e) |