forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.py
46 lines (36 loc) · 1.29 KB
/
create_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import argparse
import getpass
import re
import sys
from flask_migrate import stamp
from app import current_app
from app.models import db
from populate_db import populate
from tests.unittests.auth_helper import create_super_admin
def _validate_email(email):
if not re.match(r'[^@]+@[^@]+\.[^@]+', email):
print('\nInvalid email address')
sys.exit(1)
def _validate_password(password):
if len(password) < 4:
print('\nPassword should have minimum 4 characters')
sys.exit(1)
def create_default_user(email, password):
print("Your login is 'super_admin'.")
if not email:
email = input("Enter email for super_admin : ")
_validate_email(email)
if not password:
password = getpass.getpass("Enter password for super_admin : ")
_validate_password(password)
create_super_admin(email, password)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("email", nargs='?', help="The email for super_admin.", default='')
parser.add_argument("password", nargs='?', help="The password for super_admin.", default='')
parsed = parser.parse_args()
with current_app.app_context():
db.create_all()
stamp()
create_default_user(parsed.email, parsed.password)
populate()