2019-03-07 14:46:50 +01:00
|
|
|
from os import listdir
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
import tornado.gen
|
|
|
|
import tornado.httpserver
|
|
|
|
import tornado.ioloop
|
|
|
|
import tornado.web
|
|
|
|
import tornado.netutil
|
2019-03-07 14:04:54 +01:00
|
|
|
|
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
def make_app():
|
|
|
|
routes = []
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
def get_files(dir):
|
|
|
|
return [d for d in listdir(dir) if not d.startswith("_")]
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
def map_out(dir):
|
|
|
|
apis = get_files(dir)
|
|
|
|
for api in apis:
|
|
|
|
endpoint = ""
|
|
|
|
if api.endswith(".py"):
|
|
|
|
api = api.rstrip(".py")
|
|
|
|
routes.append(
|
|
|
|
{
|
|
|
|
"/%s/%s" % (dir, api): __import__("%s.%s" % (dir.replace("/", "."), api), fromlist=[""])
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
map_out("%s/%s" % (dir, api))
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
map_out("api")
|
|
|
|
return routes
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
r"/api/%s/%s"
|
2019-03-07 14:04:54 +01:00
|
|
|
|
2019-03-07 14:46:50 +01:00
|
|
|
return tornado.web.Application(routes)
|