-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
48 lines (35 loc) · 1.42 KB
/
manage.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
import base64
from flask_migrate import MigrateCommand
from flask_script import Manager
from server import create_app, init_counters
from server.services.users.authentication_service import AuthenticationService
from server.services.users.user_service import UserService
import os
import warnings
# Check that environmental variables are set
for key in ['TM_DB','TM_SECRET','TM_CONSUMER_KEY','TM_CONSUMER_SECRET','TM_ENV']:
if not os.getenv(key):
warnings.warn("%s environmental variable not set." % (key,))
# Initialise the flask app object
application = create_app()
try:
init_counters(application)
except Exception:
warnings.warn('Homepage counters not initialized.')
manager = Manager(application)
# Enable db migrations to be run via the command line
manager.add_command('db', MigrateCommand)
@manager.option('-u', '--user_id', help='Test User ID')
def gen_token(user_id):
""" Helper method for generating valid base64 encoded session tokens """
token = AuthenticationService.generate_session_token_for_user(user_id)
print(f'Raw token is: {token}')
b64_token = base64.b64encode(token.encode())
print(f'Your base64 encoded session token: {b64_token}')
@manager.command
def refresh_levels():
print('Started updating mapper levels...')
users_updated = UserService.refresh_mapper_level()
print(f'Updated {users_updated} user mapper levels')
if __name__ == '__main__':
manager.run()