-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
108 lines (80 loc) · 2.82 KB
/
run.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'''
This is a file that configures how your server runs
You may eventually wish to have your own explicit config file
that this reads from.
For now this should be sufficient.
Keep it clean and keep it simple, you're going to have
Up to 5 people running around breaking this constantly
If it's all in one file, then things are going to be hard to fix
If in doubt, `import this`
'''
#-----------------------------------------------------------------------------
import sys
from bottle import run
#-----------------------------------------------------------------------------
# You may eventually wish to put these in their own directories and then load
# Each file separately
# For the template, we will keep them together
import model
import view
import controller
#-----------------------------------------------------------------------------
# It might be a good idea to move the following settings to a config file and then load them
# Change this to your IP address or 0.0.0.0 when actually hosting
host = 'localhost'
# Test port, change to the appropriate port to host
port = 8080
# Turn this off for production
debug = True
def run_server():
'''
run_server
Runs a bottle server
'''
run(host=host, port=port, debug=debug)
#-----------------------------------------------------------------------------
# Optional SQL support
# Comment out the current manage_db function, and
# uncomment the following one to load an SQLite3 database
# def manage_db():
# '''
# Blank function for database support, use as needed
# '''
# pass
# """
import sql
def manage_db():
'''
manage_db
Starts up and re-initialises an SQL databse for the server
'''
sql_db = sql.SQLDatabase()
sql_db.database_setup()
return
# """
#-----------------------------------------------------------------------------
# What commands can be run with this python file
# Add your own here as you see fit
command_list = {
'manage_db' : manage_db,
'server' : run_server
}
# The default command if none other is given
default_command = 'server'
def run_commands(args):
'''
run_commands
Parses arguments as commands and runs them if they match the command list
:: args :: Command line arguments passed to this function
'''
commands = args[1:]
# Default command
if len(commands) == 0:
commands = [default_command]
for command in commands:
if command in command_list:
command_list[command]()
else:
print("Command '{command}' not found".format(command=command))
#-----------------------------------------------------------------------------
run_commands(sys.argv)