gui.utils.path_setup
1# Copyright (C) 2026 David Vaquero <pepesan@gmail.com> 2# 3# This program is free software: you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation, either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <https://www.gnu.org/licenses/>. 15 16import sys 17from pathlib import Path 18 19_FROZEN = getattr(sys, 'frozen', False) 20 21if _FROZEN: 22 # Dentro de un bundle PyInstaller: sys._MEIPASS apunta a los recursos empaquetados 23 PROJECT_ROOT = Path(sys.executable).parent.resolve() 24 SRC_DIR = Path(sys._MEIPASS) # type: ignore[attr-defined] 25 COURSES_DIR = Path.home() / 'Temario' 26else: 27 PROJECT_ROOT = Path(__file__).parent.parent.parent.parent.resolve() 28 SRC_DIR = PROJECT_ROOT / 'src' 29 COURSES_DIR = PROJECT_ROOT / 'courses' # directorio por defecto (fallback) 30 31 32def setup_path() -> None: 33 if _FROZEN: 34 return # PyInstaller ya gestiona sys.path 35 src = str(SRC_DIR) 36 if src not in sys.path: 37 sys.path.insert(0, src) 38 39 40# Delega en slides_config (módulo compartido CLI+GUI en src/) 41setup_path() 42from lib.slides_config import ( # noqa: E402 43 get_courses_dir, 44 save_courses_dir, 45 CONFIG_PATH, 46) 47 48 49def get_courses() -> list[Path]: 50 courses_dir = get_courses_dir() or COURSES_DIR 51 if not courses_dir.exists(): 52 return [] 53 return sorted(d for d in courses_dir.iterdir() if d.is_dir()) 54 55 56def get_yamls(course_dir: Path) -> list[Path]: 57 content = course_dir / 'content' 58 if not content.exists(): 59 return [] 60 return sorted(content.glob('*.yaml'))
def
setup_path() -> None:
def
get_courses() -> list[pathlib.Path]:
def
get_yamls(course_dir: pathlib.Path) -> list[pathlib.Path]: