From f0fd33fb11513a3e74079eaed5f5c1b8bb4e561d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 21 Jun 2012 15:39:40 +1200 Subject: Log inspection and manipulation from tests. --- libpathod/app.py | 37 ++++++++++--------------------------- libpathod/test.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 27 deletions(-) (limited to 'libpathod') diff --git a/libpathod/app.py b/libpathod/app.py index 95e7d169..1e65bc4f 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -9,37 +9,20 @@ def api_info(): ) -""" -class APILog(tornado.web.RequestHandler): - def get(self): - self.write( - dict( - d = self.application.get_log() - ) - ) - - -class APILogClear(tornado.web.RequestHandler): - def post(self): - self.application.clear_log() - self.write("OK") - +@app.route('/api/log') +def api_log(): + return jsonify( + log = app.config["pathod"].get_log() + ) -class APIShutdown(tornado.web.RequestHandler): - def post(self): - tornado.ioloop.IOLoop.instance().stop() - self.write("OK") - -class APIInfo(tornado.web.RequestHandler): - def get(self): - self.write( - dict( - version = version.IVERSION - ) - ) +@app.route('/api/clear_log') +def api_clear_log(): + app.config["pathod"].clear_log() + return "OK" +""" class _Page(tornado.web.RequestHandler): def render(self, name, **kwargs): tornado.web.RequestHandler.render(self, name + ".html", **kwargs) diff --git a/libpathod/test.py b/libpathod/test.py index 5fba17d5..943fe3c0 100644 --- a/libpathod/test.py +++ b/libpathod/test.py @@ -14,10 +14,30 @@ class Daemon: self.urlbase = "%s://%s:%s"%("https" if ssl else "http", IFACE, self.port) def info(self): + """ + Return some basic info about the remote daemon. + """ resp = requests.get("%s/api/info"%self.urlbase, verify=False) return resp.json + def log(self): + """ + Return the log buffer as a list of dictionaries. + """ + resp = requests.get("%s/api/log"%self.urlbase, verify=False) + return resp.json["log"] + + def clear_log(self): + """ + Clear the log. + """ + resp = requests.get("%s/api/clear_log"%self.urlbase, verify=False) + return resp.ok + def shutdown(self): + """ + Shut the daemon down, return after the thread has exited. + """ self.thread.server.shutdown() self.thread.join() -- cgit v1.2.3