Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Valo-Plex9# File : moteur/plexmoteur/config.py10# Description : Chemins et constantes d'exploitation.11# Module : moteur12# Repository : https://git.spboucher.ai/valo-plex13# Project Website : https://www.valo-plex.com14# Created : 2026-12-0115# Last Modified : 2026-12-0116#17# =============================================================================18# AUTHOR & PROFESSIONAL AFFILIATION19# =============================================================================20#21# Author : Simon-Pierre Boucher22# Position : Professor of Finance23# Institution : Université du Québec en Outaouais (UQO)24# Department : Département des sciences administratives25# Organization : SP Boucher26#27# Website : https://spboucher.ai28# Git : https://git.spboucher.ai29#30# =============================================================================31# OFFICIAL CONTACT DIRECTORY32# =============================================================================33#34# General : info@spboucher.ai35# Professional : contact@spboucher.ai36# Direct : simon@spboucher.ai37# Research : research@spboucher.ai38# Development : dev@spboucher.ai39# Support : support@spboucher.ai40# Security/Admin : admin@spboucher.ai41# Notifications : notifications@spboucher.ai42#43# Preferred Contact: contact@spboucher.ai44#45# =============================================================================46# COPYRIGHT & INTELLECTUAL PROPERTY47# =============================================================================48#49# Copyright (c) 202650# Simon-Pierre Boucher51#52# All rights reserved where applicable.53#54# This file is governed by the applicable project license,55# copyright notices, institutional agreements and relevant law.56#57# Unless expressly authorized by the applicable license or58# rights holder, copying, redistribution, sublicensing,59# publication and commercial exploitation are not permitted.60#61# Existing third-party rights and notices remain unaffected.62#63# =============================================================================64# CONFIDENTIALITY & SECURITY65# =============================================================================66#67# Classification : Public68# Distribution : Public repository; use is governed by the project license69# Security Contact : admin@spboucher.ai70#71# Access to this source does not independently grant permission72# to redistribute or disclose confidential materials.73#74# Do not embed credentials, private keys, access tokens,75# certificates or confidential personal information.76#77# =============================================================================78# LICENSE & MAINTENANCE79# =============================================================================80#81# License : None specified (no license file in this repository)82# Maintainer : Simon-Pierre Boucher83# Technical Contact: dev@spboucher.ai84#85# =============================================================================86# END OF SP BOUCHER SOURCE HEADER87# =============================================================================8889"""Chemins et constantes d'exploitation. Tout se règle par variables d'environnement."""90from __future__ import annotations9192import contextlib93import os94import sqlite395from pathlib import Path9697RACINE = Path(__file__).resolve().parents[2]98DATA = Path(os.environ.get("VX_DATA_DIR", RACINE / "data"))99# Bases de Vrai-Prix (lecture seule) : rôle, ventes, rattachements, inscriptions.100SOURCE = Path(os.environ.get("VX_SOURCE_DIR", Path.home() / "apps/vrai-prix-v3/data"))101ROLE_DB = SOURCE / "vraiprix.db"102V3_DB = SOURCE / "vraiprix-v3.db"103IMMOKA_DB = SOURCE / "immoka.db"104# Loyers demandés : base de Lou-Ka. Par défaut sur un autre nœud, lue par SSH (VX_LOUKA_HOTE,105# VX_LOUKA_DB relatif au dossier personnel distant). Si VX_LOUKA_FICHIER est posé, la base est lue106# sur place, en lecture seule (Lou-Ka installé sur le même serveur) : aucun SSH.107LOUKA_HOTE = os.environ.get("VX_LOUKA_HOTE", "M4M64a")108LOUKA_DB = os.environ.get("VX_LOUKA_DB", "apps/lou-ka/data/louka.db")109LOUKA_FICHIER = os.environ.get("VX_LOUKA_FICHIER", "").strip()110111DB = DATA / "valoplex.db"112MODELES = DATA / "modeles"113SEED = 20261201114THREADS = max(1, min(12, (os.cpu_count() or 4) // 2))115116117def ouvrir(ecriture: bool = False) -> sqlite3.Connection:118 DATA.mkdir(parents=True, exist_ok=True)119 if ecriture:120 # isolation_level=None : aucune transaction implicite ; chaque étape ouvre la sienne (``transaction``)121 # adresse en URI : la connexion accepte alors les URI de ATTACH (``file:…?mode=ro`` des sources).122 # macOS compile SQLite avec les URI activées d'office ; ailleurs (Linux) il faut le demander ici,123 # sinon ATTACH prend l'URI pour un nom de fichier et échoue.124 con = sqlite3.connect(DB.resolve().as_uri(), uri=True, timeout=120, isolation_level=None)125 con.execute("PRAGMA journal_mode=WAL")126 con.execute("PRAGMA synchronous=NORMAL")127 else:128 con = sqlite3.connect(f"file:{DB}?mode=ro", uri=True, timeout=120)129 con.row_factory = sqlite3.Row130 return con131132133def attacher_sources(con: sqlite3.Connection) -> None:134 for nom, chemin in (("role", ROLE_DB), ("v3", V3_DB), ("ik", IMMOKA_DB)):135 con.execute(f"ATTACH DATABASE 'file:{chemin}?mode=ro' AS {nom}")136137138@contextlib.contextmanager139def transaction(con: sqlite3.Connection):140 """Une étape = une transaction. Le site lit la base pendant la passe : tant141 que l'étape n'est pas validée, il voit les tables d'avant, entières. Ne142 jamais reconstruire une table hors d'une transaction (``executescript``143 valide d'office et laisserait voir des tables vides)."""144 con.execute("BEGIN IMMEDIATE")145 try:146 yield con147 except BaseException:148 con.execute("ROLLBACK")149 raise150 else:151 con.execute("COMMIT")152153154def script(con: sqlite3.Connection, sql: str) -> None:155 """Exécute plusieurs instructions une à une, DANS la transaction en cours."""156 for instruction in sql.split(";"):157 if instruction.strip():158 con.execute(instruction)159