-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
executable file
·66 lines (53 loc) · 2.08 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
manage.py
Scripts for running the applications
"""
import subprocess as sp
from flask_script import Manager, Shell, Server as OldServer
from flask_migrate import MigrateCommand, Migrate
from Application import create_app, db
from Application.settings import get_config_for_current_environment
from Application.auth.models import User
app = create_app(get_config_for_current_environment())
manager = Manager(app)
migrate = Migrate(app, db)
class Server(OldServer):
def __call__(self, *args, **kwargs):
app.config["ASSETS_URL"] = "http://localhost:5001/static/"
webpack_server = sp.Popen(["/usr/bin/node",
"node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"--content-base", "Application/static",
"--output-public-path", "http://localhost:5000/static/",
"--inline",
"--hot",
"--port", "5001",
], cwd="Application/app_src")
super().__call__(*args, **kwargs)
def _make_context():
"""Return context dict for a shell session so you can access
app, db, and the User model by default.
"""
return {'app': app, 'db': db, 'User': User}
@manager.command
def create_user():
"""Create a superuser"""
import getpass
user = input("Username [{}]: ".format(getpass.getuser()))
if not user:
user = getpass.getuser()
pprompt = lambda: (getpass.getpass(), getpass.getpass('Retype password: '))
p1, p2 = pprompt()
while p1 != p2:
print('Passwords do not match. Try again')
p1, p2 = pprompt()
User.create(username=user, password=p1, active=True, is_admin=True)
print('Administrator account created for {}'.format(user))
@manager.command
def npm_update():
sp.run(["/usr/bin/npm", "update"], cwd="Application/app_src", check=True)
manager.add_command('runserver', Server(threaded=True))
manager.add_command('shell', Shell(make_context=_make_context))
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()