Skip to content

Commit

Permalink
flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Jan 31, 2025
1 parent 70f8147 commit e6fc45f
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions .github/scripts/port_validation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python3

import os
import sys
import yaml
from os import scandir


def extract_ports(quests):
Expand All @@ -19,21 +19,34 @@ def extract_ports(quests):
return ports


def scan_directory(path: str, current_depth: int = 0, to_depth: int = 2):
"""Iterate over `path` to depth level `to_depth`
and yield any file paths at that level."""
if current_depth > to_depth:
return

with scandir(path) as sdir:
for entry in sdir:
if current_depth == to_depth and entry.is_file():
yield entry.path
elif (current_depth < to_depth) and entry.is_dir():
yield from scan_directory(entry.path, current_depth + 1)


def main():
port_map = {}
for train in os.scandir("ix-dev"):
for app in os.scandir(f"ix-dev/{train.name}"):
quest_path = f"ix-dev/{train.name}/{app.name}/questions.yaml"
if not os.path.exists(quest_path):
continue

with open(f"ix-dev/{train.name}/{app.name}/questions.yaml", "r") as f:
ports = extract_ports(yaml.load(f, Loader=yaml.FullLoader)["questions"])
for port in ports:
port_num = port["port"]
if port_num not in port_map:
port_map[port_num] = []
port_map[port_num].append(app.name)
for path in scan_directory("ix-dev"):
if not path.endswith("questions.yaml"):
continue
with open(path, "r") as f:
train = path.split("/")[-3]
app = path.split("/")[-2]
ports = extract_ports(yaml.load(f, Loader=yaml.FullLoader)["questions"])
for port in ports:
port_num = port["port"]
if port_num not in port_map:
port_map[port_num] = []
port_map[port_num].append(f"{train}/{app}")

ignore_ports = [53, 22000]
dupe_found = False
Expand Down

0 comments on commit e6fc45f

Please sign in to comment.