diff --git a/apps/cli/executables/vulture/src/vulture/condorlite.py b/apps/cli/executables/vulture/src/vulture/condorlite.py index 31ba0a553b77d0e23789385da4914d1aac20d5dc..4491aee36445320ca2811c1e531f8c701b178862 100644 --- a/apps/cli/executables/vulture/src/vulture/condorlite.py +++ b/apps/cli/executables/vulture/src/vulture/condorlite.py @@ -1,12 +1,52 @@ +# 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 - diff --git a/apps/cli/executables/vulture/src/vulture/execute.py b/apps/cli/executables/vulture/src/vulture/execute.py index 18eb05711d7c9b5042897d90171c594bb3bdbab6..5d331ebbe6b05b8304eccd4e8d5bea998335e26d 100644 --- a/apps/cli/executables/vulture/src/vulture/execute.py +++ b/apps/cli/executables/vulture/src/vulture/execute.py @@ -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()