Commit 768bab56 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Astakos 0.13 upgrade contrib scripts

Include upgrade to 0.13 helper scripts in synnefo contrib
parent e5de391d
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
from django.conf import settings
from astakos.im.models import AstakosUser
def duplicate_users():
for u in AstakosUser.objects.filter():
if AstakosUser.objects.filter(email__iexact=u.email).count() > 1:
print AstakosUser.objects.filter(email__iexact=u.email).values('pk',
'email',
'is_active')
if len(sys.argv) == 2:
pk = int(sys.argv[1])
user = AstakosUser.objects.get(pk=pk)
if AstakosUser.objects.filter(email__iexact=user.email).count() == 1:
print "No duplicate emails found for user %s" % (user)
exit()
user = AstakosUser.objects.get(pk=pk)
print "Deleting user %r" % (user)
user.delete()
exit()
else:
duplicate_users()
#!/usr/bin/env python
import os
import sys
from time import sleep
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
import astakos
from astakos.im.models import AstakosUser as A
def user_filter(user):
return A.objects.filter(email__iexact=user.email).count() > 1
argv = sys.argv
argc = len(sys.argv)
if argc < 2:
print "Usage: ./delete_astakos_users.py <id>..."
raise SystemExit()
id_list = [int(x) for x in argv[1:]]
print ""
print "This will permanently delete the following users:\n"
print "id: email"
print "-- -----"
users = A.objects.filter(id__in=id_list)
for user in users:
print "%s: %s" % (user.id, user.email)
print "\nExecute? (yes/no): ",
line = raw_input().rstrip()
if line != 'yes':
print "\nCancelled"
raise SystemExit()
print "\nConfirmed."
sleep(2)
for user in users:
print "deleting %s: %s" % (user.id, user.email)
user.delete()
#!/usr/bin/env python
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
import astakos
from astakos.im.models import AstakosUser as A
def user_filter(user):
return A.objects.filter(email__iexact=user.email).count() > 1
all_users = list(A.objects.all())
userlist = [(str(u.pk) + ': ' + str(u.email)) for u in
filter(user_filter, all_users)]
sys.stderr.write("id: email\n")
print "\n".join(userlist)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment