-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbootstrap.py
68 lines (46 loc) · 1.68 KB
/
bootstrap.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import print_function
from getpass import getpass
import readline
import sys
import migrate.versioning.api as migrate
import annotateit
from annotateit import db
from annotateit.model import Consumer, User
if __name__ == '__main__':
r = raw_input("This migration will perform initial setup of the annotation \n"
"store, and create the required admin accounts. Proceed? [Y/n] ")
if r and r[0] in ['n', 'N']:
sys.exit(1)
print("\nCreating SQLite database and ElasticSearch indices... ", end="")
app = annotateit.create_app()
annotateit.create_indices(app)
migrate_args = dict(url=app.config['SQLALCHEMY_DATABASE_URI'], debug='False', repository='migration')
migrate.version_control(**migrate_args)
migrate.upgrade(**migrate_args)
print("done.\n")
username = raw_input("Admin username [admin]: ").strip()
if not username:
username = 'admin'
email = ''
while not email:
email = raw_input("Admin email: ").strip()
password = ''
while not password:
password = getpass("Admin password: ")
ckey = raw_input("Primary consumer key [annotateit]: ").strip()
if not ckey:
ckey = 'annotateit'
with app.test_request_context():
print("\nCreating admin user... ", end="")
u = User(username, email, password)
u.is_admin = True
db.session.add(u)
db.session.commit()
print("done.")
print("Creating primary consumer... ", end="")
c = Consumer(ckey)
c.user_id = u.id
db.session.add(c)
db.session.commit()
print("done.\n")
print("Primary consumer secret: %s" % c.secret)