Remove logging code

This commit is contained in:
Patrick Jentsch 2019-11-06 15:38:00 +01:00
parent b0cf581da9
commit 8f3517d5b6

View File

@ -7,7 +7,6 @@ from . import db
from . import login_manager from . import login_manager
import os import os
import shutil import shutil
import logging
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -226,13 +225,10 @@ class User(UserMixin, db.Model):
Delete user from database. Also delete all associated jobs and corpora Delete user from database. Also delete all associated jobs and corpora
files. files.
""" """
logger = logging.getLogger(__name__)
delete_path = os.path.join('/mnt/opaque/', str(self.id)) delete_path = os.path.join('/mnt/opaque/', str(self.id))
logger.warning('Delete path for user is: {}'.format(delete_path))
while os.path.exists(delete_path): while os.path.exists(delete_path):
try: try:
shutil.rmtree(delete_path, ignore_errors=True) shutil.rmtree(delete_path, ignore_errors=True)
logger.warning('Path does still exist.')
except OSError: except OSError:
pass pass
db.session.delete(self) db.session.delete(self)
@ -383,14 +379,11 @@ class Job(db.Model):
for good. for good.
See: https://docs.docker.com/engine/swarm/swarm-tutorial/delete-service/ See: https://docs.docker.com/engine/swarm/swarm-tutorial/delete-service/
""" """
logger = logging.getLogger(__name__)
delete_path = os.path.join('/mnt/opaque/', str(self.user_id), 'jobs', delete_path = os.path.join('/mnt/opaque/', str(self.user_id), 'jobs',
str(self.id)) str(self.id))
logger.warning('Delete path is: {}'.format(delete_path))
while os.path.exists(delete_path): while os.path.exists(delete_path):
try: try:
shutil.rmtree(delete_path, ignore_errors=True) shutil.rmtree(delete_path, ignore_errors=True)
logger.warning('Path does still exist.')
except OSError: except OSError:
pass pass
db.session.delete(self) db.session.delete(self)
@ -412,15 +405,12 @@ class CorpusFile(db.Model):
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id')) corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
def delete(self): def delete(self):
logger = logging.getLogger(__name__)
logger.warning('Called CorpusFile.delete')
path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
self.dir, self.dir,
self.filename) self.filename)
try: try:
os.remove(path) os.remove(path)
except: except:
logger.warning('[ERROR] CorpusFile.delete')
return return
self.corpus.status = 'unprepared' self.corpus.status = 'unprepared'
db.session.delete(self) db.session.delete(self)
@ -473,24 +463,15 @@ class Corpus(db.Model):
'user_id': self.user_id} 'user_id': self.user_id}
def delete(self): def delete(self):
logger = logging.getLogger(__name__)
logger.warning('Called Corpus.delete')
for corpus_file in self.files: for corpus_file in self.files:
corpus_file.delete() corpus_file.delete()
logger.warning('bis hierhin und nicht weiter')
logger.warning('base_dir: {}'.format(current_app.config['OPAQUE_STORAGE_DIRECTORY']))
logger.warning('user_id: {}'.format(self.user_id))
logger.warning('id: {}'.format(self.id))
path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
str(self.user_id), str(self.user_id),
'corpora', 'corpora',
str(self.id)) str(self.id))
logger.warning(path)
try: try:
logger.warning('Try to remove {}'.format(path))
shutil.rmtree(path) shutil.rmtree(path)
except: except:
logger.warning('[ERROR] Corpus.delete')
return return
db.session.delete(self) db.session.delete(self)
db.session.commit() db.session.commit()