-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_command.py
51 lines (43 loc) · 1.25 KB
/
database_command.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
# import subprocess
# import os
# def run_preset_command():
# preset_command = "echo Hello, World!"
#
# result = subprocess.run(preset_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
#
# if result.returncode == 0:
# print(result.stdout)
# else:
# print("Error executing command:")
# print(result.stderr)
#
# run_preset_command()
import subprocess
def run_preset_command(command_number):
if command_number == 1:
preset_command = "flask db init"
elif command_number == 2:
preset_command = "flask db migrate -m 'migrate'"
elif command_number == 3:
preset_command = "flask db upgrade"
elif command_number == 4:
preset_command = "flask run --host=0.0.0.0 --port=5000"
else:
print("Invalid command number")
return
result = subprocess.run(
preset_command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if result.returncode == 0:
print(result.stdout)
else:
print("Error executing command:")
print(result.stderr)
command_number = int(
input("Select a command number\n1: init\n2: migrate\n3: upgrade\n4: run flask\n->")
)
run_preset_command(command_number)