mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Don't use module level logger functions
This commit is contained in:
parent
2af74db46f
commit
5469bd0ec1
@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from flask import abort, flash, redirect, render_template, request, url_for
|
||||
from flask import (abort, current_app, flash, redirect, render_template,
|
||||
request, url_for)
|
||||
from flask_login import current_user, login_user, login_required, logout_user
|
||||
from sqlalchemy import or_
|
||||
from . import bp
|
||||
@ -8,7 +9,6 @@ from .forms import (LoginForm, ResetPasswordForm, ResetPasswordRequestForm,
|
||||
from .. import db
|
||||
from ..email import create_message, send
|
||||
from ..models import User
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
@ -68,7 +68,9 @@ def register():
|
||||
try:
|
||||
os.makedirs(user.path)
|
||||
except OSError:
|
||||
logging.error('Make dir {} led to an OSError!'.format(user.path))
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(user.path)
|
||||
)
|
||||
db.session.delete(user)
|
||||
db.session.commit()
|
||||
abort(500)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from flask import (abort, flash, make_response, redirect, request,
|
||||
from flask import (abort, current_app, flash, make_response, redirect, request,
|
||||
render_template, url_for, send_from_directory)
|
||||
from flask_login import current_user, login_required
|
||||
from . import bp
|
||||
@ -11,7 +11,6 @@ from jsonschema import validate
|
||||
from .. import db
|
||||
from ..models import Corpus, CorpusFile, QueryResult
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import glob
|
||||
@ -34,7 +33,9 @@ def add_corpus():
|
||||
try:
|
||||
os.makedirs(corpus.path)
|
||||
except OSError:
|
||||
logging.error('Make dir {} led to an OSError!'.format(corpus.path))
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(corpus.path)
|
||||
)
|
||||
db.session.rollback()
|
||||
abort(500)
|
||||
else:
|
||||
@ -61,7 +62,9 @@ def import_corpus():
|
||||
try:
|
||||
os.makedirs(corpus.path)
|
||||
except OSError:
|
||||
logging.error('Make dir {} led to an OSError!'.format(corpus.path))
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(corpus.path)
|
||||
)
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response(
|
||||
@ -318,7 +321,9 @@ def add_query_result():
|
||||
try:
|
||||
os.makedirs(os.path.dirname(query_result.path))
|
||||
except OSError:
|
||||
logging.error('Make dir {} led to an OSError!'.format(query_result.path)) # noqa
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(query_result.path)
|
||||
)
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response(
|
||||
|
@ -7,7 +7,6 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
||||
import xml.etree.ElementTree as ET
|
||||
from . import db, login
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@ -530,7 +529,9 @@ class CorpusFile(db.Model):
|
||||
try:
|
||||
os.remove(self.path)
|
||||
except OSError:
|
||||
logging.error('Removing {} led to an OSError!'.format(self.path))
|
||||
current_app.logger.error(
|
||||
'Removing {} led to an OSError!'.format(self.path)
|
||||
)
|
||||
pass
|
||||
db.session.delete(self)
|
||||
self.corpus.status = 'unprepared'
|
||||
|
@ -1,5 +1,5 @@
|
||||
from flask import (abort, flash, make_response, render_template, request,
|
||||
url_for)
|
||||
from flask import (abort, current_app, flash, make_response, render_template,
|
||||
request, url_for)
|
||||
from flask_login import current_user, login_required
|
||||
from werkzeug.utils import secure_filename
|
||||
from . import bp
|
||||
@ -8,7 +8,6 @@ from .. import db
|
||||
from .forms import AddJobForms
|
||||
from ..models import Job, JobInput
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
@ -56,7 +55,9 @@ def service(service):
|
||||
try:
|
||||
os.makedirs(job.path)
|
||||
except OSError:
|
||||
logging.error('Make dir {} led to an OSError!'.format(job.path))
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(job.path)
|
||||
)
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response(
|
||||
|
@ -1,7 +1,6 @@
|
||||
from flask import current_app
|
||||
from ..models import Corpus
|
||||
import docker
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@ -78,7 +77,7 @@ class CheckCorporaMixin:
|
||||
restart_policy=restart_policy
|
||||
)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Create "{}" service raised '.format(name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -91,20 +90,20 @@ class CheckCorporaMixin:
|
||||
try:
|
||||
service = self.docker.services.get(service_name)
|
||||
except docker.errors.NotFound:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.NotFound" The service does not exist. '
|
||||
+ '(corpus.status: {} -> failed)'.format(corpus.status)
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
@ -121,7 +120,7 @@ class CheckCorporaMixin:
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -162,7 +161,7 @@ class CheckCorporaMixin:
|
||||
except docker.errors.NotFound:
|
||||
pass
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" container raised '.format(name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -172,7 +171,7 @@ class CheckCorporaMixin:
|
||||
try:
|
||||
container.remove(force=True)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Remove "{}" container raised '.format(name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -184,21 +183,21 @@ class CheckCorporaMixin:
|
||||
network=network)
|
||||
except docker.errors.ContainerError:
|
||||
# This case should not occur, because detach is True.
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Run "{}" container raised '.format(name)
|
||||
+ '"docker.errors.ContainerError" The container exits with a '
|
||||
+ 'non-zero exit code and detach is False.'
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.ImageNotFound:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Run "{}" container raised '.format(name)
|
||||
+ '"docker.errors.ImageNotFound" The specified image does not '
|
||||
+ 'exist.'
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Run "{}" container raised '.format(name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -211,10 +210,12 @@ class CheckCorporaMixin:
|
||||
try:
|
||||
self.docker.containers.get(container_name)
|
||||
except docker.errors.NotFound:
|
||||
logging.error('Could not find "{}" but the corpus state is "analysing".') # noqa
|
||||
current_app.logger.error(
|
||||
'Could not find "{}" but the corpus state is "analysing".'
|
||||
)
|
||||
corpus.status = 'prepared'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" container raised '.format(container_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -228,7 +229,7 @@ class CheckCorporaMixin:
|
||||
except docker.errors.NotFound:
|
||||
pass
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" container raised '.format(container_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -238,7 +239,7 @@ class CheckCorporaMixin:
|
||||
try:
|
||||
container.remove(force=True)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Remove "{}" container raised '.format(container_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
|
@ -5,7 +5,6 @@ from .. import db
|
||||
from ..models import Job, JobResult
|
||||
import docker
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@ -96,7 +95,7 @@ class CheckJobsMixin:
|
||||
restart_policy=restart_policy
|
||||
)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Create "{}" service raised '.format(name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -110,21 +109,21 @@ class CheckJobsMixin:
|
||||
try:
|
||||
service = self.docker.services.get(service_name)
|
||||
except docker.errors.NotFound:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.NotFound" The service does not exist. '
|
||||
+ '(job.status: {} -> failed)'.format(job.status)
|
||||
)
|
||||
job.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
@ -141,7 +140,7 @@ class CheckJobsMixin:
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -167,14 +166,14 @@ class CheckJobsMixin:
|
||||
except docker.errors.NotFound:
|
||||
job.status = 'canceled'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
@ -184,7 +183,7 @@ class CheckJobsMixin:
|
||||
try:
|
||||
service.update(mounts=None)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Update "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
@ -193,7 +192,7 @@ class CheckJobsMixin:
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error(
|
||||
current_app.logger.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
|
Loading…
Reference in New Issue
Block a user