64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
|
|
"""
|
|
This file contains definitions for the LocalBashConductor, in order to
|
|
execute Bash jobs on the local resource.
|
|
|
|
Author(s): David Marchant
|
|
"""
|
|
|
|
import os
|
|
|
|
from typing import Any, Dict, Tuple
|
|
|
|
from meow_base.core.base_conductor import BaseConductor
|
|
from meow_base.core.meow import valid_job
|
|
from meow_base.core.vars import DEFAULT_JOB_QUEUE_DIR, \
|
|
DEFAULT_JOB_OUTPUT_DIR, JOB_TYPE, JOB_TYPE_BASH, JOB_TYPE, \
|
|
DEFAULT_JOB_QUEUE_DIR, DEFAULT_JOB_OUTPUT_DIR
|
|
from meow_base.functionality.validation import valid_dir_path
|
|
from meow_base.functionality.file_io import make_dir
|
|
|
|
|
|
class LocalBashConductor(BaseConductor):
|
|
def __init__(self, job_queue_dir:str=DEFAULT_JOB_QUEUE_DIR,
|
|
job_output_dir:str=DEFAULT_JOB_OUTPUT_DIR, name:str="",
|
|
pause_time:int=5)->None:
|
|
"""LocalBashConductor Constructor. This should be used to execute
|
|
Bash jobs, and will then pass any internal job runner files to the
|
|
output directory. Note that if this handler is given to a MeowRunner
|
|
object, the job_queue_dir and job_output_dir will be overwridden."""
|
|
super().__init__(name=name, pause_time=pause_time)
|
|
self._is_valid_job_queue_dir(job_queue_dir)
|
|
self.job_queue_dir = job_queue_dir
|
|
self._is_valid_job_output_dir(job_output_dir)
|
|
self.job_output_dir = job_output_dir
|
|
|
|
def valid_execute_criteria(self, job:Dict[str,Any])->Tuple[bool,str]:
|
|
"""Function to determine given an job defintion, if this conductor can
|
|
process it or not. This conductor will accept any Bash job type"""
|
|
try:
|
|
valid_job(job)
|
|
msg = ""
|
|
if job[JOB_TYPE] not in [JOB_TYPE_BASH]:
|
|
msg = f"Job type was not {JOB_TYPE_BASH}."
|
|
if msg:
|
|
return False, msg
|
|
else:
|
|
return True, ""
|
|
except Exception as e:
|
|
return False, str(e)
|
|
|
|
def _is_valid_job_queue_dir(self, job_queue_dir)->None:
|
|
"""Validation check for 'job_queue_dir' variable from main
|
|
constructor."""
|
|
valid_dir_path(job_queue_dir, must_exist=False)
|
|
if not os.path.exists(job_queue_dir):
|
|
make_dir(job_queue_dir)
|
|
|
|
def _is_valid_job_output_dir(self, job_output_dir)->None:
|
|
"""Validation check for 'job_output_dir' variable from main
|
|
constructor."""
|
|
valid_dir_path(job_output_dir, must_exist=False)
|
|
if not os.path.exists(job_output_dir):
|
|
make_dir(job_output_dir)
|