-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
68 lines (61 loc) · 1.96 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
67
68
import subprocess
import click
from app import app
from shopyoapi.cmd import clean
from shopyoapi.cmd import create_box
from shopyoapi.cmd import create_module
from shopyoapi.cmd import create_module_in_box
from shopyoapi.cmd import initialise
from shopyoapi.cmd import collectstatic
from shopyoapi.database import autoload_models
from shopyoapi.info import printinfo
def runserver():
app.run(host="0.0.0.0")
@click.command()
@click.argument("args", nargs=-1)
def process(args):
printinfo()
if args[0] == "initialise" or args[0] == "initialize":
autoload_models()
initialise()
elif args[0] == "clean":
clean()
elif args[0] == "runserver":
runserver()
elif args[0] == "rundebug":
app.run(debug=True, host="0.0.0.0")
try:
if args[1]:
app.run(debug=True, host="0.0.0.0", port=int(args[1]))
except IndexError as e:
raise e
elif args[0] == "collectstatic":
if len(args) == 1:
collectstatic()
elif len(args) == 2:
collectstatic(target_module=args[1])
elif args[0] == "test":
print("test ok")
elif args[0] == "startapp" and args[1]:
create_module(args[1])
elif args[0] == "startbox" and args[1]:
create_box(args[1])
elif args[0] == "startsubapp" and args[1] and args[3]:
if args[2].lower() == "in":
create_module_in_box(args[1], args[3])
elif args[0] == "db":
try:
autoload_models()
if args[1] == "migrate":
subprocess.run(["flask", "db", "migrate"])
elif args[1] == "upgrade":
subprocess.run(["flask", "db", "upgrade"])
elif args[1] == "init":
subprocess.run(["flask", "db", "init"])
except IndexError as e:
print("db requires more options")
raise e
else:
print("Command not recognised")
if __name__ == "__main__":
process()