Add replace to work with Win

This commit is contained in:
Kiryl
2021-09-08 15:59:19 +03:00
parent 53d43dd061
commit 292ea98b12
3 changed files with 5 additions and 4 deletions

View File

@@ -96,7 +96,7 @@ class EpubConverter:
def _read_css(self, css_href, html_path):
path_to_css_from_html = css_href
html_folder = dirname(html_path)
path_to_css_from_root = normpath(join(html_folder, path_to_css_from_html))
path_to_css_from_root = normpath(join(html_folder, path_to_css_from_html)).replace('\\', '/')
css_obj = self.ebooklib_book.get_item_with_href(path_to_css_from_root)
assert css_obj, f'Css style {css_href} was not in manifest.'
css_content: str = css_obj.get_content().decode()
@@ -238,7 +238,7 @@ class EpubConverter:
def match_href_to_path_from_toc(self, href, href_in_link, internal_link_tag):
dir_name = os.path.dirname(href)
normed_path = os.path.normpath(os.path.join(dir_name, href_in_link))
normed_path = os.path.normpath(os.path.join(dir_name, href_in_link)).replace('\\', '/')
full_path = [path for path in self.added_to_toc_hrefs if normed_path in path]
if not full_path:
self.logger.log(f'Error in {href} file. No {normed_path} file found in added to TOC documents. '
@@ -413,7 +413,7 @@ if __name__ == "__main__":
logger_object = BookLogger(name=f'epub', main_logger=logger, book_id=0)
json_converter = EpubConverter('/home/katerina/PycharmProjects/Jenia/converter/epub/9781119682387_pre_code2.epub',
json_converter = EpubConverter('../epub/calibri.epub',
logger=logger_object)
tmp = json_converter.convert_to_dict()

View File

@@ -37,7 +37,7 @@ def update_src_links_in_images(body_tag: Tag,
for img in img_tags:
path_to_img_from_html = img.attrs.get('src')
html_folder = os.path.dirname(path_to_html)
path_to_img_from_root = os.path.normpath(os.path.join(html_folder, path_to_img_from_html))
path_to_img_from_root = os.path.normpath(os.path.join(html_folder, path_to_img_from_html)).replace('\\', '/')
assert path_to_img_from_root in href2img_content, \
f'Image {path_to_img_from_html} in file {path_to_html} was not added to manifest.'

1
src/tmp.json Normal file

File diff suppressed because one or more lines are too long