mirror of
https://github.com/gryf/ebook-converter.git
synced 2025-12-18 13:10:17 +01:00
More cleanups. Removing version function.
This commit is contained in:
@@ -19,6 +19,8 @@ from ebook_converter.constants_old import islinux, isfrozen, \
|
|||||||
config_dir
|
config_dir
|
||||||
from ebook_converter.startup import winutil, winutilerror
|
from ebook_converter.startup import winutil, winutilerror
|
||||||
from ebook_converter.utils.icu import safe_chr
|
from ebook_converter.utils.icu import safe_chr
|
||||||
|
from ebook_converter.utils.terminal import Detect
|
||||||
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# Prevent pyflakes from complaining
|
# Prevent pyflakes from complaining
|
||||||
@@ -98,63 +100,32 @@ def prints(*args, **kwargs):
|
|||||||
|
|
||||||
Returns the number of bytes written.
|
Returns the number of bytes written.
|
||||||
"""
|
"""
|
||||||
file = kwargs.get('file', sys.stdout)
|
fobj = kwargs.get('file', sys.stdout)
|
||||||
file = getattr(file, 'buffer', file)
|
|
||||||
enc = ('utf-8' if os.getenv('CALIBRE_WORKER')
|
enc = ('utf-8' if os.getenv('CALIBRE_WORKER')
|
||||||
else constants_old.preferred_encoding)
|
else constants_old.preferred_encoding)
|
||||||
sep = kwargs.get('sep', ' ')
|
sep = kwargs.get('sep', ' ')
|
||||||
if not isinstance(sep, bytes):
|
if isinstance(sep, bytes):
|
||||||
sep = sep.encode(enc)
|
sep = sep.decode(enc)
|
||||||
end = kwargs.get('end', '\n')
|
end = kwargs.get('end', '\n')
|
||||||
if not isinstance(end, bytes):
|
if isinstance(end, bytes):
|
||||||
end = end.encode(enc)
|
end = end.decode(enc)
|
||||||
safe_encode = kwargs.get('safe_encode', False)
|
|
||||||
count = 0
|
count = 0
|
||||||
for i, arg in enumerate(args):
|
|
||||||
if isinstance(arg, str):
|
|
||||||
if constants_old.iswindows:
|
|
||||||
from ebook_converter.utils.terminal import Detect
|
|
||||||
cs = Detect(file)
|
|
||||||
if cs.is_console:
|
|
||||||
cs.write_unicode_text(arg)
|
|
||||||
count += len(arg)
|
|
||||||
if i != len(args)-1:
|
|
||||||
file.write(sep)
|
|
||||||
count += len(sep)
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
arg = arg.encode(enc)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
try:
|
|
||||||
arg = arg.encode('utf-8')
|
|
||||||
except Exception:
|
|
||||||
if not safe_encode:
|
|
||||||
raise
|
|
||||||
arg = repr(arg)
|
|
||||||
if not isinstance(arg, bytes):
|
|
||||||
if isinstance(arg, str):
|
|
||||||
try:
|
|
||||||
arg = arg.encode(enc)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
try:
|
|
||||||
arg = arg.encode('utf-8')
|
|
||||||
except Exception:
|
|
||||||
if not safe_encode:
|
|
||||||
raise
|
|
||||||
arg = repr(arg)
|
|
||||||
|
|
||||||
|
for i, arg in enumerate(args):
|
||||||
|
if isinstance(arg, bytes):
|
||||||
|
arg = arg.decode(enc)
|
||||||
|
arg = repr(arg)
|
||||||
try:
|
try:
|
||||||
file.write(arg)
|
fobj.write(arg)
|
||||||
count += len(arg)
|
count += len(arg)
|
||||||
except Exception:
|
except Exception:
|
||||||
from polyglot import reprlib
|
arg = repr(arg)
|
||||||
arg = reprlib.repr(arg)
|
fobj.write(arg)
|
||||||
file.write(arg)
|
|
||||||
count += len(arg)
|
count += len(arg)
|
||||||
if i != len(args)-1:
|
if i != len(args)-1:
|
||||||
file.write(sep)
|
fobj.write(sep)
|
||||||
count += len(sep)
|
count += len(sep)
|
||||||
file.write(end)
|
fobj.write(end)
|
||||||
count += len(end)
|
count += len(end)
|
||||||
return count
|
return count
|
||||||
|
|
||||||
@@ -316,7 +287,7 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
|
|||||||
return check(html5_entities[ent])
|
return check(html5_entities[ent])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
from polyglot.html_entities import name2codepoint
|
from ebook_converter.polyglot.html_entities import name2codepoint
|
||||||
try:
|
try:
|
||||||
return check(my_unichr(name2codepoint[ent]))
|
return check(my_unichr(name2codepoint[ent]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
VERSION = '0.1.0'
|
||||||
CALIBRE_NS = 'http://calibre.kovidgoyal.net/2009/metadata'
|
CALIBRE_NS = 'http://calibre.kovidgoyal.net/2009/metadata'
|
||||||
DC09_NS = 'http://purl.org/metadata/dublin_core'
|
DC09_NS = 'http://purl.org/metadata/dublin_core'
|
||||||
DC10_NS = 'http://purl.org/dc/elements/1.0/'
|
DC10_NS = 'http://purl.org/dc/elements/1.0/'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import locale
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import environ_item, as_unicode
|
from ebook_converter.polyglot.builtins import environ_item
|
||||||
|
|
||||||
__appname__ = 'calibre'
|
__appname__ = 'calibre'
|
||||||
numeric_version = (4, 12, 0)
|
numeric_version = (4, 12, 0)
|
||||||
@@ -176,12 +176,8 @@ class Plugins(collections.Mapping):
|
|||||||
p = importlib.import_module(name)
|
p = importlib.import_module(name)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
p = None
|
p = None
|
||||||
try:
|
plugin_err = str(err)
|
||||||
plugin_err = str(err)
|
|
||||||
except Exception:
|
|
||||||
plugin_err = as_unicode(err, encoding=preferred_encoding, errors='replace')
|
|
||||||
self._plugins[name] = p, plugin_err
|
self._plugins[name] = p, plugin_err
|
||||||
# sys.path.remove(plugins_loc)
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.plugins)
|
return iter(self.plugins)
|
||||||
@@ -199,9 +195,7 @@ class Plugins(collections.Mapping):
|
|||||||
return self._plugins[name]
|
return self._plugins[name]
|
||||||
|
|
||||||
|
|
||||||
plugins = None
|
plugins = Plugins()
|
||||||
if plugins is None:
|
|
||||||
plugins = Plugins()
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# config_dir {{{
|
# config_dir {{{
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
|||||||
from ebook_converter.utils.date import parse_date
|
from ebook_converter.utils.date import parse_date
|
||||||
from ebook_converter.utils.zipfile import ZipFile
|
from ebook_converter.utils.zipfile import ZipFile
|
||||||
from ebook_converter import extract, walk
|
from ebook_converter import extract, walk
|
||||||
from ebook_converter.constants_old import __version__, filesystem_encoding
|
from ebook_converter import constants
|
||||||
|
from ebook_converter.constants_old import filesystem_encoding
|
||||||
|
|
||||||
|
|
||||||
DEBUG_README=b'''
|
DEBUG_README=b'''
|
||||||
@@ -956,7 +957,7 @@ OptionRecommendation(name='search_replace',
|
|||||||
if self.opts.verbose > 1:
|
if self.opts.verbose > 1:
|
||||||
self.log.debug('Resolved conversion options')
|
self.log.debug('Resolved conversion options')
|
||||||
try:
|
try:
|
||||||
self.log.debug('ebook_converter version:', __version__)
|
self.log.debug('ebook_converter version:', constants.VERSION)
|
||||||
odict = dict(self.opts.__dict__)
|
odict = dict(self.opts.__dict__)
|
||||||
for x in ('username', 'password'):
|
for x in ('username', 'password'):
|
||||||
odict.pop(x, None)
|
odict.pop(x, None)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import optparse
|
|||||||
import os
|
import os
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from ebook_converter import constants
|
||||||
from ebook_converter import constants_old
|
from ebook_converter import constants_old
|
||||||
from ebook_converter.utils.config_base import (
|
from ebook_converter.utils.config_base import (
|
||||||
Config, ConfigInterface, ConfigProxy, Option, OptionSet, OptionValues,
|
Config, ConfigInterface, ConfigProxy, Option, OptionSet, OptionValues,
|
||||||
@@ -92,7 +93,7 @@ class OptionParser(optparse.OptionParser):
|
|||||||
else '/some path/with spaces')
|
else '/some path/with spaces')
|
||||||
if version is None:
|
if version is None:
|
||||||
version = '%%prog (%s %s)' % (constants_old.__appname__,
|
version = '%%prog (%s %s)' % (constants_old.__appname__,
|
||||||
constants_old.get_version())
|
constants.VERSION)
|
||||||
optparse.OptionParser.__init__(self, usage=usage, version=version, epilog=epilog,
|
optparse.OptionParser.__init__(self, usage=usage, version=version, epilog=epilog,
|
||||||
formatter=CustomHelpFormatter(),
|
formatter=CustomHelpFormatter(),
|
||||||
conflict_handler=conflict_handler, **kwds)
|
conflict_handler=conflict_handler, **kwds)
|
||||||
|
|||||||
Reference in New Issue
Block a user