-
Notifications
You must be signed in to change notification settings - Fork 12
/
manage.py
executable file
·51 lines (42 loc) · 1.39 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
49
50
#!/usr/bin/env python
import os
if os.path.exists('.env'):
print('Importing environment from .env...')
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
from app import create_app
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from app import db
from app.models import User
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def test():
from subprocess import call
call(['nosetests', '-v',
'--with-coverage', '--cover-package=app', '--cover-branches',
'--cover-erase', '--cover-html', '--cover-html-dir=cover'])
@manager.command
def adduser(email, username, admin=False):
"""Register a new user."""
from getpass import getpass
password = getpass()
password2 = getpass(prompt='Confirm: ')
if password != password2:
import sys
sys.exit('Error: passwords do not match.')
db.create_all()
user = User(email=email, username=username, password=password,
is_admin=admin)
db.session.add(user)
db.session.commit()
db.session.add(user.follow(user))
db.session.commit()
print('User {0} was registered successfully.'.format(username))
if __name__ == '__main__':
manager.run()