Skip to content
Snippets Groups Projects
Commit 7a3d483d authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Barebones implementation of vulture that runs an executable

parent b7e8d878
No related branches found
No related tags found
No related merge requests found
# TODO: Event types that need to be supported: submitted, executing, terminated
# TODO: Log to file
import subprocess
from pathlib import Path
from typing import NamedTuple, List, Dict
from collections import namedtuple
class Job:
"""
Class representing a faked HTCondor job
"""
def __init__(self, file: Path):
self.fields, self.command = self.parse(file)
def parse(self, file: Path) -> NamedTuple:
"""
Parse condor job file for relevant fields
:param file: Path to job file
:return: NamedTuple of job data
"""
# Parse file looking for executable and arguments
JobData = namedtuple("JobData", ["field_data", "command"])
section_sep = "\n\n"
field_sep = "\n"
with open(file, "r") as f:
# Split file into data and action sections
data, command = f.read().split(section_sep)
fields = data.split(field_sep)
field_dict = self.parse_fields(fields)
return JobData(field_dict, command)
@staticmethod
def parse(file):
job = Job()
# do something here to iterate the file contents and parse it
raise NotImplementedError
def parse_fields(fields: List[str]) -> Dict[str, str]:
"""
Take in list of fields parsed from input file and return them as a dictionary
:param fields: List of fields
:return: Dictionary of fields
"""
field_dict = {}
for field in fields:
key, value = field.split(" = ")
field_dict[key] = value
return field_dict
def execute(self):
raise NotImplementedError
subprocess.run([self.fields['executable'], self.fields['arguments']])
class Dag:
......@@ -16,7 +56,5 @@ class Dag:
# do something here to iterate the file contents and parse it
raise NotImplementedError
def execute(self):
raise NotImplementedError
......@@ -5,6 +5,8 @@ CLI to our fake dagman executor and fake job executor
import argparse as ap
from pathlib import Path
from .condorlite import Job
def execute_dag(file: Path):
"""
......@@ -22,7 +24,7 @@ def execute_job(file: Path):
:param file:
:return:
"""
job = Job.parse(file)
job = Job(file)
job.execute()
......@@ -44,6 +46,7 @@ def main():
args = parser.parse_args()
if 'func' in args and 'file' in args:
args.func(args.file)
for f in args.file:
args.func(f)
else:
parser.print_usage()
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