-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
121 lines (98 loc) · 3.28 KB
/
main.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
109
110
111
112
113
114
115
116
117
118
119
from socket import gethostname
import os
import sys
from flask import Flask, render_template, session
# Test config.py exists
try:
import config
config.screen_resolution
except ImportError:
print "ERROR: no config set"
print "Please copy config.py.example to config.py and customise."
sys.exit(1)
except AttributeError, ex:
print "ERROR: config has required attribute missing - see config.py.example."
print ex.args
sys.exit(1)
# Bring external libraries into path
my_path = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.join(my_path, 'external')
for name in [name for name in os.listdir(lib_path)]:
full_path = os.path.join(lib_path, name)
if os.path.isdir(full_path):
#print 'Adding external lib at: %s' % full_path
sys.path.append(full_path)
import utils
extensions = []
app = Flask(__name__)
app.secret_key = 'Njminqche9vugWutU3HVsJQKAB'
# Load all extensions, which define the available buttons
my_path = os.path.dirname(os.path.realpath(__file__))
extensions_path = os.path.join(my_path, 'extensions')
for root, dirs, files in os.walk(extensions_path):
for name in files:
if name.endswith(".py") and not name.startswith("__"):
path = os.path.join(root, name)
modulename = 'extensions.' + name.rsplit('.', 1)[0]
__import__(modulename)
module = sys.modules[modulename]
m_config = module.mediaweb_config
app.register_blueprint(m_config['blueprint'])
extensions.append(m_config)
def order(x):
try:
return config.order.index(x['id'])
except:
return sys.maxint
extensions.sort(key=order)
PORT = 8080
HOST = gethostname()
@app.route("/old")
def old():
msg = session.pop('msg', None)
return render_template(
'index.html',
host=HOST,
port=PORT,
status=msg,
screen=utils.screen_size(),
extensions=extensions,
)
@app.route("/")
def index():
msg = session.pop('msg', None)
return render_template(
'jqm.html',
host=HOST.split('.')[0],
port=PORT,
status=msg,
screen=utils.screen_size(),
extensions=extensions,
)
import pybonjour
def register_callback(sdRef, flags, errorCode, name, regtype, domain):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Registered service:'
print ' name =', name
print ' regtype =', regtype
print ' domain =', domain
if __name__ == "__main__":
#name = "media-web@%s" % HOST
#regtype= "_http._tcp"
#sdRef = pybonjour.DNSServiceRegister(name=name,
#regtype=regtype,
#port=PORT,
#callBack=register_callback)
#pybonjour.DNSServiceProcessResult(sdRef)
try:
app.run(
host='0.0.0.0',
port=PORT,
#debug='Pro' in HOST,
debug=True,
)
except KeyboardInterrupt:
#print "Deregistering with bonjour"
#sdRef.close()
#pybonjour.DNSServiceRefDeallocate(sdRef)
pass