mirror of
https://github.com/brmlab/brmbar.git
synced 2025-08-02 07:23:36 +02:00
rework server to use flask, new items
This commit is contained in:
parent
99893f58a0
commit
bd828a71e8
8 changed files with 84 additions and 35 deletions
|
@ -1,41 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/python
|
||||
|
||||
import BaseHTTPServer
|
||||
from flask import Flask, render_template
|
||||
|
||||
class BrmbarHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
app = Flask('BrmBar')
|
||||
|
||||
def do_GET(self):
|
||||
action = self.path.split('/')[1:]
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
if action[0] == 'code':
|
||||
self.code(action[1])
|
||||
return
|
||||
@app.route('/code/<code>')
|
||||
def code(code):
|
||||
return 'CODE "%s" received' % code
|
||||
|
||||
if action[0] == 'favicon.ico':
|
||||
self.send_file('favicon.png', 'image/png')
|
||||
return
|
||||
@app.route('/admin/')
|
||||
def admin():
|
||||
return render_template('admin.html')
|
||||
|
||||
self.send_response(404)
|
||||
@app.route('/log/')
|
||||
def log():
|
||||
return render_template('log.html')
|
||||
|
||||
def code(self, code):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
self.end_headers()
|
||||
self.wfile.write('CODE "%s" received\n' % code)
|
||||
@app.route('/stats/')
|
||||
def stats():
|
||||
return render_template('stats.html')
|
||||
|
||||
def send_file(self, filename, mimetype):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', mimetype)
|
||||
self.end_headers()
|
||||
f = open(filename, 'r')
|
||||
self.wfile.write(f.read())
|
||||
f.close()
|
||||
|
||||
try:
|
||||
server_address = ('', 8000)
|
||||
httpd = BaseHTTPServer.HTTPServer(server_address, BrmbarHandler)
|
||||
print 'Starting BrmBar server ...'
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print 'Shutting down ...'
|
||||
httpd.socket.close()
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
5
server/templates/admin.html
Normal file
5
server/templates/admin.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Admin{% endblock %}
|
||||
{% block content %}
|
||||
admin
|
||||
{% endblock %}
|
15
server/templates/base.html
Normal file
15
server/templates/base.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>BrmBar: {% block title %}{% endblock %}</title>
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png">
|
||||
</head>
|
||||
<body>
|
||||
<h1><img src="/static/favicon.png" valign="middle" /> BrmBar: {{ self.title() }}</h1>
|
||||
<div id="menu">
|
||||
<a href="/">home</a> | <a href="/stats/">stats</a> | <a href="/log/">log</a> | <a href="/admin/">admin</a>
|
||||
</div>
|
||||
<div id="content">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
5
server/templates/index.html
Normal file
5
server/templates/index.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Welcome{% endblock %}
|
||||
{% block content %}
|
||||
welcome
|
||||
{% endblock %}
|
5
server/templates/log.html
Normal file
5
server/templates/log.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Log{% endblock %}
|
||||
{% block content %}
|
||||
log
|
||||
{% endblock %}
|
5
server/templates/stats.html
Normal file
5
server/templates/stats.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Stats{% endblock %}
|
||||
{% block content %}
|
||||
stats
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue