-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.py
More file actions
executable file
·59 lines (42 loc) · 1.56 KB
/
run_server.py
File metadata and controls
executable file
·59 lines (42 loc) · 1.56 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
import os
import logging
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.wsgi
from django.core.wsgi import get_wsgi_application
from tornado.options import options, define, parse_command_line
define('port', type=int, default=8000)
define('root', type=str, default=' ')
def main():
os.environ['DJANGO_SETTINGS_MODULE'] = 'plexrequests.settings'
parse_command_line()
wsgi_app = get_wsgi_application()
container = tornado.wsgi.WSGIContainer(wsgi_app)
static_path = os.getcwd() + "/static/"
root_url_file = open('plexrequests/root_url.txt', 'w+')
if len(options.root) is 1:
root = ''
else:
root = options.root
root_url_file.write(root)
root_url_file.close()
tornado_app = tornado.web.Application(
[
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path}),
(r'.*', tornado.web.FallbackHandler, dict(fallback=container)),
])
os.system('python manage.py migrate')
os.system('python manage.py collectstatic -v 0 --clear --noinput')
os.system('python manage.py loaddata default.config.json')
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
logger = logging.getLogger(__name__)
logger.info('Server started at http://localhost:{}/{}'.format(options.port, options.root))
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
tornado.ioloop.IOLoop.instance().stop()
logger.info('Server stopped')
if __name__ == '__main__':
main()