@@ -63,13 +63,18 @@ def generate_key_variants(source_path: Path, source_root: Path, output_dir: Path
|
||||
def generate_practice_scores(source_dir: Path, output_dir: Path) -> int:
|
||||
if not source_dir.exists():
|
||||
return 0
|
||||
sources = sorted(source_dir.rglob('*.xml'))
|
||||
destinations: dict[Path, Path] = {}
|
||||
for path in sources:
|
||||
parts = path.relative_to(source_dir).parts
|
||||
if len(parts) != 3 or parts[0] not in ('chord', 'melody'):
|
||||
raise ValueError(f'{path}: practice source must be stored as practice/<chord|melody>/<lesson_group>/<exercise>.xml')
|
||||
destination = Path(parts[0]) / parts[1] / slugify(path.stem)
|
||||
if destination in destinations:
|
||||
raise ValueError(f'{path}: practice output path collides with {destinations[destination]}: {destination}')
|
||||
destinations[destination] = path
|
||||
count = 0
|
||||
chord_root = source_dir / "chord"
|
||||
if chord_root.exists():
|
||||
for path in sorted(chord_root.rglob("*.xml")):
|
||||
count += generate_chord_practice(path, chord_root, output_dir)
|
||||
melody_root = source_dir / "melody"
|
||||
if melody_root.exists():
|
||||
for path in sorted(melody_root.rglob("*.xml")):
|
||||
count += generate_melody_practice(path, melody_root, output_dir)
|
||||
for destination, path in destinations.items():
|
||||
practice_type = destination.parts[0]
|
||||
count += generate_key_variants(path, source_dir / practice_type, output_dir, practice_type)
|
||||
return count
|
||||
|
||||
Reference in New Issue
Block a user