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 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 @staticmethod
def parse(file): def parse_fields(fields: List[str]) -> Dict[str, str]:
job = Job() """
# do something here to iterate the file contents and parse it Take in list of fields parsed from input file and return them as a dictionary
raise NotImplementedError :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): def execute(self):
raise NotImplementedError subprocess.run([self.fields['executable'], self.fields['arguments']])
class Dag: class Dag:
...@@ -16,7 +56,5 @@ class Dag: ...@@ -16,7 +56,5 @@ class Dag:
# do something here to iterate the file contents and parse it # do something here to iterate the file contents and parse it
raise NotImplementedError raise NotImplementedError
def execute(self): def execute(self):
raise NotImplementedError raise NotImplementedError
...@@ -5,6 +5,8 @@ CLI to our fake dagman executor and fake job executor ...@@ -5,6 +5,8 @@ CLI to our fake dagman executor and fake job executor
import argparse as ap import argparse as ap
from pathlib import Path from pathlib import Path
from .condorlite import Job
def execute_dag(file: Path): def execute_dag(file: Path):
""" """
...@@ -22,7 +24,7 @@ def execute_job(file: Path): ...@@ -22,7 +24,7 @@ def execute_job(file: Path):
:param file: :param file:
:return: :return:
""" """
job = Job.parse(file) job = Job(file)
job.execute() job.execute()
...@@ -44,6 +46,7 @@ def main(): ...@@ -44,6 +46,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if 'func' in args and 'file' in args: if 'func' in args and 'file' in args:
args.func(args.file) for f in args.file:
args.func(f)
else: else:
parser.print_usage() 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