Skip to content

Commit

Permalink
Update init values for Converter and Transformer (#2344)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikek authored Dec 17, 2024
1 parent bf88d01 commit 5992cae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ESSArch_Core/WorkflowEngine/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver

from ESSArch_Core.db.utils import check_db_connection
from ESSArch_Core.WorkflowEngine.models import ProcessStep, ProcessTask


Expand Down Expand Up @@ -31,6 +32,7 @@ def step_post_save(sender, instance, created, **kwargs):

@task_received.connect
def task_received_handler(request=None, **kwargs):
check_db_connection()
logger = logging.getLogger('essarch')
try:
t = ProcessTask.objects.get(celery_id=request.task_id)
Expand All @@ -39,7 +41,6 @@ def task_received_handler(request=None, **kwargs):
t.revoke()
except ProcessTask.DoesNotExist:
logger.debug('{} signal task_received without ProcessTask'.format(request.task_id))
pass


@task_revoked.connect
Expand Down
18 changes: 16 additions & 2 deletions ESSArch_Core/fixity/conversion/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@
class BaseConverter:
input_formats = []
output_formats = []
file_converter = True # Does the validator operate on single files or entire directories?

def __init__(self, ip=None, user=None):
def __init__(self, context=None, include=None, exclude=None, options=None,
data=None, required=True, task=None, ip=None, responsible=None,
stylesheet=None):
"""
Initializes for convert of one or more files
"""
self.context = context
self.include = include or []
self.exclude = exclude or []
self.options = options or {}
self.data = data or {}
self.required = required
self.task = task
self.ip = ip
self.user = user
self.responsible = responsible
self.stylesheet = stylesheet

@classmethod
def validate_input_format(cls, fmt):
Expand Down
3 changes: 3 additions & 0 deletions ESSArch_Core/fixity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def _run_python(self, filepath, rootdir, options, t=None, ip=None, context=None)
os.chdir(rootdir)
filepath = normalize_path(filepath)
cmd = eval(self.prepare_cmd(filepath, options))
if isinstance(cmd, str):
cmd = (cmd,)

try:
[module, task] = self.path.rsplit('.', 1)
p = getattr(importlib.import_module(module), task)(task=t, ip=ip, context=context)
Expand Down
19 changes: 17 additions & 2 deletions ESSArch_Core/fixity/transformation/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@


class BaseTransformer:
def __init__(self, ip=None, user=None):
file_transformer = True # Does the validator operate on single files or entire directories?

def __init__(self, context=None, include=None, exclude=None, options=None,
data=None, required=True, task=None, ip=None, responsible=None,
stylesheet=None):
"""
Initializes for transform of one or more files
"""
self.context = context
self.include = include or []
self.exclude = exclude or []
self.options = options or {}
self.data = data or {}
self.required = required
self.task = task
self.ip = ip
self.user = user
self.responsible = responsible
self.stylesheet = stylesheet

@classmethod
def transform(cls, path):
Expand Down

0 comments on commit 5992cae

Please sign in to comment.