| 1 |
import builtins |
| 2 |
import os |
| 3 |
import sys |
| 4 |
|
| 5 |
import _sitebuiltins |
| 6 |
|
| 7 |
USER_SITE = None |
| 8 |
|
| 9 |
|
| 10 |
def nuke_stdout(): |
| 11 |
# Redirect stdout, stdin and stderr to /dev/null |
| 12 |
from calibre_extensions.speedup import detach |
| 13 |
detach(os.devnull) |
| 14 |
|
| 15 |
|
| 16 |
def set_helper(): |
| 17 |
builtins.help = _sitebuiltins._Helper() |
| 18 |
|
| 19 |
|
| 20 |
def set_quit(): |
| 21 |
eof = 'Ctrl-D (i.e. EOF)' |
| 22 |
builtins.quit = _sitebuiltins.Quitter('quit', eof) |
| 23 |
builtins.exit = _sitebuiltins.Quitter('exit', eof) |
| 24 |
|
| 25 |
|
| 26 |
def main(): |
| 27 |
sys.argv[0] = sys.calibre_basename |
| 28 |
set_helper() |
| 29 |
set_quit() |
| 30 |
mod = __import__(sys.calibre_module, fromlist=[1]) |
| 31 |
func = getattr(mod, sys.calibre_function) |
| 32 |
if sys.gui_app and not ( |
| 33 |
sys.stdout.isatty() or sys.stderr.isatty() or sys.stdin.isatty() |
| 34 |
): |
| 35 |
# this has to be done after calibre is imported and therefore |
| 36 |
# calibre_extensions is available. |
| 37 |
nuke_stdout() |
| 38 |
return func() |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
main() |