root / snf-astakos-app / astakos / im / scripts / delete_astakos_users.py @ 55f8c5d8
History | View | Annotate | Download (901 Bytes)
1 |
#!/usr/bin/env python
|
---|---|
2 |
|
3 |
import os |
4 |
import sys |
5 |
from time import sleep |
6 |
|
7 |
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings' |
8 |
|
9 |
import astakos |
10 |
from astakos.im.models import AstakosUser as A |
11 |
|
12 |
def user_filter(user): |
13 |
return A.objects.filter(email__iexact=user.email).count() > 1 |
14 |
|
15 |
argv = sys.argv |
16 |
argc = len(sys.argv)
|
17 |
|
18 |
if argc < 2: |
19 |
print "Usage: ./delete_astakos_users.py <id>..." |
20 |
raise SystemExit() |
21 |
|
22 |
id_list = [int(x) for x in argv[1:]] |
23 |
|
24 |
print "" |
25 |
print "This will permanently delete the following users:\n" |
26 |
print "id: email" |
27 |
print "-- -----" |
28 |
|
29 |
users = A.objects.filter(id__in=id_list) |
30 |
for user in users: |
31 |
print "%s: %s" % (user.id, user.email) |
32 |
|
33 |
print "\nExecute? (yes/no): ", |
34 |
line = raw_input().rstrip()
|
35 |
if line != 'yes': |
36 |
print "\nCancelled" |
37 |
raise SystemExit() |
38 |
|
39 |
print "\nConfirmed." |
40 |
sleep(2)
|
41 |
for user in users: |
42 |
print "deleting %s: %s" % (user.id, user.email) |
43 |
user.delete() |
44 |
|