diff --git a/app.fcgi b/app.fcgi index a80f455..f7703a1 100755 --- a/app.fcgi +++ b/app.fcgi @@ -5,12 +5,16 @@ from functools import wraps from logging import DEBUG from logging.handlers import TimedRotatingFileHandler from time import asctime +from traceback import format_exc from flask import Flask, g, request from flask.ext.mako import MakoTemplates, render_template, TemplateError from flup.server.fcgi import WSGIServer from copyvios.cookies import parse_cookies +from copyvios.misc import get_bot +from copyvios.settings import process_settings +from copyvios.sites import get_sites app = Flask(__name__) MakoTemplates(app) @@ -20,13 +24,15 @@ app.logger.addHandler(TimedRotatingFileHandler( "logs/app.log", when="D", interval=1, backupCount=7)) app.logger.info(u"Flask server started " + asctime()) -def debug_exceptions(func): +def catch_errors(func): @wraps(func) def inner(*args, **kwargs): try: return func(*args, **kwargs) except TemplateError as exc: - return "
" + exc.text + "" + return render_template("error.mako", traceback=exc.text) + except Exception: + return render_template("error.mako", traceback=format_exc()) return inner @app.before_request @@ -50,17 +56,23 @@ def write_access_log(response): return response @app.route("/") -@debug_exceptions +@catch_errors def index(): return render_template("index.mako") @app.route("/settings", methods=["GET", "POST"]) -@debug_exceptions +@catch_errors def settings(): - return render_template("settings.mako") + status = process_settings() if request.method == "POST" else None + bot = get_bot() + langs, projects = get_sites(bot) + default = bot.wiki.get_site() + kwargs = {"status": status, "langs": langs, "projects": projects, + "default_lang": default.lang, "default_project": default.project} + return render_template("settings.mako", **kwargs) @app.route("/debug") -@debug_exceptions +@catch_errors def debug(): return render_template("debug.mako") diff --git a/copyvios/settings.py b/copyvios/settings.py index 4009cdd..0ab3b4c 100644 --- a/copyvios/settings.py +++ b/copyvios/settings.py @@ -4,10 +4,9 @@ from flask import g from markupsafe import escape from .cookies import set_cookie, delete_cookie -from .misc import get_bot, Query -from .sites import get_sites +from .misc import Query -def main(): +def process_settings(): query = Query(method="POST") if query.action == "set": status = _do_set(query) @@ -15,10 +14,7 @@ def main(): status = _do_delete(query) else: status = None - - bot = get_bot() - langs, projects = get_sites(bot) - return bot, status, langs, projects + return status def _do_set(query): cookies = g.cookies diff --git a/templates/debug.mako b/templates/debug.mako index 5c43e61..7332663 100644 --- a/templates/debug.mako +++ b/templates/debug.mako @@ -1,10 +1,10 @@ <%include file="/support/header.mako" args="title='Debug - Earwig\'s Copyvio Detector'"/> <%! from flask import request %>\ -
An error occured! If it hasn't been reported (try to check), please file an issue or email me. Include the following information:
+{{traceback | h}}+
The given site (project=${query.project | h}, language=${lang | h}) doesn't seem to exist. It may also be closed or private. Confirm its URL.
-The given page doesn't seem to exist: ${page.title | h}.
-The given revision ID doesn't seem to exist: ${oldid | h}.
-Unsupported URI scheme: ${url | h}.
-This tool attempts to detect copyright violations in articles. Simply give the title of the page or ID of the revision you want to check and hit Submit. The tool will search for similar content elsewhere on the web and display a report if a match is found. If you also provide a URL, it will not query any search engines and instead display a report comparing the article to that particular webpage, like the Duplication Detector. Check out the FAQ for more information and technical details.
-Note: The tool is still in beta. You are completely welcome to use it and provide feedback, but be aware that it may produce strange or broken results.
- - % if result: - <% show_details = "CopyviosShowDetails" in cookies and cookies["CopyviosShowDetails"].value == "True" %> - -The given site (project=${query.project | h}, language=${lang | h}) doesn't seem to exist. It may also be closed or private. Confirm its URL.
+The given page doesn't seem to exist: ${page.title | h}.
+The given revision ID doesn't seem to exist: ${oldid | h}.
+Unsupported URI scheme: ${url | h}.
+This tool attempts to detect copyright violations in articles. Simply give the title of the page or ID of the revision you want to check and hit Submit. The tool will search for similar content elsewhere on the web and display a report if a match is found. If you also provide a URL, it will not query any search engines and instead display a report comparing the article to that particular webpage, like the Duplication Detector. Check out the FAQ for more information and technical details.
+Note: The tool is still in beta. You are completely welcome to use it and provide feedback, but be aware that it may produce strange or broken results.
+Article: ${highlight_delta(result.article_chain, result.delta_chain)} |
+ Source: ${highlight_delta(result.source_chain, result.delta_chain)} |
+
${status}
-This page contains some configurable options for the copyvio detector. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.
- +${key | h} | + % try: + <% lines = dumps(loads(cookie.value), indent=4).splitlines() %>\ +
+ % for line in lines:
+ ${line | h}
+ % endfor
+ |
+ % except ValueError:
+ ${cookie.value | h} | + % endtry +
+ |
+
+ |
+
No cookies!
+% endif <%include file="/support/footer.mako"/>