From 372899739d6c9d16e615f2ef849764236145a17f Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 14 Jun 2020 16:09:08 +0200 Subject: [PATCH] Removed patheq function --- ebook_converter/__init__.py | 29 +++-------------- ebook_converter/ebooks/conversion/cli.py | 41 +++++++++++------------- 2 files changed, 23 insertions(+), 47 deletions(-) diff --git a/ebook_converter/__init__.py b/ebook_converter/__init__.py index e222765..6879c5c 100644 --- a/ebook_converter/__init__.py +++ b/ebook_converter/__init__.py @@ -45,14 +45,6 @@ def to_unicode(raw, encoding='utf-8', errors='strict'): 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): if isinstance(path, bytes): path = path.decode(filesystem_encoding) @@ -61,15 +53,6 @@ def unicode_path(path, abs=False): 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): return name + '_again' @@ -107,21 +90,21 @@ def sanitize_file_name(name, substitute='_'): def prints(*args, **kwargs): - ''' + """ Print unicode arguments safely by encoding them to preferred_encoding 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 function to use repr when encoding fails. Returns the number of bytes written. - ''' + """ file = kwargs.get('file', sys.stdout) file = getattr(file, 'buffer', file) enc = 'utf-8' if os.getenv('CALIBRE_WORKER') else preferred_encoding - sep = kwargs.get('sep', ' ') + sep = kwargs.get('sep', ' ') if not isinstance(sep, bytes): sep = sep.encode(enc) - end = kwargs.get('end', '\n') + end = kwargs.get('end', '\n') if not isinstance(end, bytes): end = end.encode(enc) safe_encode = kwargs.get('safe_encode', False) @@ -175,10 +158,6 @@ def prints(*args, **kwargs): return count -class CommandLineError(Exception): - pass - - def setup_cli_handlers(logger, level): import logging if os.getenv('CALIBRE_WORKER') and logger.handlers: diff --git a/ebook_converter/ebooks/conversion/cli.py b/ebook_converter/ebooks/conversion/cli.py index 3ad1a57..878156d 100644 --- a/ebook_converter/ebooks/conversion/cli.py +++ b/ebook_converter/ebooks/conversion/cli.py @@ -10,9 +10,7 @@ import sys from ebook_converter.utils.config import OptionParser from ebook_converter.utils.logging import Log from ebook_converter.customize.conversion import OptionRecommendation -from ebook_converter import patheq from ebook_converter import init_mimetypes -from ebook_converter.utils.localization import localize_user_manual_link USAGE = '%prog ' + '''\ @@ -42,12 +40,11 @@ For full documentation of the conversion system see https://manual.calibre-ebook.com/conversion.html ''' -HEURISTIC_OPTIONS = ['markup_chapter_headings', - 'italicize_common_cases', 'fix_indents', - 'html_unwrap_factor', 'unwrap_lines', - 'delete_blank_paragraphs', 'format_scene_breaks', - 'dehyphenate', 'renumber_headings', - 'replace_scene_breaks'] +HEURISTIC_OPTIONS = ['markup_chapter_headings', 'italicize_common_cases', + 'fix_indents', 'html_unwrap_factor', 'unwrap_lines', + 'delete_blank_paragraphs', 'format_scene_breaks', + 'dehyphenate', 'renumber_headings', + 'replace_scene_breaks'] 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') raise SystemExit(1) - input = os.path.abspath(args[1]) - if not input.endswith('.recipe') and not os.access(input, os.R_OK) and not \ + input_file = os.path.abspath(args[1]) + if not input_file.endswith('.recipe') and not os.access(input_file, os.R_OK) and not \ ('-h' in args or '--help' in args): - log.error('Cannot read from', input) + log.error('Cannot read from', input_file) raise SystemExit(1) - if input.endswith('.recipe') and not os.access(input, os.R_OK): - input = args[1] + if input_file.endswith('.recipe') and not os.access(input_file, os.R_OK): + input_file = args[1] - output = args[2] - if (output.startswith('.') and output[:2] not in {'..', '.'} and '/' not in - output and '\\' not in output): - output = os.path.splitext(os.path.basename(input))[0]+output - output = os.path.abspath(output) + output_file = args[2] + if (output_file.startswith('.') and output_file[:2] not in {'..', '.'} and '/' not in + output_file and '\\' not in output_file): + output_file = os.path.splitext(os.path.basename(input_file))[0]+output_file + output_file = os.path.abspath(output_file) - return input, output + return input_file, output_file def option_recommendation_to_cli_option(add_option, rec): @@ -307,15 +304,15 @@ def create_option_parser(args, log): else: 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 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') - plumber = Plumber(input, output, log, reporter) + plumber = Plumber(input_file, output_file, log, reporter) add_input_output_options(parser, plumber) add_pipeline_options(parser, plumber)