49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""infra_paths.py — Resolucion de rutas compartidas del repo INFRAESTRUCTURA.
|
|
|
|
Los scripts de infraestructura viven en `INFRAESTRUCTURA/scripts/` y necesitan:
|
|
- Estado runtime propio del repo -> `INFRAESTRUCTURA/estado/`
|
|
- Datos de negocio y modulos aun compartidos del repo
|
|
`biblioteca_negocio_prolongo` -> pendientes.json, idd_channel, netatmo_tool, alarma_twilio
|
|
|
|
La ubicacion del repo de negocio se resuelve asi (por orden):
|
|
1. Variable de entorno `BIBLIOTECA_REPO`
|
|
2. Repo hermano de INFRAESTRUCTURA: `../biblioteca_negocio_prolongo`
|
|
|
|
En el portatil la estructura de carpetas es la misma (`Documents/GitHub/...`), por lo
|
|
que el hermano funciona sin configurar nada; `BIBLIOTECA_REPO` permite sobreescribirlo.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
INFRA_ROOT = Path(__file__).resolve().parent.parent
|
|
SCRIPTS_DIR = INFRA_ROOT / "scripts"
|
|
ESTADO_DIR = INFRA_ROOT / "estado"
|
|
|
|
|
|
def biblioteca_repo() -> Path:
|
|
"""Devuelve la ruta del repo de negocio (biblioteca_negocio_prolongo)."""
|
|
env = os.environ.get("BIBLIOTECA_REPO")
|
|
if env:
|
|
return Path(env).expanduser().resolve()
|
|
return (INFRA_ROOT.parent / "biblioteca_negocio_prolongo").resolve()
|
|
|
|
|
|
def bootstrap_biblioteca_paths() -> Path:
|
|
"""Anade al sys.path los modulos que aun viven en el repo de negocio.
|
|
|
|
Transitorio: `idd_channel`, `netatmo_tool` y `alarma_twilio` siguen en
|
|
biblioteca_negocio_prolongo porque los bots del VPS los importan desde alli.
|
|
Cuando se centralicen en INFRAESTRUCTURA, esta funcion quedara vacia.
|
|
"""
|
|
repo = biblioteca_repo()
|
|
for candidato in (repo, repo / "scripts"):
|
|
sp = str(candidato)
|
|
if candidato.exists() and sp not in sys.path:
|
|
sys.path.insert(0, sp)
|
|
return repo
|