2012-12-13 21:48:45 +01:00
|
|
|
from optparse import make_option
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from zephyr.models import User
|
|
|
|
import simplejson
|
|
|
|
|
|
|
|
def dump():
|
|
|
|
passwords = []
|
|
|
|
for u in User.objects.all():
|
|
|
|
passwords.append((u.email, u.password))
|
|
|
|
file("dumped-passwords", "w").write(simplejson.dumps(passwords) + "\n")
|
|
|
|
|
|
|
|
def restore(change):
|
|
|
|
for (email, password) in simplejson.loads(file("dumped-passwords").read()):
|
2012-12-14 00:55:06 +01:00
|
|
|
try:
|
|
|
|
user = User.objects.get(email__iexact=email)
|
|
|
|
except User.DoesNotExist:
|
|
|
|
print "Skipping...", email
|
|
|
|
continue
|
2012-12-13 21:48:45 +01:00
|
|
|
if change:
|
|
|
|
user.password = password
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('--restore', default=False, action='store_true'),
|
|
|
|
make_option('--dry-run', '-n', default=False, action='store_true'),)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
if options["restore"]:
|
|
|
|
restore(change=not options['dry_run'])
|
|
|
|
else:
|
|
|
|
dump()
|