A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

app.fcgi 2.4 KiB

há 10 anos
há 10 anos
há 10 anos
há 10 anos
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.cookies import parse_cookies
  12. from copyvios.misc import get_bot
  13. from copyvios.settings import process_settings
  14. from copyvios.sites import get_sites
  15. app = Flask(__name__)
  16. MakoTemplates(app)
  17. app.logger.setLevel(DEBUG)
  18. app.logger.addHandler(TimedRotatingFileHandler(
  19. "logs/app.log", when="D", interval=1, backupCount=7))
  20. app.logger.info(u"Flask server started " + asctime())
  21. def catch_errors(func):
  22. @wraps(func)
  23. def inner(*args, **kwargs):
  24. try:
  25. return func(*args, **kwargs)
  26. except TemplateError as exc:
  27. return render_template("error.mako", traceback=exc.text)
  28. except Exception:
  29. return render_template("error.mako", traceback=format_exc())
  30. return inner
  31. @app.before_request
  32. def prepare_cookies():
  33. cookie_string = request.environ.get("HTTP_COOKIE")
  34. g.cookies = parse_cookies(request.script_root, cookie_string)
  35. g.new_cookies = []
  36. @app.after_request
  37. def add_new_cookies(response):
  38. if g.new_cookies:
  39. if "Set-Cookie" in response.headers:
  40. g.new_cookies.insert(0, response.headers["Set-Cookie"])
  41. response.headers["Set-Cookie"] = "; ".join(g.new_cookies)
  42. return response
  43. @app.after_request
  44. def write_access_log(response):
  45. msg = u"%s %s -> %s"
  46. app.logger.debug(msg, asctime(), request.path, response.status_code)
  47. return response
  48. @app.route("/")
  49. @catch_errors
  50. def index():
  51. return render_template("index.mako")
  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. @app.route("/debug")
  63. @catch_errors
  64. def debug():
  65. return render_template("debug.mako")
  66. if __name__ == '__main__':
  67. WSGIServer(app).run()