LibreOffice Calc extension for Silo PLM integration. Uses shared silo-client package (submodule) for API communication. Changes from monorepo version: - SiloClient class removed from client.py, replaced with CalcSiloSettings adapter + factory function wrapping silo_client.SiloClient - silo_calc_component.py adds silo-client to sys.path - Makefile build-oxt copies silo_client into .oxt for self-contained packaging - All other modules unchanged
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""Silo API client for LibreOffice Calc extension.
|
|
|
|
Thin wrapper around the shared ``silo_client`` package. Provides a
|
|
``CalcSiloSettings`` adapter that reads/writes the local JSON settings
|
|
file, and re-exports ``SiloClient`` so existing ``from .client import
|
|
SiloClient`` imports continue to work unchanged.
|
|
"""
|
|
|
|
import os
|
|
import urllib.parse
|
|
|
|
from silo_client import SiloClient as _BaseSiloClient
|
|
from silo_client import SiloSettings
|
|
|
|
from . import settings as _settings
|
|
|
|
|
|
class CalcSiloSettings(SiloSettings):
|
|
"""Settings adapter backed by ``~/.config/silo/calc-settings.json``."""
|
|
|
|
def get_api_url(self) -> str:
|
|
cfg = _settings.load()
|
|
url = cfg.get("api_url", "").rstrip("/")
|
|
if not url:
|
|
url = os.environ.get("SILO_API_URL", "http://localhost:8080/api")
|
|
parsed = urllib.parse.urlparse(url)
|
|
if not parsed.path or parsed.path == "/":
|
|
url = url + "/api"
|
|
return url
|
|
|
|
def get_api_token(self) -> str:
|
|
return _settings.load().get("api_token", "") or os.environ.get(
|
|
"SILO_API_TOKEN", ""
|
|
)
|
|
|
|
def get_ssl_verify(self) -> bool:
|
|
return _settings.load().get("ssl_verify", True)
|
|
|
|
def get_ssl_cert_path(self) -> str:
|
|
return _settings.load().get("ssl_cert_path", "")
|
|
|
|
def save_auth(self, username, role, source, token):
|
|
_settings.save_auth(username=username, role=role, source=source, token=token)
|
|
|
|
def clear_auth(self):
|
|
_settings.clear_auth()
|
|
|
|
|
|
_calc_settings = CalcSiloSettings()
|
|
|
|
|
|
def SiloClient(base_url=None):
|
|
"""Factory matching the old ``SiloClient(base_url=...)`` constructor."""
|
|
return _BaseSiloClient(_calc_settings, base_url=base_url)
|