Files
breeze/scripts/practice_media.py
T
waozi 6b90f3670c Build practice packs from the practices repository
The practices' pictures, course data and recordings, 184 MB, move out of
Breeze into their own public repository, waozixyz/practices, pinned in
ziran.toml and ziran.lock like the other packages and linked at
build/packages/practices. The build stages them under assets/practices/ as
before, so every pack it makes is byte for byte the same. The narration,
Sun Salutation character and Tai Chi generators write into a practices
checkout mapped in ziran.local.toml. Breeze's history keeps the files.
2026-10-24 23:17:45 -03:00

38 lines
1.4 KiB
Python

"""Where the practice media is on disk.
The practices' pictures, course data and recordings live in the
practices package (https://github.com/waozixyz/practices),
pinned in ziran.lock and linked at build/packages/practices. Packages
keep their resources under assets/practices/, so a packaged path such as
assets/practices/taichi/course.tch names MEDIA / 'taichi/course.tch'.
"""
import os
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
MEDIA = ROOT / 'build/packages/practices'
PREFIX = 'assets/practices/'
def media_path(path):
"""The file on disk for a packaged path, or for a path in the project."""
path = str(path)
if path.startswith(PREFIX):
return MEDIA / path[len(PREFIX):]
return ROOT / path
def packaged_path(file):
"""The packaged path of a file in the practice media."""
return PREFIX + Path(file).resolve().relative_to(MEDIA.resolve()).as_posix()
def writable_media():
"""The media checkout generators may write into: a working repository
mapped in ziran.local.toml, never the locked package cache."""
cache = Path(os.environ.get('XDG_CACHE_HOME') or Path.home() / '.cache') / 'ziran'
if not MEDIA.is_dir() or MEDIA.resolve().is_relative_to(cache.resolve()):
raise SystemExit(f'{MEDIA} is the locked package; map practices to your '
'practices checkout in ziran.local.toml to change its media')
return MEDIA