From 8bd06ba37ad3ac1a4e3400cd36662377d27ed503 Mon Sep 17 00:00:00 2001 From: Pawel Sikora Date: Wed, 5 May 2021 06:56:58 +0200 Subject: [PATCH] more prints to verbose mode, add more exception handling --- mkdocs_with_confluence/plugin.py | 41 +++++++++++++++++++++++++------- setup.py | 2 +- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mkdocs_with_confluence/plugin.py b/mkdocs_with_confluence/plugin.py index 71417f8..53984bb 100644 --- a/mkdocs_with_confluence/plugin.py +++ b/mkdocs_with_confluence/plugin.py @@ -107,27 +107,49 @@ class MkdocsWithConfluence(BasePlugin): print("-", end="", flush=True) print(f"] ({MkdocsWithConfluence._id} / {self.flen})", end="\r", flush=True) - if self.config["debug"]: + if self.config["verbose"]: print(f"\nHandling Page '{page.title}' (And Parent Nav Pages if necessary):\n") if not all(self.config_scheme): print("ERR: YOU HAVE EMPTY VALUES IN YOUR CONFIG. ABORTING") return markdown - try: - parent = self.__get_section_title(page.ancestors[0].__repr__()) + try: + if self.config["verbose"]: + print("Get section first parent title...: ") + try: + parent = self.__get_section_title(page.ancestors[0].__repr__()) + except IndexError as e: + print( + f'ERR({e}): No second parent! Assuming self.config["parent_page_name"]' + f"{self.config['parent_page_name']}..." + ) + parent = None + if self.config["verbose"]: + print(f"{parent}") + if not parent: + parent = self.config["parent_page_name"] if self.config["parent_page_name"] is not None: main_parent = self.config["parent_page_name"] else: main_parent = self.config["space"] - parent1 = self.__get_section_title(page.ancestors[1].__repr__()) + if self.config["verbose"]: + print("Get section second parent title...: ") + try: + parent1 = self.__get_section_title(page.ancestors[1].__repr__()) + except IndexError as e: + print(f"ERR({e}) No second parent! Assuming second parent is main parent: {main_parent}...") + parent1 = None + if self.config["verbose"]: + print(f"{parent}") + if not parent1: parent1 = main_parent - if self.config["debug"]: + if self.config["verbose"]: print(f"ONLY ONE PARENT FOUND. ASSUMING AS A FIRST NODE after main parent config {main_parent}") - if self.config["debug"]: + if self.config["verbose"]: print(f"PARENT0: {parent}, PARENT1: {parent1}, MAIN PARENT: {main_parent}") tf = tempfile.NamedTemporaryFile(delete=False) @@ -139,9 +161,9 @@ class MkdocsWithConfluence(BasePlugin): if self.config["debug"]: print(f"FOUND IMAGE: {match.group(1)}") files.append(match.group(1)) - except AttributeError: + except AttributeError as e: if self.config["debug"]: - print("WARN: No images found in markdown. Proceed..") + print(f"WARN(({e}): No images found in markdown. Proceed..") new_markdown = re.sub( r'