A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.fcgi 2.3 KiB

10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /data/project/copyvios/env/bin/python
  2. # -*- coding: utf-8 -*-
  3. from functools import wraps
  4. from logging import DEBUG
  5. from logging.handlers import TimedRotatingFileHandler
  6. from time import asctime
  7. from traceback import format_exc
  8. from flask import Flask, g, request
  9. from flask.ext.mako import MakoTemplates, render_template, TemplateError
  10. from flup.server.fcgi import WSGIServer
  11. from copyvios.checker import do_check
  12. from copyvios.cookies import parse_cookies
  13. from copyvios.misc import get_bot
  14. from copyvios.settings import process_settings
  15. from copyvios.sites import get_sites
  16. app = Flask(__name__)
  17. MakoTemplates(app)
  18. app.logger.setLevel(DEBUG)
  19. app.logger.addHandler(TimedRotatingFileHandler(
  20. "logs/app.log", when="D", interval=1, backupCount=7))
  21. app.logger.info(u"Flask server started " + asctime())
  22. def catch_errors(func):
  23. @wraps(func)
  24. def inner(*args, **kwargs):
  25. try:
  26. return func(*args, **kwargs)
  27. except TemplateError as exc:
  28. return render_template("error.mako", traceback=exc.text)
  29. except Exception:
  30. return render_template("error.mako", traceback=format_exc())
  31. return inner
  32. @app.before_request
  33. def prepare_cookies():
  34. cookie_string = request.environ.get("HTTP_COOKIE")
  35. g.cookies = parse_cookies(request.script_root, cookie_string)
  36. g.new_cookies = []
  37. @app.after_request
  38. def add_new_cookies(response):
  39. for cookie in g.new_cookies:
  40. response.headers.add("Set-Cookie", cookie)
  41. return response
  42. @app.after_request
  43. def write_access_log(response):
  44. msg = u"%s %s -> %s"
  45. app.logger.debug(msg, asctime(), request.path, response.status_code)
  46. return response
  47. @app.route("/")
  48. @catch_errors
  49. def index():
  50. query = do_check()
  51. return render_template("index.mako", query=query, result=query.result)
  52. @app.route("/settings", methods=["GET", "POST"])
  53. @catch_errors
  54. def settings():
  55. status = process_settings() if request.method == "POST" else None
  56. bot = get_bot()
  57. langs, projects = get_sites(bot)
  58. default = bot.wiki.get_site()
  59. kwargs = {"status": status, "langs": langs, "projects": projects,
  60. "default_lang": default.lang, "default_project": default.project}
  61. return render_template("settings.mako", **kwargs)
  62. if __name__ == '__main__':
  63. WSGIServer(app).run()