-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·60 lines (47 loc) · 1.75 KB
/
run.py
File metadata and controls
executable file
·60 lines (47 loc) · 1.75 KB
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
#!/usr/bin/env python
import os
import logging
from queue import Queue
from tornado.httpserver import HTTPServer
from tornado.options import define, options
from tornado.ioloop import IOLoop, PeriodicCallback
from application import create_app
from application.log import LogViewQueue
define("port", default = 80, help = "listen port")
define("root", default = "data", help = "root directory containing audio files")
define("db", default = os.path.join(os.path.dirname(__file__), "music.db"), help = "library database")
settings = {
"debug": True,
"template_path": os.path.join(os.path.dirname(__file__), "application", "templates"),
"static_path": os.path.join(os.path.dirname(__file__), "application", "static"),
"autoreload": False,
}
def print_options(options):
print("Listening on port {port}".format(port = options.port))
print("Root directory is {root}".format(root = options.root))
print("Database is {db}".format(db = options.db))
def init_logging():
access = logging.getLogger("tornado.access")
application = logging.getLogger("tornado.application")
general = logging.getLogger("tornado.general")
queue = Queue(100)
handler = LogViewQueue(queue)
access.addHandler(handler)
application.addHandler(handler)
general.addHandler(handler)
return handler
def main():
"Webserver for music application"
app = create_app(settings)
options.parse_command_line()
print_options(options)
http_server = HTTPServer(app)
http_server.listen(options.port)
app.init_db(options.db)
app.set_root_directory(options.root)
console = init_logging()
app.init_console(console)
PeriodicCallback(app.update_state, 200).start()
IOLoop.current().start()
if __name__ == "__main__":
main()