Add try except blocks where is needed

This commit is contained in:
Kiryl
2022-10-20 17:00:19 +03:00
parent 31d0d1a88a
commit a21a4b55b3
2 changed files with 33 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
import json import json
import codecs import codecs
import logging
from src.book_solver import BookSolver from src.book_solver import BookSolver
from src.util.helpers import BookLogger from src.util.helpers import BookLogger
@@ -30,11 +31,19 @@ class EpubBook(BookSolver):
json for LiveCarta platform json for LiveCarta platform
""" """
html_preprocessor = HtmlPresetsProcessor(
logger=self.logger_object, preset_path="presets/epub_presets.json")
style_preprocessor = StyleReader() style_preprocessor = StyleReader()
html_processor = HtmlEpubProcessor(logger=self.logger_object, # Parses and cleans html, gets list of tags, gets footnotes
html_preprocessor=html_preprocessor) try:
html_preprocessor = HtmlPresetsProcessor(
logger=self.logger_object, preset_path="presets/epub_presets.json")
html_processor = HtmlEpubProcessor(logger=self.logger_object,
html_preprocessor=html_preprocessor)
except Exception as exc:
self.logger_object.log(
"Error has occurred while processing .html", logging.ERROR)
self.logger_object.log_error_to_main_log()
self.status_wrapper.set_error()
raise exc
json_converter = EpubConverter( json_converter = EpubConverter(
self.book_path, access=self.access, logger=self.logger_object, self.book_path, access=self.access, logger=self.logger_object,
style_processor=style_preprocessor, html_processor=html_processor) style_processor=style_preprocessor, html_processor=html_processor)

View File

@@ -109,24 +109,27 @@ class StyleReader:
return constraints_on_value, value_not_in_possible_values_list return constraints_on_value, value_not_in_possible_values_list
def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list: def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list:
for i, style in reversed(list(enumerate(split_style))): try:
style_name, style_value = style.split(":") for i, style in reversed(list(enumerate(split_style))):
if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS: style_name, style_value = style.split(":")
# property not in LIVECARTA_STYLE_ATTRS, remove if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
split_style.remove(style) # property not in LIVECARTA_STYLE_ATTRS, remove
continue split_style.remove(style)
continue
cleaned_value = self.clean_value(style_value, style_name) cleaned_value = self.clean_value(style_value, style_name)
if all(self.style_conditions(cleaned_value, style_name)): if all(self.style_conditions(cleaned_value, style_name)):
# there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove # there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove
split_style.remove(style) split_style.remove(style)
continue continue
else: else:
if style_name in self.LIVECARTA_STYLE_ATTRS_MAPPING: if style_name in self.LIVECARTA_STYLE_ATTRS_MAPPING:
# function that converts our data # function that converts our data
func = self.LIVECARTA_STYLE_ATTRS_MAPPING[style_name] func = self.LIVECARTA_STYLE_ATTRS_MAPPING[style_name]
style_value = func(cleaned_value) style_value = func(cleaned_value)
split_style[i] = style_name + ":" + style_value split_style[i] = style_name + ":" + style_value
except ValueError as ve:
print(f"Style value isn't correct.")
return split_style return split_style
def build_inline_style_content(self, style: str) -> str: def build_inline_style_content(self, style: str) -> str: