def inspect_db(ctx): infos = dict() for table_name, size in count_all(ctx.current_db): infos[table_name] = {"current_db_size": size, "archive_db_size": 0, "diff": size} if database_exists(ctx.archive_db.engine.url): for table_name, size in count_all(ctx.archive_db): infos[table_name]["archive_db_size"] = size diff = infos[table_name]["current_db_size"] - size infos[table_name]["diff"] = diff headers = ["Table", "Current DB size", "Archive DB size", "Diff"] rows = [(k, to_unicode(infos[k]["current_db_size"]), to_unicode(infos[k]["archive_db_size"]), to_unicode(infos[k]["diff"])) for k in iterkeys(infos)] return sorted(rows, key=lambda x: x[0]), headers
def register_error_handlers(app): """Creates a JSON-oriented Flask app. All error responses that you don't specifically manage yourself will have application/json content type, and will contain JSON like this (just an example): { "code": 405, "message": "405: Method Not Allowed" } """ def make_json_error(ex): code = ex.code if isinstance(ex, HTTPException) else 500 message = to_unicode(ex) data = getattr(ex, 'data', None) if data: message = to_unicode(data) response = jsonify(code=code, message=message) response.status_code = code return response for code in iterkeys(default_exceptions): app.errorhandler(code)(make_json_error) return app