forked from notner/Medusa
/
head.py
executable file
·57 lines (39 loc) · 1.56 KB
/
head.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
#!/usr/bin/env python
"""
Medusa's Head serves the web interface, API, and communicates instructions
to the Snakes (media players).
"""
import os
import flask
from lib.head.api import api
from lib.head.index import Index
from lib.head.proxy import Proxy
from lib.medusa.communicate import Communicate
from lib.medusa.config import config
from lib.medusa.log import log
from lib.view.pages import pages
#------------------------------------------------------------------------------
PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib/view")
API_BASE = config.get("head", "api_base")
URL_BASE = config.get("head", "url_base")
#------------------------------------------------------------------------------
Index()
Communicate(proxy=Proxy)
#------------------------------------------------------------------------------
app = flask.Flask(__name__,
template_folder="%s/templates" % PATH,
static_folder="%s/static" % PATH,
static_url_path="/%s/static" % URL_BASE)
app.register_blueprint(api, url_prefix="/%s/%s" % (URL_BASE, API_BASE))
app.register_blueprint(pages, url_prefix="/%s" % URL_BASE)
#------------------------------------------------------------------------------
@app.route("/")
def root():
return flask.redirect("/%s" % URL_BASE)
#------------------------------------------------------------------------------
if __name__ == "__main__":
try:
log.warn("Head initialised")
app.run(host="0.0.0.0", port=config.getint("ports", "head"))
finally:
log.warn("Head exited")