Skip to content

Commit

Permalink
fixes #100
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Apr 17, 2024
1 parent 4400eba commit 86a6cf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion wikibot3rd/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.1"
__version__ = "0.11.2"
29 changes: 18 additions & 11 deletions wikibot3rd/wikipush.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ def nuke(self, pageTitles, force=False):
pageToBeDeleted.delete("deleted by wiknuke")
self.log("✅")
except Exception as ex:
msg = str(ex)
self.log("❌:%s" % msg)
self.show_exception(ex)

@staticmethod
def getDiff(text: str, newText: str, n: int = 1, forHuman: bool = True) -> str:
Expand Down Expand Up @@ -353,8 +352,7 @@ def edit(
else:
self.log("↔")
except Exception as ex:
msg = str(ex)
self.log(f"❌:{msg}")
self.show_exception(ex)

def edit_wikison(
self,
Expand Down Expand Up @@ -403,8 +401,7 @@ def edit_wikison(
else:
self.log("↔")
except Exception as ex:
msg = str(ex)
self.log(f"❌:{msg}")
self.show_exception(ex)

def upload(self, files, force=False):
"""
Expand All @@ -427,7 +424,7 @@ def upload(self, files, force=False):
self.uploadImage(file, filename, description, force)
self.log("✅")
except Exception as ex:
self.log("❌:%s" % str(ex))
self.show_exception(ex)

def backup(self, pageTitles, backupPath=None, git=False, withImages=False):
"""
Expand Down Expand Up @@ -463,7 +460,7 @@ def backup(self, pageTitles, backupPath=None, git=False, withImages=False):
self.backupImages(page.images(), imageBackupPath)

except Exception as ex:
self.log("❌:%s" % str(ex))
self.show_exception(ex)
if git:
gitPath = "%s/.git" % backupPath
if not os.path.isdir(gitPath):
Expand Down Expand Up @@ -546,7 +543,7 @@ def work(
self.log("❌")
failed.append(pageTitle)
except Exception as ex:
self.log(f"❌:{str(ex)}")
self.show_exception(ex)
failed.append(pageTitle)
return failed

Expand Down Expand Up @@ -627,6 +624,17 @@ def pushImages(self, imageList, delim="", ignore=False):
print(image.imageinfo)
except Exception as ex:
self.handleException(ex, ignore)

def show_exception(self, ex: Exception):
"""
Show the given exception and, if debug mode is on, show the traceback.
"""
msg = f"❌: {str(ex)}"
if self.debug:
# Append the formatted traceback to the message
msg += "\n" + traceback.format_exc()

self.log(msg)

def handleException(self, ex, ignoreExists=False):
"""
Expand Down Expand Up @@ -783,8 +791,7 @@ def restore(self, pageTitles=None, backupPath=None, listFile=None, stdIn=False):
)
self.log("✅")
except Exception as ex:
self.log("❌:%s" % str(ex))

self.show_exception(ex)

__version__ = Version.version
__date__ = Version.date
Expand Down

0 comments on commit 86a6cf8

Please sign in to comment.