1#!/usr/bin/env python323from pathlib import Path4import sys567def handle_owners(repo_root, file):8 includes = []9 with file.open() as f:10 print("{}:".format(file.relative_to(repo_root)))11 for line in f:12 if line.startswith("include "):13 includes.append(Path(line.split()[1][1:]).absolute())1415 print(f"\t{line}", end="")16 print()1718 for include in includes:19 handle_owners(repo_root, include)202122if len(sys.argv) != 2:23 print("usage: find_owners.py <PATH>")24 exit(1)2526p = Path(sys.argv[1]).absolute()27if not p.exists():28 print(f"{sys.argv[1]} does not exist")29 exit(2)3031repo_root = None32current = p33while current != current.parent:34 if (current / ".git").is_dir():35 repo_root = current36 break37 current = current.parent3839if repo_root is None:40 print("Could not find repository root (no .git directory)")41 exit(3)4243if p.is_file() and p.name == "OWNERS":44 handle_owners(repo_root, p)45 p = p.parent.parent4647while True:48 inner = p / "OWNERS"49 if inner.is_file():50 handle_owners(repo_root, inner)5152 if p == repo_root:53 break5455 p = p.parent