当代数据库管理系统课程实验二
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

51 rader
1.4 KiB

  1. import logging
  2. import os
  3. from flask import Flask
  4. from flask import Blueprint
  5. from flask import request
  6. from be.view import testconn
  7. from be.view import auth
  8. from be.view import seller
  9. from be.view import buyer
  10. from be.model.creatTB import createTable
  11. from be.model.buyer import tostop
  12. bp_shutdown = Blueprint("shutdown", __name__)
  13. def shutdown_server():
  14. func = request.environ.get("werkzeug.server.shutdown")
  15. if func is None:
  16. raise RuntimeError("Not running with the Werkzeug Server")
  17. func()
  18. @bp_shutdown.route("/shutdown", methods=["POST","GET"])
  19. def be_shutdown():
  20. # tostop() ## 不需要测试自动取消时删去此部分
  21. shutdown_server()
  22. return "Server shutting down..."
  23. def be_run():
  24. this_path = os.path.dirname(__file__)
  25. parent_path = os.path.dirname(this_path)
  26. log_file = os.path.join(parent_path, "app.log")
  27. createTable()
  28. logging.basicConfig(filename=log_file, level=logging.ERROR)
  29. handler = logging.StreamHandler()
  30. formatter = logging.Formatter(
  31. "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s"
  32. )
  33. handler.setFormatter(formatter)
  34. logging.getLogger().addHandler(handler)
  35. app = Flask(__name__)
  36. app.register_blueprint(bp_shutdown)
  37. app.register_blueprint(testconn.bp_testconn)
  38. app.register_blueprint(auth.bp_auth)
  39. app.register_blueprint(seller.bp_seller)
  40. app.register_blueprint(buyer.bp_buyer)
  41. app.run()