forked from ScoDoc/DocScoDoc
Exception speciale pour envoyer bug report
This commit is contained in:
parent
9a13470ff3
commit
9032b1fa67
@ -10,6 +10,7 @@ import traceback
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import SMTPHandler, WatchedFileHandler
|
from logging.handlers import SMTPHandler, WatchedFileHandler
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from flask import current_app, g, request
|
from flask import current_app, g, request
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
@ -27,6 +28,7 @@ import sqlalchemy
|
|||||||
|
|
||||||
from app.scodoc.sco_exceptions import (
|
from app.scodoc.sco_exceptions import (
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
|
ScoBugCatcher,
|
||||||
ScoGenError,
|
ScoGenError,
|
||||||
ScoValueError,
|
ScoValueError,
|
||||||
APIInvalidParams,
|
APIInvalidParams,
|
||||||
@ -77,6 +79,28 @@ def internal_server_error(exc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_sco_bug(exc):
|
||||||
|
"""Un bug, en général rare, sur lequel les dev cherchent des
|
||||||
|
informations pour le corriger.
|
||||||
|
"""
|
||||||
|
Thread(
|
||||||
|
target=_async_dump, args=(current_app._get_current_object(), request.url)
|
||||||
|
).start()
|
||||||
|
|
||||||
|
return internal_server_error(exc)
|
||||||
|
|
||||||
|
|
||||||
|
def _async_dump(app, request_url: str):
|
||||||
|
from app.scodoc.sco_dump_db import sco_dump_and_send_db
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
ndb.open_db_connection()
|
||||||
|
try:
|
||||||
|
sco_dump_and_send_db("ScoBugCatcher", request_url=request_url)
|
||||||
|
except ScoValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def handle_invalid_usage(error):
|
def handle_invalid_usage(error):
|
||||||
response = jsonify(error.to_dict())
|
response = jsonify(error.to_dict())
|
||||||
response.status_code = error.status_code
|
response.status_code = error.status_code
|
||||||
@ -196,7 +220,7 @@ def create_app(config_class=DevConfig):
|
|||||||
|
|
||||||
app.register_error_handler(ScoGenError, handle_sco_value_error)
|
app.register_error_handler(ScoGenError, handle_sco_value_error)
|
||||||
app.register_error_handler(ScoValueError, handle_sco_value_error)
|
app.register_error_handler(ScoValueError, handle_sco_value_error)
|
||||||
|
app.register_error_handler(ScoBugCatcher, handle_sco_bug)
|
||||||
app.register_error_handler(AccessDenied, handle_access_denied)
|
app.register_error_handler(AccessDenied, handle_access_denied)
|
||||||
app.register_error_handler(500, internal_server_error)
|
app.register_error_handler(500, internal_server_error)
|
||||||
app.register_error_handler(503, postgresql_server_error)
|
app.register_error_handler(503, postgresql_server_error)
|
||||||
|
@ -49,6 +49,7 @@ Balises img: actuellement interdites.
|
|||||||
from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table
|
from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table
|
||||||
from reportlab.lib.units import cm, mm
|
from reportlab.lib.units import cm, mm
|
||||||
from reportlab.lib.colors import Color, blue
|
from reportlab.lib.colors import Color, blue
|
||||||
|
from app.scodoc.sco_exceptions import ScoBugCatcher
|
||||||
|
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app.scodoc.sco_pdf import SU
|
from app.scodoc.sco_pdf import SU
|
||||||
@ -416,7 +417,11 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator):
|
|||||||
# Chaque UE:
|
# Chaque UE:
|
||||||
for ue in I["ues"]:
|
for ue in I["ues"]:
|
||||||
ue_type = None
|
ue_type = None
|
||||||
|
try:
|
||||||
coef_ue = ue["coef_ue_txt"] if prefs["bul_show_ue_coef"] else ""
|
coef_ue = ue["coef_ue_txt"] if prefs["bul_show_ue_coef"] else ""
|
||||||
|
except TypeError as exc:
|
||||||
|
raise ScoBugCatcher(f"ue={ue!r}") from exc
|
||||||
|
|
||||||
ue_descr = ue["ue_descr_txt"]
|
ue_descr = ue["ue_descr_txt"]
|
||||||
rowstyle = ""
|
rowstyle = ""
|
||||||
plusminus = minuslink #
|
plusminus = minuslink #
|
||||||
|
@ -51,14 +51,12 @@ import fcntl
|
|||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from flask import flash, request
|
from flask import g, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
|
||||||
import app.scodoc.notesdb as ndb
|
import app.scodoc.notesdb as ndb
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app import log
|
from app import log
|
||||||
from app.scodoc import html_sco_header
|
|
||||||
from app.scodoc import sco_preferences
|
|
||||||
from app.scodoc import sco_users
|
from app.scodoc import sco_users
|
||||||
import sco_version
|
import sco_version
|
||||||
from app.scodoc.sco_exceptions import ScoValueError
|
from app.scodoc.sco_exceptions import ScoValueError
|
||||||
@ -68,8 +66,7 @@ SCO_DUMP_LOCK = "/tmp/scodump.lock"
|
|||||||
|
|
||||||
def sco_dump_and_send_db(message: str = "", request_url: str = ""):
|
def sco_dump_and_send_db(message: str = "", request_url: str = ""):
|
||||||
"""Dump base de données et l'envoie anonymisée pour debug"""
|
"""Dump base de données et l'envoie anonymisée pour debug"""
|
||||||
H = [html_sco_header.sco_header(page_title="Assistance technique")]
|
# get current (dept) DB name:
|
||||||
# get currect (dept) DB name:
|
|
||||||
cursor = ndb.SimpleQuery("SELECT current_database()", {})
|
cursor = ndb.SimpleQuery("SELECT current_database()", {})
|
||||||
db_name = cursor.fetchone()[0]
|
db_name = cursor.fetchone()[0]
|
||||||
ano_db_name = "ANO" + db_name
|
ano_db_name = "ANO" + db_name
|
||||||
@ -96,27 +93,7 @@ def sco_dump_and_send_db(message: str = "", request_url: str = ""):
|
|||||||
|
|
||||||
# Send
|
# Send
|
||||||
r = _send_db(ano_db_name, message, request_url)
|
r = _send_db(ano_db_name, message, request_url)
|
||||||
if (
|
code = r.status_code
|
||||||
r.status_code
|
|
||||||
== requests.codes.INSUFFICIENT_STORAGE # pylint: disable=no-member
|
|
||||||
):
|
|
||||||
H.append(
|
|
||||||
"""<p class="warning">
|
|
||||||
Erreur: espace serveur trop plein.
|
|
||||||
Merci de contacter <a href="mailto:{0}">{0}</a></p>""".format(
|
|
||||||
scu.SCO_DEV_MAIL
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif r.status_code == requests.codes.OK: # pylint: disable=no-member
|
|
||||||
H.append("""<p>Opération effectuée.</p>""")
|
|
||||||
else:
|
|
||||||
H.append(
|
|
||||||
"""<p class="warning">
|
|
||||||
Erreur: code <tt>{0} {1}</tt>
|
|
||||||
Merci de contacter <a href="mailto:{2}">{2}</a></p>""".format(
|
|
||||||
r.status_code, r.reason, scu.SCO_DEV_MAIL
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Drop anonymized database
|
# Drop anonymized database
|
||||||
@ -125,8 +102,8 @@ def sco_dump_and_send_db(message: str = "", request_url: str = ""):
|
|||||||
fcntl.flock(x, fcntl.LOCK_UN)
|
fcntl.flock(x, fcntl.LOCK_UN)
|
||||||
|
|
||||||
log("sco_dump_and_send_db: done.")
|
log("sco_dump_and_send_db: done.")
|
||||||
flash("Données envoyées au serveur d'assistance")
|
|
||||||
return "\n".join(H) + html_sco_header.sco_footer()
|
return code
|
||||||
|
|
||||||
|
|
||||||
def _duplicate_db(db_name, ano_db_name):
|
def _duplicate_db(db_name, ano_db_name):
|
||||||
@ -195,7 +172,7 @@ def _send_db(ano_db_name: str, message: str = "", request_url: str = ""):
|
|||||||
scu.SCO_DUMP_UP_URL,
|
scu.SCO_DUMP_UP_URL,
|
||||||
files=files,
|
files=files,
|
||||||
data={
|
data={
|
||||||
"dept_name": sco_preferences.get_preference("DeptName"),
|
"dept_name": getattr(g, "scodoc_dept", "-"),
|
||||||
"message": message or "",
|
"message": message or "",
|
||||||
"request_url": request_url or request.url,
|
"request_url": request_url or request.url,
|
||||||
"serial": _get_scodoc_serial(),
|
"serial": _get_scodoc_serial(),
|
||||||
|
@ -47,9 +47,12 @@ class ScoValueError(ScoException):
|
|||||||
self.dest_url = dest_url
|
self.dest_url = dest_url
|
||||||
|
|
||||||
|
|
||||||
|
class ScoBugCatcher(ScoException):
|
||||||
|
"bug avec enquete en cours"
|
||||||
|
|
||||||
|
|
||||||
class NoteProcessError(ScoValueError):
|
class NoteProcessError(ScoValueError):
|
||||||
"Valeurs notes invalides"
|
"Valeurs notes invalides"
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidEtudId(NoteProcessError):
|
class InvalidEtudId(NoteProcessError):
|
||||||
|
@ -73,6 +73,7 @@ from app.scodoc.scolog import logdb
|
|||||||
|
|
||||||
from app.scodoc.sco_exceptions import (
|
from app.scodoc.sco_exceptions import (
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
|
ScoBugCatcher,
|
||||||
ScoException,
|
ScoException,
|
||||||
ScoValueError,
|
ScoValueError,
|
||||||
ScoInvalidIdType,
|
ScoInvalidIdType,
|
||||||
|
@ -30,7 +30,7 @@ issu de ScoDoc7 / ZScolar.py
|
|||||||
|
|
||||||
Emmanuel Viennet, 2021
|
Emmanuel Viennet, 2021
|
||||||
"""
|
"""
|
||||||
import os
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
@ -2198,4 +2198,24 @@ def stat_bac(formsemestre_id):
|
|||||||
@scodoc7func
|
@scodoc7func
|
||||||
def sco_dump_and_send_db(message="", request_url=""):
|
def sco_dump_and_send_db(message="", request_url=""):
|
||||||
"Send anonymized data to supervision"
|
"Send anonymized data to supervision"
|
||||||
return sco_dump_db.sco_dump_and_send_db(message, request_url)
|
|
||||||
|
status_code = sco_dump_db.sco_dump_and_send_db(message, request_url)
|
||||||
|
H = [html_sco_header.sco_header(page_title="Assistance technique")]
|
||||||
|
if status_code == requests.codes.INSUFFICIENT_STORAGE: # pylint: disable=no-member
|
||||||
|
H.append(
|
||||||
|
"""<p class="warning">
|
||||||
|
Erreur: espace serveur trop plein.
|
||||||
|
Merci de contacter <a href="mailto:{0}">{0}</a></p>""".format(
|
||||||
|
scu.SCO_DEV_MAIL
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif status_code == requests.codes.OK: # pylint: disable=no-member
|
||||||
|
H.append("""<p>Opération effectuée.</p>""")
|
||||||
|
else:
|
||||||
|
H.append(
|
||||||
|
f"""<p class="warning">
|
||||||
|
Erreur: code <tt>{status_code}</tt>
|
||||||
|
Merci de contacter <a href="mailto:{scu.SCO_DEV_MAIL}">{scu.SCO_DEV_MAIL}</a></p>"""
|
||||||
|
)
|
||||||
|
flash("Données envoyées au serveur d'assistance")
|
||||||
|
return "\n".join(H) + html_sco_header.sco_footer()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- mode: python -*-
|
# -*- mode: python -*-
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
SCOVERSION = "9.1.82"
|
SCOVERSION = "9.1.83"
|
||||||
|
|
||||||
SCONAME = "ScoDoc"
|
SCONAME = "ScoDoc"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user