-
Notifications
You must be signed in to change notification settings - Fork 3
/
gkcore_cli.py
executable file
·87 lines (73 loc) · 2.33 KB
/
gkcore_cli.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
from sys import argv as args
import subprocess as cmd
import os, sys
help_text = """\t
This script helps your setup / run gkcore - GNUKhata's REST API service
USAGE: ./gkcore_cli.py [OPTION]
OPTIONS:
\tinit - Initialize the database
\tmigrate - Perform migrations on existing database
\tserve - Start the development server
\tdeploy - Start the production server
\tdump - Export a snapshot of the database to a file
"""
def check_flags(arg):
"""Validate script arguments & run appropriate action"""
if arg == "init":
if sys.platform.startswith("win"):
cmd.run(["docker-compose", "up", "-d"])
cmd.run(["pip", "install", "-r", "requirements.txt"])
cmd.run(["python", "setup.py", "develop"])
cmd.run(["python", "initdb.py"])
return
else:
cmd.run(["docker-compose", "up", "-d"])
cmd.run(["pip", "install", "-r", "requirements.txt"])
cmd.run(["python3", "setup.py", "develop"])
cmd.run(["python3", "initdb.py"])
return
elif arg == "migrate":
if sys.platform.startswith("win"):
cmd.run(["python", "db_migrate.py"])
return
cmd.run(["python3", "db_migrate.py"])
return
elif arg == "serve":
# if sys.platform.startswith("win"):
# cmd.run(["docker-compose", "up", "-d"])
# cmd.run(["pserve", "development.ini", "--reload"])
# return
cmd.run(["docker-compose", "up", "-d"])
cmd.run(["pserve", "development.ini", "--reload"])
return
elif arg == "deploy":
# if sys.platform.startswith("win"):
# cmd.run(["docker-compose", "up", "-d"])
# cmd.run(["pserve", "production.ini"])
# return
cmd.run(["docker-compose", "up", "-d"])
cmd.run(["pserve", "production.ini"])
return
elif arg == "dump":
cmd.run(
[
"docker-compose",
"exec",
"db",
"pg_dump",
"-U",
"gkadmin",
"-d",
"gkdata",
">",
"gkdump.sql",
]
)
return
else:
print(help_text)
if len(args) == 2:
check_flags(args[1])
else:
print(help_text)