Files
Copies/copienator/rubrics.py
T

22 lines
761 B
Python

"""Shared inventory of usable, individual Persp files."""
from pathlib import Path
def present_rubric_labels(root: Path, labels: list[str]) -> list[str]:
present = []
for label in labels:
path = root / 'Persp' / label.replace('/', '_')
if not path.is_file():
continue
try:
content = path.read_text(encoding='utf-8').strip()
except UnicodeError:
continue
lines = content.split('\n', 1)
body = lines[1].strip() if lines[0].strip() == label and len(lines) > 1 else content
if body and body != label and not any(
(ord(char) < 32 and char != '\n') or ord(char) == 127 for char in content
):
present.append(label)
return present