A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #! /data/project/copyvios/env/bin/python
  2. # -*- coding: utf-8 -*-
  3. from functools import wraps
  4. from json import dumps
  5. from logging import DEBUG, INFO, getLogger
  6. from logging.handlers import TimedRotatingFileHandler
  7. from time import asctime
  8. from traceback import format_exc
  9. from earwigbot.bot import Bot
  10. from earwigbot.wiki.copyvios import globalize
  11. from flask import Flask, g, make_response, request
  12. from flask.ext.mako import MakoTemplates, render_template, TemplateError
  13. from flup.server.fcgi import WSGIServer
  14. from copyvios.api import format_api_error, handle_api_request
  15. from copyvios.checker import do_check
  16. from copyvios.cookies import parse_cookies
  17. from copyvios.settings import process_settings
  18. from copyvios.sites import update_sites
  19. app = Flask(__name__)
  20. MakoTemplates(app)
  21. app.logger.setLevel(DEBUG)
  22. app.logger.addHandler(TimedRotatingFileHandler(
  23. "logs/app.log", when="midnight", backupCount=7))
  24. app.logger.info(u"Flask server started " + asctime())
  25. getLogger("earwigbot.wiki.cvworker").setLevel(INFO)
  26. def catch_errors(func):
  27. @wraps(func)
  28. def inner(*args, **kwargs):
  29. try:
  30. return func(*args, **kwargs)
  31. except TemplateError as exc:
  32. return render_template("error.mako", traceback=exc.text)
  33. except Exception:
  34. return render_template("error.mako", traceback=format_exc())
  35. return inner
  36. @app.before_first_request
  37. def setup_app():
  38. g.bot = Bot(".earwigbot", 100)
  39. g.langs, g.projects = set(), set()
  40. g.last_sites_update = 0
  41. g.background_data = {}
  42. g.last_background_updates = {}
  43. globalize()
  44. @app.before_request
  45. def prepare_request():
  46. g.db = None
  47. g.cookies = parse_cookies(
  48. request.script_root, request.environ.get("HTTP_COOKIE"))
  49. g.new_cookies = []
  50. @app.after_request
  51. def add_new_cookies(response):
  52. for cookie in g.new_cookies:
  53. response.headers.add("Set-Cookie", cookie)
  54. return response
  55. @app.after_request
  56. def write_access_log(response):
  57. msg = u"%s %s %s %s -> %s"
  58. app.logger.debug(msg, asctime(), request.method, request.path,
  59. request.values.to_dict(), response.status_code)
  60. return response
  61. @app.teardown_appcontext
  62. def close_databases(error):
  63. if g.db:
  64. g.db.close()
  65. @app.route("/")
  66. @catch_errors
  67. def index():
  68. query = do_check()
  69. update_sites()
  70. return render_template("index.mako", query=query, result=query.result)
  71. @app.route("/settings", methods=["GET", "POST"])
  72. @catch_errors
  73. def settings():
  74. status = process_settings() if request.method == "POST" else None
  75. update_sites()
  76. default = g.bot.wiki.get_site()
  77. kwargs = {"status": status, "default_lang": default.lang,
  78. "default_project": default.project}
  79. return render_template("settings.mako", **kwargs)
  80. @app.route("/api")
  81. @catch_errors
  82. def api():
  83. return render_template("api.mako", help=True)
  84. @app.route("/api.json")
  85. @catch_errors
  86. def api_json():
  87. if not request.args:
  88. return render_template("api.mako", help=True)
  89. format = request.args.get("format", "json")
  90. if format in ["json", "jsonfm"]:
  91. try:
  92. result = handle_api_request()
  93. except Exception as exc:
  94. result = format_api_error("unhandled_exception", exc)
  95. else:
  96. errmsg = u"Unknown format: '{0}'".format(format)
  97. result = format_api_error("unknown_format", errmsg)
  98. if format == "jsonfm":
  99. return render_template("api.mako", help=False, result=result)
  100. resp = make_response(dumps(result))
  101. resp.mimetype = "application/json"
  102. return resp
  103. if __name__ == '__main__':
  104. WSGIServer(app).run()