-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
63 lines (51 loc) · 1.82 KB
/
server.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
# -*- coding: utf-8 -*-
# 好
'''
* This file is part of BT-Scale (https://github.com/danielfaust/bt-scale).
* Copyright (c) 2019 Daniel Faust.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import os
import sys
import json
import traceback
#===============================================
sys.dont_write_bytecode = True
#===============================================
# ensure that the current working directory is the one of this script.
# this is probably bad practice but it safeguards a lot of things.
os.chdir(os.path.dirname(os.path.abspath(__file__)))
SERVER_PORT = 8088
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
storage = {}
class ScaleServer(BaseHTTPRequestHandler):
def log_message(self, format, *args):
return
def do_GET(self):
try:
import server_handler
reload(server_handler)
return server_handler.do_GET(self, storage)
except:
traceback.print_exc()
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
response = {
'error': 'exception-in-server_handler'
}
self.wfile.write(json.dumps(response, indent=2))
httpd = HTTPServer(('0.0.0.0', SERVER_PORT), ScaleServer)
print 'Starting server on port', SERVER_PORT, '...'
httpd.serve_forever()