Last active
August 8, 2024 16:12
-
-
Save rajvermacas/a997468403c4f63f5125384cd2f0ee20 to your computer and use it in GitHub Desktop.
AutosysGilParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def parse_jobs(file_path): | |
"""Parses the gil.txt file and returns a dictionary of jobs with their dependencies.""" | |
with open(file_path, 'r') as file: | |
content = file.read() | |
# Split the content into job blocks based on insert_job keyword | |
job_blocks = re.split(r'\/\*\s+[\w\s-]+\s+\*\/', content) | |
job_dict = {} | |
for block in job_blocks: | |
# Skip empty blocks | |
if not block.strip(): | |
continue | |
# Extract the job name | |
job_name_match = re.search(r'insert_job:\s+(\w+)', block) | |
if job_name_match: | |
job_name = job_name_match.group(1) | |
# Extract the condition (dependencies) | |
condition_match = re.search(r'condition:\s+(.*)', block) | |
if condition_match: | |
condition = condition_match.group(1) | |
# Find all dependencies in the condition, ignoring timestamps (success(job_name, time)) | |
dependencies = re.findall(r'(?:success|s|n)\((\w+),?\s*\d*\.*\d*\)', condition) | |
else: | |
dependencies = [] | |
job_dict[job_name] = dependencies | |
return job_dict | |
def find_all_dependencies(job_name, job_dict, visited=None): | |
"""Recursively finds all dependencies for a given job.""" | |
if visited is None: | |
visited = set() | |
if job_name not in job_dict: | |
return [] | |
dependencies = job_dict[job_name] | |
all_dependencies = [] | |
for dep in dependencies: | |
if dep not in visited: | |
visited.add(dep) | |
all_dependencies.append(dep) | |
all_dependencies.extend(find_all_dependencies(dep, job_dict, visited)) | |
return all_dependencies | |
if __name__ == "__main__": | |
# Parse the file and create a job dictionary | |
job_dict = parse_jobs(r'gil.txt') | |
# Input job name to find dependencies | |
# job_name = input("Enter the job name: ") | |
job_name = "group_name3" | |
# Find all dependencies | |
dependencies = find_all_dependencies(job_name, job_dict) | |
# Output the dependencies | |
if dependencies: | |
print(f"All dependent jobs for '{job_name}': {dependencies}") | |
else: | |
print(f"No dependencies found for '{job_name}'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment