mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-16 02:53:33 +02:00
Removed osx code
This commit is contained in:
@@ -17,14 +17,11 @@ Various run time constants.
|
|||||||
|
|
||||||
|
|
||||||
_plat = sys.platform.lower()
|
_plat = sys.platform.lower()
|
||||||
isosx = 'darwin' in _plat
|
|
||||||
isnewosx = isosx and getattr(sys, 'new_app_bundle', False)
|
|
||||||
isfreebsd = 'freebsd' in _plat
|
isfreebsd = 'freebsd' in _plat
|
||||||
isnetbsd = 'netbsd' in _plat
|
isnetbsd = 'netbsd' in _plat
|
||||||
isdragonflybsd = 'dragonfly' in _plat
|
isdragonflybsd = 'dragonfly' in _plat
|
||||||
ishaiku = 'haiku1' in _plat
|
ishaiku = 'haiku1' in _plat
|
||||||
isfrozen = hasattr(sys, 'frozen')
|
isfrozen = hasattr(sys, 'frozen')
|
||||||
isunix = True
|
|
||||||
isportable = os.getenv('CALIBRE_PORTABLE_BUILD') is not None
|
isportable = os.getenv('CALIBRE_PORTABLE_BUILD') is not None
|
||||||
isxp = isoldvista = False
|
isxp = isoldvista = False
|
||||||
is64bit = sys.maxsize > (1 << 32)
|
is64bit = sys.maxsize > (1 << 32)
|
||||||
|
|||||||
@@ -2,16 +2,10 @@ import importlib
|
|||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from ebook_converter.constants_old import numeric_version, isosx
|
from ebook_converter.constants_old import numeric_version
|
||||||
from ebook_converter.ptempfile import PersistentTemporaryFile
|
from ebook_converter.ptempfile import PersistentTemporaryFile
|
||||||
|
|
||||||
|
|
||||||
platform = 'linux'
|
|
||||||
|
|
||||||
if isosx:
|
|
||||||
platform = 'osx'
|
|
||||||
|
|
||||||
|
|
||||||
class PluginNotFound(ValueError):
|
class PluginNotFound(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -482,7 +476,8 @@ class CatalogPlugin(Plugin):
|
|||||||
|
|
||||||
# TODO(gryf): remove this entire abomination in favor of map and lazy
|
# TODO(gryf): remove this entire abomination in favor of map and lazy
|
||||||
# importing if needed.
|
# importing if needed.
|
||||||
from ebook_converter.customize.builtins import plugins as builtin_plugins
|
from ebook_converter.customize.builtins import plugins as \
|
||||||
|
builtin_plugins
|
||||||
if not type(self) in builtin_plugins:
|
if not type(self) in builtin_plugins:
|
||||||
raise ValueError(f'Plugin type "{self.__str__}" not found')
|
raise ValueError(f'Plugin type "{self.__str__}" not found')
|
||||||
|
|
||||||
@@ -526,8 +521,8 @@ class InterfaceActionBase(Plugin):
|
|||||||
ac = self.actual_plugin_
|
ac = self.actual_plugin_
|
||||||
if ac is None:
|
if ac is None:
|
||||||
mod, cls = self.actual_plugin.split(':')
|
mod, cls = self.actual_plugin.split(':')
|
||||||
ac = getattr(importlib.import_module(mod), cls)(gui,
|
ac = getattr(importlib.import_module(mod),
|
||||||
self.site_customization)
|
cls)(gui, self.site_customization)
|
||||||
self.actual_plugin_ = ac
|
self.actual_plugin_ = ac
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,11 @@ from struct import pack
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from ebook_converter.ebooks.oeb import base
|
from ebook_converter.ebooks.oeb import base
|
||||||
from ebook_converter.constants_old import isosx
|
|
||||||
from ebook_converter.ebooks.mobi.utils import (utf8_text, to_base)
|
from ebook_converter.ebooks.mobi.utils import (utf8_text, to_base)
|
||||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||||
from ebook_converter.ebooks.metadata import authors_to_sort_string
|
from ebook_converter.ebooks.metadata import authors_to_sort_string
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
EXTH_CODES = {
|
EXTH_CODES = {
|
||||||
'creator': 100,
|
'creator': 100,
|
||||||
'publisher': 101,
|
'publisher': 101,
|
||||||
@@ -45,10 +40,10 @@ COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+')
|
|||||||
|
|
||||||
|
|
||||||
def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
||||||
share_not_sync=True, cover_offset=None, thumbnail_offset=None,
|
share_not_sync=True, cover_offset=None, thumbnail_offset=None,
|
||||||
start_offset=None, mobi_doctype=2, num_of_resources=None,
|
start_offset=None, mobi_doctype=2, num_of_resources=None,
|
||||||
kf8_unknown_count=0, be_kindlegen2=False, kf8_header_index=None,
|
kf8_unknown_count=0, be_kindlegen2=False, kf8_header_index=None,
|
||||||
page_progression_direction=None, primary_writing_mode=None):
|
page_progression_direction=None, primary_writing_mode=None):
|
||||||
exth = BytesIO()
|
exth = BytesIO()
|
||||||
nrecs = 0
|
nrecs = 0
|
||||||
|
|
||||||
@@ -67,7 +62,7 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
elif term == 'rights':
|
elif term == 'rights':
|
||||||
try:
|
try:
|
||||||
rights = utf8_text(str(metadata.rights[0]))
|
rights = utf8_text(str(metadata.rights[0]))
|
||||||
except:
|
except Exception:
|
||||||
rights = b'Unknown'
|
rights = b'Unknown'
|
||||||
exth.write(pack(b'>II', EXTH_CODES['rights'], len(rights) + 8))
|
exth.write(pack(b'>II', EXTH_CODES['rights'], len(rights) + 8))
|
||||||
exth.write(rights)
|
exth.write(rights)
|
||||||
@@ -125,7 +120,7 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
exth.write(b'EBOK')
|
exth.write(b'EBOK')
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
else:
|
else:
|
||||||
ids = {0x101:b'NWPR', 0x103:b'MAGZ'}.get(mobi_doctype, None)
|
ids = {0x101: b'NWPR', 0x103: b'MAGZ'}.get(mobi_doctype, None)
|
||||||
if ids:
|
if ids:
|
||||||
exth.write(pack(b'>II', 501, 12))
|
exth.write(pack(b'>II', 501, 12))
|
||||||
exth.write(ids)
|
exth.write(ids)
|
||||||
@@ -145,7 +140,8 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
exth.write(datestr)
|
exth.write(datestr)
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
if is_periodical:
|
if is_periodical:
|
||||||
exth.write(pack(b'>II', EXTH_CODES['lastupdatetime'], len(datestr) + 8))
|
exth.write(pack(b'>II', EXTH_CODES['lastupdatetime'],
|
||||||
|
len(datestr) + 8))
|
||||||
exth.write(datestr)
|
exth.write(datestr)
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
@@ -154,10 +150,10 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
vals = {204: mv, 205: 2, 206: 9, 207: 0}
|
vals = {204: mv, 205: 2, 206: 9, 207: 0}
|
||||||
elif is_periodical:
|
elif is_periodical:
|
||||||
# Pretend to be amazon's super secret periodical generator
|
# Pretend to be amazon's super secret periodical generator
|
||||||
vals = {204:201, 205:2, 206:0, 207:101}
|
vals = {204: 201, 205: 2, 206: 0, 207: 101}
|
||||||
else:
|
else:
|
||||||
# Pretend to be kindlegen 1.2
|
# Pretend to be kindlegen 1.2
|
||||||
vals = {204:201, 205:1, 206:2, 207:33307}
|
vals = {204: 201, 205: 1, 206: 2, 207: 33307}
|
||||||
for code, val in vals.items():
|
for code, val in vals.items():
|
||||||
exth.write(pack(b'>III', code, 12, val))
|
exth.write(pack(b'>III', code, 12, val))
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
@@ -168,14 +164,17 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
|
|
||||||
if cover_offset is not None:
|
if cover_offset is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['coveroffset'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['coveroffset'], 12,
|
||||||
cover_offset))
|
cover_offset))
|
||||||
exth.write(pack(b'>III', EXTH_CODES['hasfakecover'], 12, 0))
|
exth.write(pack(b'>III', EXTH_CODES['hasfakecover'], 12, 0))
|
||||||
nrecs += 2
|
nrecs += 2
|
||||||
if thumbnail_offset is not None:
|
if thumbnail_offset is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['thumboffset'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['thumboffset'], 12,
|
||||||
thumbnail_offset))
|
thumbnail_offset))
|
||||||
thumbnail_uri_str = ('kindle:embed:%s' %(to_base(thumbnail_offset, base=32, min_num_digits=4))).encode('utf-8')
|
thumbnail_uri_str = ('kindle:embed:%s' %
|
||||||
exth.write(pack(b'>II', EXTH_CODES['kf8_thumbnail_uri'], len(thumbnail_uri_str) + 8))
|
to_base(thumbnail_offset, base=32,
|
||||||
|
min_num_digits=4)).encode('utf-8')
|
||||||
|
exth.write(pack(b'>II', EXTH_CODES['kf8_thumbnail_uri'],
|
||||||
|
len(thumbnail_uri_str) + 8))
|
||||||
exth.write(thumbnail_uri_str)
|
exth.write(thumbnail_uri_str)
|
||||||
nrecs += 2
|
nrecs += 2
|
||||||
|
|
||||||
@@ -186,34 +185,35 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
|||||||
start_offset = [start_offset]
|
start_offset = [start_offset]
|
||||||
for so in start_offset:
|
for so in start_offset:
|
||||||
if so is not None:
|
if so is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['startreading'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['startreading'], 12, so))
|
||||||
so))
|
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
if kf8_header_index is not None:
|
if kf8_header_index is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['kf8_header_index'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['kf8_header_index'], 12,
|
||||||
kf8_header_index))
|
kf8_header_index))
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
if num_of_resources is not None:
|
if num_of_resources is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['num_of_resources'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['num_of_resources'], 12,
|
||||||
num_of_resources))
|
num_of_resources))
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
if kf8_unknown_count is not None:
|
if kf8_unknown_count is not None:
|
||||||
exth.write(pack(b'>III', EXTH_CODES['kf8_unknown_count'], 12,
|
exth.write(pack(b'>III', EXTH_CODES['kf8_unknown_count'], 12,
|
||||||
kf8_unknown_count))
|
kf8_unknown_count))
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
if primary_writing_mode:
|
if primary_writing_mode:
|
||||||
pwm = primary_writing_mode.encode('utf-8')
|
pwm = primary_writing_mode.encode('utf-8')
|
||||||
exth.write(pack(b'>II', EXTH_CODES['primary_writing_mode'], len(pwm) + 8))
|
exth.write(pack(b'>II', EXTH_CODES['primary_writing_mode'],
|
||||||
|
len(pwm) + 8))
|
||||||
exth.write(pwm)
|
exth.write(pwm)
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
if page_progression_direction in {'rtl', 'ltr', 'default'}:
|
if page_progression_direction in {'rtl', 'ltr', 'default'}:
|
||||||
ppd = page_progression_direction.encode('ascii')
|
ppd = page_progression_direction.encode('ascii')
|
||||||
exth.write(pack(b'>II', EXTH_CODES['page_progression_direction'], len(ppd) + 8))
|
exth.write(pack(b'>II', EXTH_CODES['page_progression_direction'],
|
||||||
|
len(ppd) + 8))
|
||||||
exth.write(ppd)
|
exth.write(ppd)
|
||||||
nrecs += 1
|
nrecs += 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
||||||
"""
|
"""
|
||||||
Provides platform independent temporary files that persist even after
|
Provides platform independent temporary files that persist even after
|
||||||
being closed.
|
being closed.
|
||||||
"""
|
"""
|
||||||
import tempfile, os, atexit
|
import atexit
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from ebook_converter.constants_old import __version__, __appname__, \
|
from ebook_converter.constants_old import __version__, __appname__, \
|
||||||
filesystem_encoding, isosx
|
filesystem_encoding
|
||||||
|
|
||||||
|
|
||||||
def cleanup(path):
|
def cleanup(path):
|
||||||
@@ -15,7 +15,7 @@ def cleanup(path):
|
|||||||
import os as oss
|
import os as oss
|
||||||
if oss.path.exists(path):
|
if oss.path.exists(path):
|
||||||
oss.remove(path)
|
oss.remove(path)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ def remove_dir(x):
|
|||||||
try:
|
try:
|
||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(x, ignore_errors=True)
|
shutil.rmtree(x, ignore_errors=True)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ def determined_remove_dir(x):
|
|||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(x)
|
shutil.rmtree(x)
|
||||||
return
|
return
|
||||||
except:
|
except Exception:
|
||||||
import os # noqa
|
import os # noqa
|
||||||
if os.path.exists(x):
|
if os.path.exists(x):
|
||||||
# In case some other program has one of the temp files open.
|
# In case some other program has one of the temp files open.
|
||||||
@@ -47,7 +47,7 @@ def determined_remove_dir(x):
|
|||||||
try:
|
try:
|
||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(x, ignore_errors=True)
|
shutil.rmtree(x, ignore_errors=True)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -67,13 +67,15 @@ def osx_cache_dir():
|
|||||||
import ctypes
|
import ctypes
|
||||||
libc = ctypes.CDLL(None)
|
libc = ctypes.CDLL(None)
|
||||||
buf = ctypes.create_string_buffer(512)
|
buf = ctypes.create_string_buffer(512)
|
||||||
l = libc.confstr(65538, ctypes.byref(buf), len(buf)) # _CS_DARWIN_USER_CACHE_DIR = 65538
|
# _CS_DARWIN_USER_CACHE_DIR = 65538
|
||||||
if 0 < l < len(buf):
|
buflen = libc.confstr(65538, ctypes.byref(buf), len(buf))
|
||||||
|
if 0 < buflen < len(buf):
|
||||||
try:
|
try:
|
||||||
q = buf.value.decode('utf-8').rstrip('\0')
|
q = buf.value.decode('utf-8').rstrip('\0')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if q and os.path.isdir(q) and os.access(q, os.R_OK | os.W_OK | os.X_OK):
|
if q and os.path.isdir(q) and os.access(q, os.R_OK | os.W_OK |
|
||||||
|
os.X_OK):
|
||||||
_osx_cache_dir = q
|
_osx_cache_dir = q
|
||||||
return q
|
return q
|
||||||
|
|
||||||
@@ -98,20 +100,12 @@ def base_dir():
|
|||||||
else:
|
else:
|
||||||
base = os.environ.get('CALIBRE_TEMP_DIR', None)
|
base = os.environ.get('CALIBRE_TEMP_DIR', None)
|
||||||
prefix = app_prefix('tmp_')
|
prefix = app_prefix('tmp_')
|
||||||
if base is None:
|
|
||||||
if isosx:
|
|
||||||
# Use the cache dir rather than the temp dir for temp files as Apple
|
|
||||||
# thinks deleting unused temp files is a good idea. See note under
|
|
||||||
# _CS_DARWIN_USER_TEMP_DIR here
|
|
||||||
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/confstr.3.html
|
|
||||||
base = osx_cache_dir()
|
|
||||||
|
|
||||||
_base_dir = tempfile.mkdtemp(prefix=prefix, dir=base)
|
_base_dir = tempfile.mkdtemp(prefix=prefix, dir=base)
|
||||||
atexit.register(remove_dir, _base_dir)
|
atexit.register(remove_dir, _base_dir)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tempfile.gettempdir()
|
tempfile.gettempdir()
|
||||||
except:
|
except Exception:
|
||||||
# Widows temp vars set to a path not encodable in mbcs
|
# Widows temp vars set to a path not encodable in mbcs
|
||||||
# Use our temp dir
|
# Use our temp dir
|
||||||
tempfile.tempdir = _base_dir
|
tempfile.tempdir = _base_dir
|
||||||
@@ -144,10 +138,10 @@ def _make_dir(suffix, prefix, base):
|
|||||||
|
|
||||||
|
|
||||||
class PersistentTemporaryFile(object):
|
class PersistentTemporaryFile(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A file-like object that is a temporary file that is available even after being closed on
|
A file-like object that is a temporary file that is available even after
|
||||||
all platforms. It is automatically deleted on normal program termination.
|
being closed on all platforms. It is automatically deleted on normal
|
||||||
|
program termination.
|
||||||
"""
|
"""
|
||||||
_file = None
|
_file = None
|
||||||
|
|
||||||
@@ -177,15 +171,15 @@ class PersistentTemporaryFile(object):
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
try:
|
try:
|
||||||
self.close()
|
self.close()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def PersistentTemporaryDirectory(suffix='', prefix='', dir=None):
|
def PersistentTemporaryDirectory(suffix='', prefix='', dir=None):
|
||||||
'''
|
"""
|
||||||
Return the path to a newly created temporary directory that will
|
Return the path to a newly created temporary directory that will
|
||||||
be automatically deleted on application exit.
|
be automatically deleted on application exit.
|
||||||
'''
|
"""
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = base_dir()
|
dir = base_dir()
|
||||||
tdir = _make_dir(suffix, prefix, dir)
|
tdir = _make_dir(suffix, prefix, dir)
|
||||||
@@ -195,10 +189,9 @@ def PersistentTemporaryDirectory(suffix='', prefix='', dir=None):
|
|||||||
|
|
||||||
|
|
||||||
class TemporaryDirectory(object):
|
class TemporaryDirectory(object):
|
||||||
|
"""
|
||||||
'''
|
|
||||||
A temporary directory to be used in a with statement.
|
A temporary directory to be used in a with statement.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
def __init__(self, suffix='', prefix='', dir=None, keep=False):
|
def __init__(self, suffix='', prefix='', dir=None, keep=False):
|
||||||
self.suffix = suffix
|
self.suffix = suffix
|
||||||
@@ -227,7 +220,10 @@ class TemporaryFile(object):
|
|||||||
suffix = ''
|
suffix = ''
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = base_dir()
|
dir = base_dir()
|
||||||
self.prefix, self.suffix, self.dir, self.mode = prefix, suffix, dir, mode
|
self.mode = mode
|
||||||
|
self.dir = dir
|
||||||
|
self.suffix = suffix
|
||||||
|
self.prefix = prefix
|
||||||
self._file = None
|
self._file = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
@@ -244,7 +240,7 @@ class TemporaryFile(object):
|
|||||||
class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
|
class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
|
||||||
|
|
||||||
def __init__(self, max_size=0, suffix="", prefix="", dir=None, mode='w+b',
|
def __init__(self, max_size=0, suffix="", prefix="", dir=None, mode='w+b',
|
||||||
bufsize=-1):
|
bufsize=-1):
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
prefix = ''
|
prefix = ''
|
||||||
if suffix is None:
|
if suffix is None:
|
||||||
@@ -253,7 +249,8 @@ class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
|
|||||||
dir = base_dir()
|
dir = base_dir()
|
||||||
self._name = None
|
self._name = None
|
||||||
tempfile.SpooledTemporaryFile.__init__(self, max_size=max_size,
|
tempfile.SpooledTemporaryFile.__init__(self, max_size=max_size,
|
||||||
suffix=suffix, prefix=prefix, dir=dir, mode=mode)
|
suffix=suffix, prefix=prefix,
|
||||||
|
dir=dir, mode=mode)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ if not _run_once:
|
|||||||
#
|
#
|
||||||
# Convert command line arguments to unicode
|
# Convert command line arguments to unicode
|
||||||
enc = constants_old.preferred_encoding
|
enc = constants_old.preferred_encoding
|
||||||
if constants_old.isosx:
|
|
||||||
enc = 'utf-8'
|
|
||||||
for i in range(1, len(sys.argv)):
|
for i in range(1, len(sys.argv)):
|
||||||
if not isinstance(sys.argv[i], str):
|
if not isinstance(sys.argv[i], str):
|
||||||
sys.argv[i] = sys.argv[i].decode(enc, 'replace')
|
sys.argv[i] = sys.argv[i].decode(enc, 'replace')
|
||||||
@@ -62,13 +60,14 @@ if not _run_once:
|
|||||||
import string
|
import string
|
||||||
string
|
string
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, '') # set the locale to the user's default locale
|
# set the locale to the user's default locale
|
||||||
except:
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
except Exception:
|
||||||
dl = locale.getdefaultlocale()
|
dl = locale.getdefaultlocale()
|
||||||
try:
|
try:
|
||||||
if dl:
|
if dl:
|
||||||
locale.setlocale(locale.LC_ALL, dl[0])
|
locale.setlocale(locale.LC_ALL, dl[0])
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def connect_lambda(bound_signal, self, func, **kw):
|
def connect_lambda(bound_signal, self, func, **kw):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from ebook_converter.constants_old import isosx, plugins, preferred_encoding
|
from ebook_converter.constants_old import preferred_encoding
|
||||||
from ebook_converter.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
from ebook_converter.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
||||||
from ebook_converter.utils.localization import lcdata
|
from ebook_converter.utils.localization import lcdata
|
||||||
|
|
||||||
@@ -24,12 +24,13 @@ try:
|
|||||||
|
|
||||||
import locale
|
import locale
|
||||||
raw = locale.nl_langinfo(locale.D_FMT)
|
raw = locale.nl_langinfo(locale.D_FMT)
|
||||||
parse_date_day_first = first_index(raw, ('%d', '%a', '%A')) < first_index(raw, ('%m', '%b', '%B'))
|
parse_date_day_first = (first_index(raw, ('%d', '%a', '%A')) <
|
||||||
|
first_index(raw, ('%m', '%b', '%B')))
|
||||||
del raw, first_index
|
del raw, first_index
|
||||||
except:
|
except Exception:
|
||||||
parse_date_day_first = False
|
parse_date_day_first = False
|
||||||
|
|
||||||
DEFAULT_DATE = datetime.datetime(2000,1,1, tzinfo=utc_tz)
|
DEFAULT_DATE = datetime.datetime(2000, 1, 1, tzinfo=utc_tz)
|
||||||
EPOCH = datetime.datetime(1970, 1, 1, tzinfo=_utc_tz)
|
EPOCH = datetime.datetime(1970, 1, 1, tzinfo=_utc_tz)
|
||||||
|
|
||||||
|
|
||||||
@@ -61,9 +62,9 @@ def iso_pat():
|
|||||||
|
|
||||||
|
|
||||||
def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
||||||
'''
|
"""
|
||||||
Parse a date/time string into a timezone aware datetime object. The timezone
|
Parse a date/time string into a timezone aware datetime object. The
|
||||||
is always either UTC or the local timezone.
|
timezone is always either UTC or the local timezone.
|
||||||
|
|
||||||
:param assume_utc: If True and date_string does not specify a timezone,
|
:param assume_utc: If True and date_string does not specify a timezone,
|
||||||
assume UTC, otherwise assume local timezone.
|
assume UTC, otherwise assume local timezone.
|
||||||
@@ -72,7 +73,7 @@ def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
|||||||
|
|
||||||
:param default: Missing fields are filled in from default. If None, the
|
:param default: Missing fields are filled in from default. If None, the
|
||||||
current month and year are used.
|
current month and year are used.
|
||||||
'''
|
"""
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
if not date_string:
|
if not date_string:
|
||||||
return UNDEFINED_DATE
|
return UNDEFINED_DATE
|
||||||
@@ -81,8 +82,9 @@ def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
|||||||
if default is None:
|
if default is None:
|
||||||
func = (datetime.datetime.utcnow if assume_utc
|
func = (datetime.datetime.utcnow if assume_utc
|
||||||
else datetime.datetime.now)
|
else datetime.datetime.now)
|
||||||
default = func().replace(day=15, hour=0, minute=0, second=0, microsecond=0,
|
default = func().replace(day=15, hour=0, minute=0, second=0,
|
||||||
tzinfo=_utc_tz if assume_utc else _local_tz)
|
microsecond=0,
|
||||||
|
tzinfo=_utc_tz if assume_utc else _local_tz)
|
||||||
if iso_pat().match(date_string) is not None:
|
if iso_pat().match(date_string) is not None:
|
||||||
dt = parse(date_string, default=default)
|
dt = parse(date_string, default=default)
|
||||||
else:
|
else:
|
||||||
@@ -109,8 +111,9 @@ def parse_only_date(raw, assume_utc=True, as_utc=True):
|
|||||||
'''
|
'''
|
||||||
f = utcnow if assume_utc else now
|
f = utcnow if assume_utc else now
|
||||||
default = f().replace(hour=0, minute=0, second=0, microsecond=0,
|
default = f().replace(hour=0, minute=0, second=0, microsecond=0,
|
||||||
day=15)
|
day=15)
|
||||||
return fix_only_date(parse_date(raw, default=default, assume_utc=assume_utc, as_utc=as_utc))
|
return fix_only_date(parse_date(raw, default=default,
|
||||||
|
assume_utc=assume_utc, as_utc=as_utc))
|
||||||
|
|
||||||
|
|
||||||
def strptime(val, fmt, assume_utc=False, as_utc=True):
|
def strptime(val, fmt, assume_utc=False, as_utc=True):
|
||||||
@@ -127,7 +130,8 @@ def dt_factory(time_t, assume_utc=False, as_utc=True):
|
|||||||
return dt.astimezone(_utc_tz if as_utc else _local_tz)
|
return dt.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
|
|
||||||
|
|
||||||
safeyear = lambda x: min(max(x, datetime.MINYEAR), datetime.MAXYEAR)
|
def _safeyear(year):
|
||||||
|
return min(max(year, datetime.MINYEAR), datetime.MAXYEAR)
|
||||||
|
|
||||||
|
|
||||||
def qt_to_dt(qdate_or_qdatetime, as_utc=True):
|
def qt_to_dt(qdate_or_qdatetime, as_utc=True):
|
||||||
@@ -137,17 +141,23 @@ def qt_to_dt(qdate_or_qdatetime, as_utc=True):
|
|||||||
o = o.toUTC()
|
o = o.toUTC()
|
||||||
d, t = o.date(), o.time()
|
d, t = o.date(), o.time()
|
||||||
try:
|
try:
|
||||||
ans = datetime.datetime(safeyear(d.year()), d.month(), d.day(), t.hour(), t.minute(), t.second(), t.msec()*1000, utc_tz)
|
ans = datetime.datetime(_safeyear(d.year()), d.month(), d.day(),
|
||||||
|
t.hour(), t.minute(), t.second(),
|
||||||
|
t.msec()*1000, utc_tz)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
ans = datetime.datetime(safeyear(d.year()), d.month(), 1, t.hour(), t.minute(), t.second(), t.msec()*1000, utc_tz)
|
ans = datetime.datetime(_safeyear(d.year()), d.month(), 1,
|
||||||
|
t.hour(), t.minute(), t.second(),
|
||||||
|
t.msec()*1000, utc_tz)
|
||||||
if not as_utc:
|
if not as_utc:
|
||||||
ans = ans.astimezone(local_tz)
|
ans = ans.astimezone(local_tz)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dt = datetime.datetime(safeyear(o.year()), o.month(), o.day()).replace(tzinfo=_local_tz)
|
dt = datetime.datetime(_safeyear(o.year()), o.month(),
|
||||||
|
o.day()).replace(tzinfo=_local_tz)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
dt = datetime.datetime(safeyear(o.year()), o.month(), 1).replace(tzinfo=_local_tz)
|
dt = datetime.datetime(_safeyear(o.year()), o.month(),
|
||||||
|
1).replace(tzinfo=_local_tz)
|
||||||
return dt.astimezone(_utc_tz if as_utc else _local_tz)
|
return dt.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
|
|
||||||
|
|
||||||
@@ -168,7 +178,7 @@ def isoformat(date_time, assume_utc=False, as_utc=True, sep='T'):
|
|||||||
return str(date_time.isoformat())
|
return str(date_time.isoformat())
|
||||||
if date_time.tzinfo is None:
|
if date_time.tzinfo is None:
|
||||||
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
return str(date_time.isoformat(sep))
|
return str(date_time.isoformat(sep))
|
||||||
|
|
||||||
@@ -210,7 +220,7 @@ def w3cdtf(date_time, assume_utc=False):
|
|||||||
if hasattr(date_time, 'tzinfo'):
|
if hasattr(date_time, 'tzinfo'):
|
||||||
if date_time.tzinfo is None:
|
if date_time.tzinfo is None:
|
||||||
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
return str(date_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
return str(date_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||||
|
|
||||||
@@ -220,7 +230,7 @@ def as_local_time(date_time, assume_utc=True):
|
|||||||
return date_time
|
return date_time
|
||||||
if date_time.tzinfo is None:
|
if date_time.tzinfo is None:
|
||||||
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
return date_time.astimezone(_local_tz)
|
return date_time.astimezone(_local_tz)
|
||||||
|
|
||||||
|
|
||||||
@@ -235,7 +245,7 @@ def as_utc(date_time, assume_utc=True):
|
|||||||
return date_time
|
return date_time
|
||||||
if date_time.tzinfo is None:
|
if date_time.tzinfo is None:
|
||||||
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
return date_time.astimezone(_utc_tz)
|
return date_time.astimezone(_utc_tz)
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +259,8 @@ def utcnow():
|
|||||||
|
|
||||||
def utcfromtimestamp(stamp):
|
def utcfromtimestamp(stamp):
|
||||||
try:
|
try:
|
||||||
return datetime.datetime.utcfromtimestamp(stamp).replace(tzinfo=_utc_tz)
|
return (datetime.datetime.utcfromtimestamp(stamp)
|
||||||
|
.replace(tzinfo=_utc_tz))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Raised if stamp is out of range for the platforms gmtime function
|
# Raised if stamp is out of range for the platforms gmtime function
|
||||||
# For example, this happens with negative values on windows
|
# For example, this happens with negative values on windows
|
||||||
@@ -269,27 +280,27 @@ def timestampfromdt(dt, assume_utc=True):
|
|||||||
|
|
||||||
|
|
||||||
def fd_format_hour(dt, ampm, hr):
|
def fd_format_hour(dt, ampm, hr):
|
||||||
l = len(hr)
|
length = len(hr)
|
||||||
h = dt.hour
|
h = dt.hour
|
||||||
if ampm:
|
if ampm:
|
||||||
h = h%12
|
h = h % 12
|
||||||
if l == 1:
|
if length == 1:
|
||||||
return '%d'%h
|
return '%d' % h
|
||||||
return '%02d'%h
|
return '%02d' % h
|
||||||
|
|
||||||
|
|
||||||
def fd_format_minute(dt, ampm, min):
|
def fd_format_minute(dt, ampm, min):
|
||||||
l = len(min)
|
length = len(min)
|
||||||
if l == 1:
|
if length == 1:
|
||||||
return '%d'%dt.minute
|
return '%d' % dt.minute
|
||||||
return '%02d'%dt.minute
|
return '%02d' % dt.minute
|
||||||
|
|
||||||
|
|
||||||
def fd_format_second(dt, ampm, sec):
|
def fd_format_second(dt, ampm, sec):
|
||||||
l = len(sec)
|
length = len(sec)
|
||||||
if l == 1:
|
if length == 1:
|
||||||
return '%d'%dt.second
|
return '%d' % dt.second
|
||||||
return '%02d'%dt.second
|
return '%02d' % dt.second
|
||||||
|
|
||||||
|
|
||||||
def fd_format_ampm(dt, ampm, ap):
|
def fd_format_ampm(dt, ampm, ap):
|
||||||
@@ -300,27 +311,27 @@ def fd_format_ampm(dt, ampm, ap):
|
|||||||
|
|
||||||
|
|
||||||
def fd_format_day(dt, ampm, dy):
|
def fd_format_day(dt, ampm, dy):
|
||||||
l = len(dy)
|
length = len(dy)
|
||||||
if l == 1:
|
if length == 1:
|
||||||
return '%d'%dt.day
|
return '%d' % dt.day
|
||||||
if l == 2:
|
if length == 2:
|
||||||
return '%02d'%dt.day
|
return '%02d' % dt.day
|
||||||
return lcdata['abday' if l == 3 else 'day'][(dt.weekday() + 1) % 7]
|
return lcdata['abday' if length == 3 else 'day'][(dt.weekday() + 1) % 7]
|
||||||
|
|
||||||
|
|
||||||
def fd_format_month(dt, ampm, mo):
|
def fd_format_month(dt, ampm, mo):
|
||||||
l = len(mo)
|
length = len(mo)
|
||||||
if l == 1:
|
if length == 1:
|
||||||
return '%d'%dt.month
|
return '%d' % dt.month
|
||||||
if l == 2:
|
if length == 2:
|
||||||
return '%02d'%dt.month
|
return '%02d' % dt.month
|
||||||
return lcdata['abmon' if l == 3 else 'mon'][dt.month - 1]
|
return lcdata['abmon' if length == 3 else 'mon'][dt.month - 1]
|
||||||
|
|
||||||
|
|
||||||
def fd_format_year(dt, ampm, yr):
|
def fd_format_year(dt, ampm, yr):
|
||||||
if len(yr) == 2:
|
if len(yr) == 2:
|
||||||
return '%02d'%(dt.year % 100)
|
return '%02d' % (dt.year % 100)
|
||||||
return '%04d'%dt.year
|
return '%04d' % dt.year
|
||||||
|
|
||||||
|
|
||||||
fd_function_index = {
|
fd_function_index = {
|
||||||
@@ -343,7 +354,10 @@ def fd_repl_func(dt, ampm, mo):
|
|||||||
|
|
||||||
|
|
||||||
def format_date(dt, format, assume_utc=False, as_utc=False):
|
def format_date(dt, format, assume_utc=False, as_utc=False):
|
||||||
''' Return a date formatted as a string using a subset of Qt's formatting codes '''
|
"""
|
||||||
|
Return a date formatted as a string using a subset of Qt's formatting
|
||||||
|
codes
|
||||||
|
"""
|
||||||
if not format:
|
if not format:
|
||||||
format = 'dd MMM yyyy'
|
format = 'dd MMM yyyy'
|
||||||
|
|
||||||
@@ -353,7 +367,7 @@ def format_date(dt, format, assume_utc=False, as_utc=False):
|
|||||||
if hasattr(dt, 'tzinfo'):
|
if hasattr(dt, 'tzinfo'):
|
||||||
if dt.tzinfo is None:
|
if dt.tzinfo is None:
|
||||||
dt = dt.replace(tzinfo=_utc_tz if assume_utc else
|
dt = dt.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
dt = dt.astimezone(_utc_tz if as_utc else _local_tz)
|
dt = dt.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
|
|
||||||
if format == 'iso':
|
if format == 'iso':
|
||||||
@@ -435,14 +449,16 @@ def clean_date_for_sort(dt, fmt=None):
|
|||||||
if fmt == 'iso':
|
if fmt == 'iso':
|
||||||
fmt = 'yyMdhms'
|
fmt = 'yyMdhms'
|
||||||
|
|
||||||
tt = {'year':UNDEFINED_DATE.year, 'mon':UNDEFINED_DATE.month,
|
tt = {'year': UNDEFINED_DATE.year, 'mon': UNDEFINED_DATE.month,
|
||||||
'day':UNDEFINED_DATE.day, 'hour':UNDEFINED_DATE.hour,
|
'day': UNDEFINED_DATE.day, 'hour': UNDEFINED_DATE.hour,
|
||||||
'min':UNDEFINED_DATE.minute, 'sec':UNDEFINED_DATE.second}
|
'min': UNDEFINED_DATE.minute, 'sec': UNDEFINED_DATE.second}
|
||||||
|
|
||||||
repl_func = functools.partial(cd_repl_func, tt, dt)
|
repl_func = functools.partial(cd_repl_func, tt, dt)
|
||||||
re.sub('(s{1,2})|(m{1,2})|(h{1,2})|(d{1,4}|M{1,4}|(?:yyyy|yy))', repl_func, fmt)
|
re.sub('(s{1,2})|(m{1,2})|(h{1,2})|(d{1,4}|M{1,4}|(?:yyyy|yy))',
|
||||||
return dt.replace(year=tt['year'], month=tt['mon'], day=tt['day'], hour=tt['hour'],
|
repl_func, fmt)
|
||||||
minute=tt['min'], second=tt['sec'], microsecond=0)
|
return dt.replace(year=tt['year'], month=tt['mon'], day=tt['day'],
|
||||||
|
hour=tt['hour'], minute=tt['min'], second=tt['sec'],
|
||||||
|
microsecond=0)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ from collections import defaultdict
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from ebook_converter import walk
|
from ebook_converter import walk
|
||||||
from ebook_converter.constants_old import isosx
|
from ebook_converter.constants_old import DEBUG
|
||||||
from ebook_converter.constants_old import plugins, DEBUG
|
|
||||||
from ebook_converter.constants_old import filesystem_encoding
|
from ebook_converter.constants_old import filesystem_encoding
|
||||||
from ebook_converter.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
from ebook_converter.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||||
|
|
||||||
@@ -90,15 +89,6 @@ def fc_list():
|
|||||||
|
|
||||||
|
|
||||||
def font_dirs():
|
def font_dirs():
|
||||||
if isosx:
|
|
||||||
return [
|
|
||||||
'/Library/Fonts',
|
|
||||||
'/System/Library/Fonts',
|
|
||||||
'/usr/share/fonts',
|
|
||||||
'/var/root/Library/Fonts',
|
|
||||||
os.path.expanduser('~/.fonts'),
|
|
||||||
os.path.expanduser('~/Library/Fonts'),
|
|
||||||
]
|
|
||||||
return fc_list()
|
return fc_list()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ del err
|
|||||||
|
|
||||||
|
|
||||||
def collator():
|
def collator():
|
||||||
__import__('pdb').set_trace()
|
|
||||||
global _collator, _locale
|
global _collator, _locale
|
||||||
if _collator is None:
|
if _collator is None:
|
||||||
if _locale is None:
|
if _locale is None:
|
||||||
@@ -34,7 +33,6 @@ def collator():
|
|||||||
|
|
||||||
|
|
||||||
def primary_collator():
|
def primary_collator():
|
||||||
__import__('pdb').set_trace()
|
|
||||||
'Ignores case differences and accented characters'
|
'Ignores case differences and accented characters'
|
||||||
global _primary_collator
|
global _primary_collator
|
||||||
if _primary_collator is None:
|
if _primary_collator is None:
|
||||||
@@ -44,7 +42,6 @@ def primary_collator():
|
|||||||
|
|
||||||
|
|
||||||
def sort_collator():
|
def sort_collator():
|
||||||
__import__('pdb').set_trace()
|
|
||||||
'Ignores case differences and recognizes numbers in strings (if the tweak is set)'
|
'Ignores case differences and recognizes numbers in strings (if the tweak is set)'
|
||||||
global _sort_collator
|
global _sort_collator
|
||||||
if _sort_collator is None:
|
if _sort_collator is None:
|
||||||
@@ -55,7 +52,6 @@ def sort_collator():
|
|||||||
|
|
||||||
|
|
||||||
def numeric_collator():
|
def numeric_collator():
|
||||||
__import__('pdb').set_trace()
|
|
||||||
'Uses natural sorting for numbers inside strings so something2 will sort before something10'
|
'Uses natural sorting for numbers inside strings so something2 will sort before something10'
|
||||||
global _numeric_collator
|
global _numeric_collator
|
||||||
if _numeric_collator is None:
|
if _numeric_collator is None:
|
||||||
@@ -66,7 +62,6 @@ def numeric_collator():
|
|||||||
|
|
||||||
|
|
||||||
def case_sensitive_collator():
|
def case_sensitive_collator():
|
||||||
__import__('pdb').set_trace()
|
|
||||||
'Always sorts upper case letter before lower case'
|
'Always sorts upper case letter before lower case'
|
||||||
global _case_sensitive_collator
|
global _case_sensitive_collator
|
||||||
if _case_sensitive_collator is None:
|
if _case_sensitive_collator is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user