mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Cleanup calibre initialization
This commit is contained in:
parent
c58e1db9a0
commit
8311f0a8d3
@ -19,13 +19,14 @@ except EnvironmentError:
|
||||
from calibre.constants import (iswindows, ismacos, islinux, isfrozen,
|
||||
isbsd, preferred_encoding, __appname__, __version__, __author__,
|
||||
plugins, filesystem_encoding, config_dir)
|
||||
from calibre.startup import get_debug_executable
|
||||
from calibre.startup import initialize_calibre
|
||||
initialize_calibre()
|
||||
from calibre.utils.icu import safe_chr
|
||||
from calibre.prints import prints
|
||||
|
||||
if False:
|
||||
# Prevent pyflakes from complaining
|
||||
get_debug_executable, __appname__, islinux, __version__
|
||||
__appname__, islinux, __version__
|
||||
isfrozen, __author__, isbsd, config_dir, plugins
|
||||
|
||||
_mt_inited = False
|
||||
|
@ -20,10 +20,7 @@ builtins.__dict__['__'] = lambda s: s
|
||||
# For backwards compat with some third party plugins
|
||||
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
||||
|
||||
|
||||
from calibre.constants import iswindows, preferred_encoding, plugins, ismacos, islinux, DEBUG, isfreebsd
|
||||
|
||||
_run_once = False
|
||||
from calibre.constants import iswindows, plugins, ismacos, islinux, DEBUG, isfreebsd
|
||||
|
||||
|
||||
def get_debug_executable():
|
||||
@ -46,8 +43,11 @@ def get_debug_executable():
|
||||
return [exe_name]
|
||||
|
||||
|
||||
if not _run_once:
|
||||
_run_once = True
|
||||
def initialize_calibre():
|
||||
if hasattr(initialize_calibre, 'initialized'):
|
||||
return
|
||||
initialize_calibre.initialized = True
|
||||
|
||||
# Ensure that all temp files/dirs are created under a calibre tmp dir
|
||||
from calibre.ptempfile import base_dir
|
||||
try:
|
||||
@ -55,15 +55,6 @@ if not _run_once:
|
||||
except EnvironmentError:
|
||||
pass # Ignore this error during startup, so we can show a better error message to the user later.
|
||||
|
||||
#
|
||||
# Convert command line arguments to unicode
|
||||
enc = preferred_encoding
|
||||
if ismacos:
|
||||
enc = 'utf-8'
|
||||
for i in range(1, len(sys.argv)):
|
||||
if not isinstance(sys.argv[i], unicode_type):
|
||||
sys.argv[i] = sys.argv[i].decode(enc, 'replace')
|
||||
|
||||
#
|
||||
# Ensure that the max number of open files is at least 1024
|
||||
if iswindows:
|
||||
@ -130,10 +121,7 @@ if not _run_once:
|
||||
except:
|
||||
pass
|
||||
|
||||
# local_open() opens a file that wont be inherited by child processes
|
||||
local_open = open # PEP 446
|
||||
builtins.__dict__['lopen'] = local_open
|
||||
|
||||
builtins.__dict__['lopen'] = open # legacy compatibility
|
||||
from calibre.utils.icu import title_case, lower as icu_lower, upper as icu_upper
|
||||
builtins.__dict__['icu_lower'] = icu_lower
|
||||
builtins.__dict__['icu_upper'] = icu_upper
|
||||
|
Loading…
x
Reference in New Issue
Block a user