From 4599779fd31e691df9511b8f0ccb0e9b094b976c Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 13 Nov 2021 12:14:47 +0100 Subject: [PATCH] Codechange: address various of CodeQL warnings (#223) --- truewiki/namespaces/file/namespace.py | 4 ++-- truewiki/namespaces/file/wikilink.py | 2 +- truewiki/storage/git.py | 4 ++-- truewiki/storage/github.py | 6 +++--- truewiki/storage/gitlab.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/truewiki/namespaces/file/namespace.py b/truewiki/namespaces/file/namespace.py index 1eded72..13a319b 100644 --- a/truewiki/namespaces/file/namespace.py +++ b/truewiki/namespaces/file/namespace.py @@ -193,12 +193,12 @@ def edit_callback(old_page: str, new_page: str, payload, execute: bool = False): # Someone is renaming the File to another namespace. This is most # likely not what the user wants, but let him do it anyway. if not new_page.startswith("File/"): - return + return None # Someone is making a File without adding a file. This is not ideal, # but for the same reason as the case above, we let him do it anyway. if not payload.get("file"): - return + return None payload["file"].file.seek(0) data = payload["file"].file.read() diff --git a/truewiki/namespaces/file/wikilink.py b/truewiki/namespaces/file/wikilink.py index 986eaa6..047ddab 100644 --- a/truewiki/namespaces/file/wikilink.py +++ b/truewiki/namespaces/file/wikilink.py @@ -39,7 +39,7 @@ def link_media(instance: WikiPage, wikilink: wikitextparser.WikiLink): except InvalidWikiLink as e: # Errors always end with a dot, hence the [:-1]. instance.add_error(f'{e.args[0][:-1]} (wikilink "{wikilink.string}").') - return + return False if wikilink.text: text = wikilink.text.strip() diff --git a/truewiki/storage/git.py b/truewiki/storage/git.py index d4a5a4e..be2be0f 100644 --- a/truewiki/storage/git.py +++ b/truewiki/storage/git.py @@ -65,10 +65,10 @@ def check_for_exception(task): class Storage(local.Storage): out_of_process_class = OutOfProcessStorage - def __init__(self): + def __init__(self, ssh_command=None): super().__init__() - self._ssh_command = None + self._ssh_command = ssh_command self._files_added = [] self._files_changed = [] diff --git a/truewiki/storage/github.py b/truewiki/storage/github.py index 10de4a2..0fc91f0 100644 --- a/truewiki/storage/github.py +++ b/truewiki/storage/github.py @@ -82,8 +82,6 @@ class Storage(GitStorage): out_of_process_class = OutOfProcessStorage def __init__(self): - super().__init__() - # We need to write the private key to disk: GitPython can only use # SSH-keys that are written on disk. if _github_private_key: @@ -91,7 +89,9 @@ def __init__(self): self._github_private_key_file.write(_github_private_key) self._github_private_key_file.flush() - self._ssh_command = f"ssh -i {self._github_private_key_file.name}" + super().__init__(f"ssh -i {self._github_private_key_file.name}") + else: + super().__init__() def prepare(self): _git = super().prepare() diff --git a/truewiki/storage/gitlab.py b/truewiki/storage/gitlab.py index bf9928e..e5dd846 100644 --- a/truewiki/storage/gitlab.py +++ b/truewiki/storage/gitlab.py @@ -25,8 +25,6 @@ class Storage(GitStorage): out_of_process_class = OutOfProcessStorage def __init__(self): - super().__init__() - # We need to write the private key to disk: GitPython can only use # SSH-keys that are written on disk. if _gitlab_private_key: @@ -34,7 +32,9 @@ def __init__(self): self._gitlab_private_key_file.write(_gitlab_private_key) self._gitlab_private_key_file.flush() - self._ssh_command = f"ssh -i {self._gitlab_private_key_file.name}" + super().__init__(f"ssh -i {self._gitlab_private_key_file.name}") + else: + super().__init__() def prepare(self): _git = super().prepare()