mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -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,
|
from calibre.constants import (iswindows, ismacos, islinux, isfrozen,
|
||||||
isbsd, preferred_encoding, __appname__, __version__, __author__,
|
isbsd, preferred_encoding, __appname__, __version__, __author__,
|
||||||
plugins, filesystem_encoding, config_dir)
|
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.utils.icu import safe_chr
|
||||||
from calibre.prints import prints
|
from calibre.prints import prints
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# Prevent pyflakes from complaining
|
# Prevent pyflakes from complaining
|
||||||
get_debug_executable, __appname__, islinux, __version__
|
__appname__, islinux, __version__
|
||||||
isfrozen, __author__, isbsd, config_dir, plugins
|
isfrozen, __author__, isbsd, config_dir, plugins
|
||||||
|
|
||||||
_mt_inited = False
|
_mt_inited = False
|
||||||
|
@ -20,10 +20,7 @@ builtins.__dict__['__'] = lambda s: s
|
|||||||
# For backwards compat with some third party plugins
|
# For backwards compat with some third party plugins
|
||||||
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
||||||
|
|
||||||
|
from calibre.constants import iswindows, plugins, ismacos, islinux, DEBUG, isfreebsd
|
||||||
from calibre.constants import iswindows, preferred_encoding, plugins, ismacos, islinux, DEBUG, isfreebsd
|
|
||||||
|
|
||||||
_run_once = False
|
|
||||||
|
|
||||||
|
|
||||||
def get_debug_executable():
|
def get_debug_executable():
|
||||||
@ -46,8 +43,11 @@ def get_debug_executable():
|
|||||||
return [exe_name]
|
return [exe_name]
|
||||||
|
|
||||||
|
|
||||||
if not _run_once:
|
def initialize_calibre():
|
||||||
_run_once = True
|
if hasattr(initialize_calibre, 'initialized'):
|
||||||
|
return
|
||||||
|
initialize_calibre.initialized = True
|
||||||
|
|
||||||
# Ensure that all temp files/dirs are created under a calibre tmp dir
|
# Ensure that all temp files/dirs are created under a calibre tmp dir
|
||||||
from calibre.ptempfile import base_dir
|
from calibre.ptempfile import base_dir
|
||||||
try:
|
try:
|
||||||
@ -55,15 +55,6 @@ if not _run_once:
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass # Ignore this error during startup, so we can show a better error message to the user later.
|
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
|
# Ensure that the max number of open files is at least 1024
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -130,10 +121,7 @@ if not _run_once:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# local_open() opens a file that wont be inherited by child processes
|
builtins.__dict__['lopen'] = open # legacy compatibility
|
||||||
local_open = open # PEP 446
|
|
||||||
builtins.__dict__['lopen'] = local_open
|
|
||||||
|
|
||||||
from calibre.utils.icu import title_case, lower as icu_lower, upper as icu_upper
|
from calibre.utils.icu import title_case, lower as icu_lower, upper as icu_upper
|
||||||
builtins.__dict__['icu_lower'] = icu_lower
|
builtins.__dict__['icu_lower'] = icu_lower
|
||||||
builtins.__dict__['icu_upper'] = icu_upper
|
builtins.__dict__['icu_upper'] = icu_upper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user