mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-27 22:03:32 +01:00
Removed patheq function
This commit is contained in:
@@ -45,14 +45,6 @@ def to_unicode(raw, encoding='utf-8', errors='strict'):
|
|||||||
return raw.decode(encoding, errors)
|
return raw.decode(encoding, errors)
|
||||||
|
|
||||||
|
|
||||||
def patheq(p1, p2):
|
|
||||||
p = os.path
|
|
||||||
d = lambda x : p.normcase(p.normpath(p.realpath(p.normpath(x))))
|
|
||||||
if not p1 or not p2:
|
|
||||||
return False
|
|
||||||
return d(p1) == d(p2)
|
|
||||||
|
|
||||||
|
|
||||||
def unicode_path(path, abs=False):
|
def unicode_path(path, abs=False):
|
||||||
if isinstance(path, bytes):
|
if isinstance(path, bytes):
|
||||||
path = path.decode(filesystem_encoding)
|
path = path.decode(filesystem_encoding)
|
||||||
@@ -61,15 +53,6 @@ def unicode_path(path, abs=False):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def osx_version():
|
|
||||||
if isosx:
|
|
||||||
import platform
|
|
||||||
src = platform.mac_ver()[0]
|
|
||||||
m = re.match(r'(\d+)\.(\d+)\.(\d+)', src)
|
|
||||||
if m:
|
|
||||||
return int(m.group(1)), int(m.group(2)), int(m.group(3))
|
|
||||||
|
|
||||||
|
|
||||||
def confirm_config_name(name):
|
def confirm_config_name(name):
|
||||||
return name + '_again'
|
return name + '_again'
|
||||||
|
|
||||||
@@ -107,21 +90,21 @@ def sanitize_file_name(name, substitute='_'):
|
|||||||
|
|
||||||
|
|
||||||
def prints(*args, **kwargs):
|
def prints(*args, **kwargs):
|
||||||
'''
|
"""
|
||||||
Print unicode arguments safely by encoding them to preferred_encoding
|
Print unicode arguments safely by encoding them to preferred_encoding
|
||||||
Has the same signature as the print function from Python 3, except for the
|
Has the same signature as the print function from Python 3, except for the
|
||||||
additional keyword argument safe_encode, which if set to True will cause the
|
additional keyword argument safe_encode, which if set to True will cause the
|
||||||
function to use repr when encoding fails.
|
function to use repr when encoding fails.
|
||||||
|
|
||||||
Returns the number of bytes written.
|
Returns the number of bytes written.
|
||||||
'''
|
"""
|
||||||
file = kwargs.get('file', sys.stdout)
|
file = kwargs.get('file', sys.stdout)
|
||||||
file = getattr(file, 'buffer', file)
|
file = getattr(file, 'buffer', file)
|
||||||
enc = 'utf-8' if os.getenv('CALIBRE_WORKER') else preferred_encoding
|
enc = 'utf-8' if os.getenv('CALIBRE_WORKER') else preferred_encoding
|
||||||
sep = kwargs.get('sep', ' ')
|
sep = kwargs.get('sep', ' ')
|
||||||
if not isinstance(sep, bytes):
|
if not isinstance(sep, bytes):
|
||||||
sep = sep.encode(enc)
|
sep = sep.encode(enc)
|
||||||
end = kwargs.get('end', '\n')
|
end = kwargs.get('end', '\n')
|
||||||
if not isinstance(end, bytes):
|
if not isinstance(end, bytes):
|
||||||
end = end.encode(enc)
|
end = end.encode(enc)
|
||||||
safe_encode = kwargs.get('safe_encode', False)
|
safe_encode = kwargs.get('safe_encode', False)
|
||||||
@@ -175,10 +158,6 @@ def prints(*args, **kwargs):
|
|||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
class CommandLineError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def setup_cli_handlers(logger, level):
|
def setup_cli_handlers(logger, level):
|
||||||
import logging
|
import logging
|
||||||
if os.getenv('CALIBRE_WORKER') and logger.handlers:
|
if os.getenv('CALIBRE_WORKER') and logger.handlers:
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import sys
|
|||||||
from ebook_converter.utils.config import OptionParser
|
from ebook_converter.utils.config import OptionParser
|
||||||
from ebook_converter.utils.logging import Log
|
from ebook_converter.utils.logging import Log
|
||||||
from ebook_converter.customize.conversion import OptionRecommendation
|
from ebook_converter.customize.conversion import OptionRecommendation
|
||||||
from ebook_converter import patheq
|
|
||||||
from ebook_converter import init_mimetypes
|
from ebook_converter import init_mimetypes
|
||||||
from ebook_converter.utils.localization import localize_user_manual_link
|
|
||||||
|
|
||||||
|
|
||||||
USAGE = '%prog ' + '''\
|
USAGE = '%prog ' + '''\
|
||||||
@@ -42,12 +40,11 @@ For full documentation of the conversion system see
|
|||||||
https://manual.calibre-ebook.com/conversion.html
|
https://manual.calibre-ebook.com/conversion.html
|
||||||
'''
|
'''
|
||||||
|
|
||||||
HEURISTIC_OPTIONS = ['markup_chapter_headings',
|
HEURISTIC_OPTIONS = ['markup_chapter_headings', 'italicize_common_cases',
|
||||||
'italicize_common_cases', 'fix_indents',
|
'fix_indents', 'html_unwrap_factor', 'unwrap_lines',
|
||||||
'html_unwrap_factor', 'unwrap_lines',
|
'delete_blank_paragraphs', 'format_scene_breaks',
|
||||||
'delete_blank_paragraphs', 'format_scene_breaks',
|
'dehyphenate', 'renumber_headings',
|
||||||
'dehyphenate', 'renumber_headings',
|
'replace_scene_breaks']
|
||||||
'replace_scene_breaks']
|
|
||||||
|
|
||||||
DEFAULT_TRUE_OPTIONS = HEURISTIC_OPTIONS + ['remove_fake_margins']
|
DEFAULT_TRUE_OPTIONS = HEURISTIC_OPTIONS + ['remove_fake_margins']
|
||||||
|
|
||||||
@@ -62,21 +59,21 @@ def check_command_line_options(parser, args, log):
|
|||||||
log.error('\n\nYou must specify the input AND output files')
|
log.error('\n\nYou must specify the input AND output files')
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
input = os.path.abspath(args[1])
|
input_file = os.path.abspath(args[1])
|
||||||
if not input.endswith('.recipe') and not os.access(input, os.R_OK) and not \
|
if not input_file.endswith('.recipe') and not os.access(input_file, os.R_OK) and not \
|
||||||
('-h' in args or '--help' in args):
|
('-h' in args or '--help' in args):
|
||||||
log.error('Cannot read from', input)
|
log.error('Cannot read from', input_file)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
if input.endswith('.recipe') and not os.access(input, os.R_OK):
|
if input_file.endswith('.recipe') and not os.access(input_file, os.R_OK):
|
||||||
input = args[1]
|
input_file = args[1]
|
||||||
|
|
||||||
output = args[2]
|
output_file = args[2]
|
||||||
if (output.startswith('.') and output[:2] not in {'..', '.'} and '/' not in
|
if (output_file.startswith('.') and output_file[:2] not in {'..', '.'} and '/' not in
|
||||||
output and '\\' not in output):
|
output_file and '\\' not in output_file):
|
||||||
output = os.path.splitext(os.path.basename(input))[0]+output
|
output_file = os.path.splitext(os.path.basename(input_file))[0]+output_file
|
||||||
output = os.path.abspath(output)
|
output_file = os.path.abspath(output_file)
|
||||||
|
|
||||||
return input, output
|
return input_file, output_file
|
||||||
|
|
||||||
|
|
||||||
def option_recommendation_to_cli_option(add_option, rec):
|
def option_recommendation_to_cli_option(add_option, rec):
|
||||||
@@ -307,15 +304,15 @@ def create_option_parser(args, log):
|
|||||||
else:
|
else:
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
input, output = check_command_line_options(parser, args, log)
|
input_file, output_file = check_command_line_options(parser, args, log)
|
||||||
|
|
||||||
from ebook_converter.ebooks.conversion.plumber import Plumber
|
from ebook_converter.ebooks.conversion.plumber import Plumber
|
||||||
|
|
||||||
reporter = ProgressBar(log)
|
reporter = ProgressBar(log)
|
||||||
if patheq(input, output):
|
if os.path.abspath(input_file) == os.path.abspath(output_file):
|
||||||
raise ValueError('Input file is the same as the output file')
|
raise ValueError('Input file is the same as the output file')
|
||||||
|
|
||||||
plumber = Plumber(input, output, log, reporter)
|
plumber = Plumber(input_file, output_file, log, reporter)
|
||||||
add_input_output_options(parser, plumber)
|
add_input_output_options(parser, plumber)
|
||||||
add_pipeline_options(parser, plumber)
|
add_pipeline_options(parser, plumber)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user