Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / scripts / upgrade / delete_astakos_users.py @ 50f74340

History | View | Annotate | Download (901 Bytes)

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