[web] Add /options/dump API to backend.

This commit is contained in:
Matthew Shao 2017-07-24 20:32:46 +08:00
parent 6c4dbcc7a7
commit 38d926d159

View File

@ -451,6 +451,22 @@ class Options(RequestHandler):
raise APIError(400, "{}".format(err)) raise APIError(400, "{}".format(err))
class DumpOptions(RequestHandler):
def get(self):
self.set_header("Content-Disposition", "attachment; filename=options")
self.set_header("Content-Type", "application/octet-stream")
data = optmanager.save(self.master.options)
self.write(data)
def post(self):
try:
data = optmanager.parse(self.filecontents)
self.master.options.update(**data)
except Exception as err:
raise APIError(400, "{}".format(err))
class Application(tornado.web.Application): class Application(tornado.web.Application):
def __init__(self, master, debug): def __init__(self, master, debug):
self.master = master self.master = master
@ -475,7 +491,8 @@ class Application(tornado.web.Application):
FlowContentView), FlowContentView),
(r"/settings", Settings), (r"/settings", Settings),
(r"/clear", ClearAll), (r"/clear", ClearAll),
(r"/options", Options) (r"/options", Options),
(r"/options/dump", DumpOptions)
] ]
settings = dict( settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"), template_path=os.path.join(os.path.dirname(__file__), "templates"),