Skip to content
Snippets Groups Projects
Unverified Commit 684a24cf authored by Peter Stanko's avatar Peter Stanko
Browse files

Better logging

parent e9033935
No related branches found
No related tags found
No related merge requests found
Pipeline #
import abc import abc
import logging
from pathlib import Path from pathlib import Path
from storage.entities import Entity, Results, Submission, TestFiles, UploadedEntity from storage.entities import Entity, Results, Submission, TestFiles, UploadedEntity
from storage.utils import copy_and_overwrite, unique_name from storage.utils import copy_and_overwrite, unique_name
log = logging.getLogger(__name__)
class AbstractStoragePart(object): class AbstractStoragePart(object):
def __init__(self, storage: 'Storage'): def __init__(self, storage: 'Storage'):
...@@ -55,10 +58,12 @@ class AbstractStoragePart(object): ...@@ -55,10 +58,12 @@ class AbstractStoragePart(object):
Returns(Entity): Returns(Entity):
""" """
log.info(f"[CREATE] {self._entity_klass.__name__} [{entity_id}]: {kwargs}")
upload = self.create_upload(entity_id, **kwargs) upload = self.create_upload(entity_id, **kwargs)
return upload.process() return upload.process()
def create_upload(self, entity_id, **kwargs): def create_upload(self, entity_id, **kwargs):
log.info(f"[UPLOAD] {self._entity_klass.__name__} [{entity_id}]: {kwargs}")
entity = self.__instance(entity_id=entity_id) entity = self.__instance(entity_id=entity_id)
upload = self.__wrap_entity(entity=entity, **kwargs) upload = self.__wrap_entity(entity=entity, **kwargs)
return upload return upload
...@@ -75,6 +80,7 @@ class AbstractStoragePart(object): ...@@ -75,6 +80,7 @@ class AbstractStoragePart(object):
return self.__instance(entity_id=entity_id) return self.__instance(entity_id=entity_id)
def clone(self, from_id: str, to_id: str) -> Entity: def clone(self, from_id: str, to_id: str) -> Entity:
log.info(f"[CLONE] {self._entity_klass.__name__}: {from_id} -> {to_id}")
from_instance = self.get(from_id) from_instance = self.get(from_id)
to_instance = self.__instance(entity_id=to_id) to_instance = self.__instance(entity_id=to_id)
copy_and_overwrite( copy_and_overwrite(
...@@ -84,6 +90,7 @@ class AbstractStoragePart(object): ...@@ -84,6 +90,7 @@ class AbstractStoragePart(object):
return to_instance return to_instance
def __instance(self, entity_id) -> Entity: def __instance(self, entity_id) -> Entity:
log.debug(f"[GET] {self._entity_klass.__name__}: #{entity_id}")
return self._entity_klass(entity_id=entity_id, base_dir=self.path) return self._entity_klass(entity_id=entity_id, base_dir=self.path)
def __wrap_entity(self, entity, **kwargs) -> UploadedEntity: def __wrap_entity(self, entity, **kwargs) -> UploadedEntity:
...@@ -120,6 +127,7 @@ class TestFilesStorage(AbstractStoragePart): ...@@ -120,6 +127,7 @@ class TestFilesStorage(AbstractStoragePart):
return Path(self.config.get('test_files_dir')) return Path(self.config.get('test_files_dir'))
def update(self, entity_id: str, **kwargs): def update(self, entity_id: str, **kwargs):
log.info(f"[UPDATE] {self._entity_klass.__name__} [{entity_id}]: {kwargs}")
test_files = self.get(entity_id=entity_id) test_files = self.get(entity_id=entity_id)
if test_files: if test_files:
test_files.delete() test_files.delete()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment