| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> |
| 4 |
|
| 5 |
import builtins |
| 6 |
import os |
| 7 |
import sys |
| 8 |
|
| 9 |
import _sitebuiltins |
| 10 |
|
| 11 |
USER_SITE = None |
| 12 |
|
| 13 |
|
| 14 |
def set_quit(): |
| 15 |
eof = 'Ctrl-D (i.e. EOF)' |
| 16 |
builtins.quit = _sitebuiltins.Quitter('quit', eof) |
| 17 |
builtins.exit = _sitebuiltins.Quitter('exit', eof) |
| 18 |
|
| 19 |
|
| 20 |
def setup_openssl_environment(): |
| 21 |
# Workaround for Linux distros that have still failed to get their heads |
| 22 |
# out of their asses and implement a common location for SSL certificates. |
| 23 |
# It's not that hard people, there exists a wonderful tool called the symlink |
| 24 |
# See http://www.mobileread.com/forums/showthread.php?t=256095 |
| 25 |
if 'SSL_CERT_FILE' not in os.environ and 'SSL_CERT_DIR' not in os.environ: |
| 26 |
if os.access('/etc/pki/tls/certs/ca-bundle.crt', os.R_OK): |
| 27 |
os.environ['SSL_CERT_FILE'] = '/etc/pki/tls/certs/ca-bundle.crt' |
| 28 |
# morons in Fedora removed the bundle file in Fedora 44. |
| 29 |
# https://fedoraproject.org/wiki/Changes/droppingOfCertPemFile |
| 30 |
# Hopefully there does not exist another distro that uses this dir for something else. |
| 31 |
elif os.path.isdir('/etc/pki/tls/certs'): |
| 32 |
os.environ['SSL_CERT_DIR'] = '/etc/pki/tls/certs' |
| 33 |
elif os.path.isdir('/etc/ssl/certs'): |
| 34 |
os.environ['SSL_CERT_DIR'] = '/etc/ssl/certs' |
| 35 |
|
| 36 |
|
| 37 |
def preload_libxml2(): |
| 38 |
# QtWebEngineProcess on some ancient Linux systems probes for GPU backends |
| 39 |
# which loads swrast_dri.so which links against system libxml2, which |
| 40 |
# overwrites or global libxml2 symbols. |
| 41 |
# So we preload lxml and html5_parser as a workaround. |
| 42 |
# Thankfully this is basically only needed for ancient Debian as modern |
| 43 |
# mesa uses libexpat not libxml2. |
| 44 |
# We need a specific version of libxml2 as html5-parser checks the version, |
| 45 |
# so preload it to ensure we have the correct one. |
| 46 |
from html5_parser import parse |
| 47 |
setattr(preload_libxml2, 'parse', parse) |
| 48 |
|
| 49 |
|
| 50 |
def set_helper(): |
| 51 |
builtins.help = _sitebuiltins._Helper() |
| 52 |
|
| 53 |
|
| 54 |
def main(): |
| 55 |
sys.argv[0] = sys.calibre_basename |
| 56 |
set_helper() |
| 57 |
setup_openssl_environment() |
| 58 |
preload_libxml2() |
| 59 |
set_quit() |
| 60 |
mod = __import__(sys.calibre_module, fromlist=[1]) |
| 61 |
func = getattr(mod, sys.calibre_function) |
| 62 |
return func() |
| 63 |
|
| 64 |
|
| 65 |
if __name__ == '__main__': |
| 66 |
main() |