#!/usr/bin/python3
import os, sys, django

def usage() :
    print("""\
Usage: $0 adminLoginName admin.email@example.com passwordForShell
parameters:
- adminLoginName          the login name for the administrator
- admin.email@example.com the email address of the administrator
- passwordForShell        a password; beware of characters not supported by sh""")

if __name__ == "__main__" :
    if len(sys.argv) < 4:
        usage()
    else:
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wimsLTI.settings')
        django.setup()
        from django.contrib.auth.models import User
        user, _ =User.objects.get_or_create(username=sys.argv[1])
        user.email=sys.argv[2]
        user.set_password(sys.argv[3])
        user.is_superuser=True
        user.is_staff=True
        user.last_name="Admin"
        user.save()
        print(user.last_name, user.email)
        print("Superuser {} a été enregistré".format(user.username))
            
