60 lines
2.0 KiB
Python
Executable File
60 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
"""Django's command-line utility for administrative tasks."""
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def main():
|
|
"""Run administrative tasks."""
|
|
try:
|
|
from dotenv import load_dotenv
|
|
env_path = Path(__file__).resolve().parent.parent / '.env'
|
|
if env_path.exists():
|
|
load_dotenv(env_path)
|
|
except ImportError:
|
|
pass
|
|
|
|
# --- FIX: Preload libraries for WeasyPrint/Pango ---
|
|
# This fixes OSError: cannot load library 'libgobject-2.0-0' during deployment
|
|
import ctypes.util
|
|
import ctypes
|
|
|
|
# 1. Ensure LD_LIBRARY_PATH includes standard paths (helper for find_library)
|
|
if 'LD_LIBRARY_PATH' not in os.environ:
|
|
os.environ['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu:/usr/lib'
|
|
else:
|
|
if '/usr/lib/x86_64-linux-gnu' not in os.environ['LD_LIBRARY_PATH']:
|
|
os.environ['LD_LIBRARY_PATH'] += ':/usr/lib/x86_64-linux-gnu'
|
|
|
|
# 2. Manually load the library to ensure it's available
|
|
try:
|
|
if not ctypes.util.find_library('libgobject-2.0-0'):
|
|
# Try to load known paths directly
|
|
candidates = [
|
|
'libgobject-2.0.so.0',
|
|
'/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0',
|
|
'/usr/lib/libgobject-2.0.so.0'
|
|
]
|
|
for c in candidates:
|
|
try:
|
|
ctypes.CDLL(c)
|
|
break
|
|
except OSError:
|
|
continue
|
|
except Exception:
|
|
pass
|
|
# ---------------------------------------------------
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
|
try:
|
|
from django.core.management import execute_from_command_line
|
|
except ImportError as exc:
|
|
raise ImportError(
|
|
"Couldn't import Django. Are you sure it's installed and "
|
|
"available on your PYTHONPATH environment variable? Did you "
|
|
"forget to activate a virtual environment?"
|
|
) from exc
|
|
execute_from_command_line(sys.argv)
|
|
|
|
if __name__ == '__main__':
|
|
main() |