JairoDanielMT commited on
Commit
701cf50
1 Parent(s): f3be12e

texto seleccionable

Browse files
Files changed (1) hide show
  1. app/config.py +0 -55
app/config.py CHANGED
@@ -1,61 +1,6 @@
1
  from __future__ import annotations
2
 
3
- import logging
4
- import os
5
  from pathlib import Path
6
- from typing import Optional
7
-
8
- import pdfkit
9
 
10
  # Carpeta de este m贸dulo (app/)
11
  BASE_DIR = Path(__file__).parent
12
-
13
- # Cache de configuraci贸n de pdfkit
14
- # False => a煤n no inicializado
15
- # None => se intent贸 inicializar pero no se encontr贸 wkhtmltopdf
16
- # config => configuraci贸n v谩lida
17
- _PDFKIT_CONFIG: Optional[pdfkit.configuration] | bool = False
18
-
19
-
20
- def _detect_wkhtmltopdf() -> Optional[str]:
21
- """
22
- Para entorno Docker (Linux):
23
-
24
- 1) Si hay WKHTMLTOPDF_PATH y apunta a un archivo, usarlo.
25
- 2) Si no, devolver None y dejar que pdfkit use lo que haya en PATH.
26
-
27
- No nos preocupamos por .exe ni por Windows aqu铆.
28
- """
29
- env_path = os.getenv("WKHTMLTOPDF_PATH")
30
- if env_path and Path(env_path).is_file():
31
- return env_path
32
-
33
- # None = que pdfkit use wkhtmltopdf del PATH (/usr/bin/wkhtmltopdf)
34
- return None
35
-
36
-
37
- def get_pdfkit_config() -> Optional[pdfkit.configuration]:
38
- """
39
- Devuelve una instancia de pdfkit.configuration o None si
40
- no se pudo inicializar wkhtmltopdf.
41
- """
42
- global _PDFKIT_CONFIG
43
-
44
- if _PDFKIT_CONFIG is not False:
45
- return _PDFKIT_CONFIG # type: ignore[return-value]
46
-
47
- wkhtml_path = _detect_wkhtmltopdf()
48
-
49
- try:
50
- if wkhtml_path:
51
- _PDFKIT_CONFIG = pdfkit.configuration(wkhtmltopdf=wkhtml_path)
52
- logging.info("wkhtmltopdf detectado en WKHTMLTOPDF_PATH: %s", wkhtml_path)
53
- else:
54
- # Usar binario en PATH (caso normal en Docker: /usr/bin/wkhtmltopdf)
55
- _PDFKIT_CONFIG = pdfkit.configuration()
56
- logging.info("wkhtmltopdf detectado en PATH.")
57
- except OSError as exc:
58
- logging.error("No se pudo inicializar pdfkit: %s", exc)
59
- _PDFKIT_CONFIG = None
60
-
61
- return _PDFKIT_CONFIG # type: ignore[return-value]
 
1
  from __future__ import annotations
2
 
 
 
3
  from pathlib import Path
 
 
 
4
 
5
  # Carpeta de este m贸dulo (app/)
6
  BASE_DIR = Path(__file__).parent