forked from metabrainz/artwork-redirect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverart_redirect_server.py
executable file
·68 lines (47 loc) · 1.64 KB
/
coverart_redirect_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
64
65
66
67
#!/usr/bin/env python
import os
import sys
from coverart_redirect.server import make_application
from coverart_redirect.config import Config
def production (addr, port, application):
import cherrypy
from cherrypy import wsgiserver
server = wsgiserver.CherryPyWSGIServer((addr, port), application)
cherrypy.config.update({
'log.screen': True,
"server.thread_pool" : 10
})
cherrypy.log("server starting")
try:
server.start()
except KeyboardInterrupt:
server.stop()
def development (addr, port, application):
from werkzeug import run_simple
run_simple (addr, port, application, use_reloader=True,
extra_files=None, reloader_interval=1, threaded=False,
processes=1, request_handler=None)
def help ():
print """
syntax: python coverart_redirect_server.py [options]
options:
--help This message
-r, --development Use werkzeug development server (restarts on source code changes)
"""
sys.exit (0)
if __name__ == '__main__':
config_path = os.path.dirname(os.path.abspath(__file__)) + '/coverart_redirect.conf'
static_path = os.path.dirname(os.path.abspath(__file__)) + '/static'
config = Config(config_path, static_path)
application = make_application(config)
addr = config.listen.addr
port = int(config.listen.port)
option = None
if len (sys.argv) > 1:
option = sys.argv.pop ()
if option == '--help':
help ()
elif option == '-r' or option == '--development':
development (addr, port, application)
else:
production (addr, port, application)