From eb3c88feb6be3895f6120bfa18e4333045a9c827 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Thu, 4 Jan 2024 11:49:02 +0100 Subject: [PATCH] [Piconsupdater] bugfix, thread method and error message logging added Picon.py: - bugfix: plugin always froze with the download screen when an error occurred with a broken picon. - changing method from 'threading.Thread' to (faster) 'twisted.internet.reactor.callInThread' - imports sorted DownloadJob.py: - Exception error message logging PiconsUpdaterView.py - timeouts for MessageBox added --- PiconsUpdater/src/DownloadJob.py | 4 +++- PiconsUpdater/src/Picon.py | 24 ++++++++++++------------ PiconsUpdater/src/PiconsUpdaterView.py | 6 +++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/PiconsUpdater/src/DownloadJob.py b/PiconsUpdater/src/DownloadJob.py index 5d075de41..2de251af3 100644 --- a/PiconsUpdater/src/DownloadJob.py +++ b/PiconsUpdater/src/DownloadJob.py @@ -19,12 +19,14 @@ def downloadPage(self, link, file, success, fail=None): link = link.encode('ascii', 'xmlcharrefreplace').decode().replace(' ', '%20').replace('\n', '').encode('utf-8') try: response = get(link) + content = response.content response.raise_for_status() with open(file, "wb") as f: - f.write(response.content) + f.write(content) success(file) except exceptions.RequestException as err: if fail is not None: + printToConsole("Error in module 'downloadPage': %s" % err) fail(err) diff --git a/PiconsUpdater/src/Picon.py b/PiconsUpdater/src/Picon.py index c4766d30b..e5e6f243f 100644 --- a/PiconsUpdater/src/Picon.py +++ b/PiconsUpdater/src/Picon.py @@ -1,15 +1,17 @@ -from os.path import isfile from _collections import deque -from subprocess import call -from threading import Thread +from os.path import isfile from PIL import Image -from .reflection import add_reflection +from subprocess import call +from twisted.internet.reactor import callInThread + from Components.config import config + from .BouquetParser import getChannelKey from .DiskUtils import getFiles, getCleanFileName from .EventDispatcher import dispatchEvent from .JobProgressView import JobProgressView -from . import printToConsole, getPiconsPath, getTmpLocalPicon, _ # for localized messages +from .reflection import add_reflection +from .import printToConsole, getPiconsPath, getTmpLocalPicon, _ # for localized messages MERGE_PICONS_FINISHED = 'mergePiconsFinished' OPTIMIZE_PICONS_FINISHED = 'optimizePiconsFinished' @@ -55,8 +57,7 @@ def execQueue(self): progress = int(100 * (float(self.mergePiconsCount) / float(self.mergePiconsTotal))) self.session.current_dialog.setProgress(progress, _('Merge %d of %d Picons') % (self.mergePiconsCount, self.mergePiconsTotal)) mergeData = self.executionQueueList.popleft() - t = Thread(target=self.mergePicon, args=(mergeData.channelPicon, mergeData.targetPicon)) - t.start() + callInThread(self.mergePicon, mergeData.channelPicon, mergeData.targetPicon) except Exception as e: self.__clearExecutionQueueList() printToConsole('MergePicon execQueue exception:\n' + str(e)) @@ -80,13 +81,13 @@ def mergePicon(self, channelPicon, targetPicon): background = Image.open(self.bgPath) except Exception: printToConsole("Error: Background '%s' is corrupted!" % self.bgPath) - return + self.__runFinished() try: picon = Image.open(channelPicon) except Exception: printToConsole("Error: Picon '%s' is corrupted!" % channelPicon) - return + self.__runFinished() backgroundWidth, backgroundHeight = background.size piconWidth, piconHeight = picon.size @@ -103,7 +104,7 @@ def mergePicon(self, channelPicon, targetPicon): background.paste(foreground, None, foreground) except Exception as e: printToConsole("Error: ChannelPicon: %s '%s'" % (str(e), channelPicon)) - return + self.__runFinished() if piconWidth != self.size[0] or piconHeight != self.size[1]: background.thumbnail(self.size, Image.LANCZOS) @@ -138,8 +139,7 @@ def execQueue(self): progress = int(100 * (float(self.optimizePiconsCount) / float(self.optimizePiconsTotal))) self.session.current_dialog.setProgress(progress, _('Optimize %d of %d Picons') % (self.optimizePiconsCount, self.optimizePiconsTotal)) self.execCommand = self.executionQueueList.popleft() - t = Thread(target=self.optimizePicon) - t.start() + callInThread(self.optimizePicon) except Exception as e: self.__clearExecutionQueueList() printToConsole('OptimizePicons execQueue exception:\n' + str(e)) diff --git a/PiconsUpdater/src/PiconsUpdaterView.py b/PiconsUpdater/src/PiconsUpdaterView.py index bf9c95508..23ca160f5 100644 --- a/PiconsUpdater/src/PiconsUpdaterView.py +++ b/PiconsUpdater/src/PiconsUpdaterView.py @@ -223,7 +223,7 @@ def startDownloadPicons(self): return bgimagepath = self.getBackgroundImagePath() if bgimagepath and self.getCurrentBackgroundList() is not None and isfile(bgimagepath) is False: - self.session.open(MessageBox, _('Background Image not downloaded yet, please wait some seconds and try again.'), type=MessageBox.TYPE_INFO) + self.session.open(MessageBox, _('Background Image not downloaded yet, please wait some seconds and try again.'), type=MessageBox.TYPE_INFO, timeout=10) return addEventListener(DOWNLOAD_ALL_FINISHED, self.__downloadAllFinished) self.session.open(JobProgressView, 'Download Progress', msgBoxID='startDownload') @@ -314,7 +314,7 @@ def __checkReadWriteDir(self, configElement): return False def __showPathIsNotWriteableWarning(self, dirName): - self.session.open(MessageBox, _('The directory %s is not writable.\nMake sure you select a writable directory instead.') % dirName, MessageBox.TYPE_ERROR) + self.session.open(MessageBox, _('The directory %s is not writable.\nMake sure you select a writable directory instead.') % dirName, MessageBox.TYPE_ERROR, timeout=10) def __selectionChanged(self): cur = self['config'].getCurrent() @@ -385,7 +385,7 @@ def processFinished(self, *args): self.session.current_dialog.close(True) def showOptimizeFileSizeMessage(self, *args): - self.session.openWithCallback(self.__optimizeFileSizeWindowCallback, MessageBox, _('Optimize Picons file size?\n\nBe aware, this function is maybe very slow and reduces the quality!!'), MessageBox.TYPE_YESNO, default=False) + self.session.openWithCallback(self.__optimizeFileSizeWindowCallback, MessageBox, _('Optimize Picons file size?\n\nBe aware, this function is maybe very slow and reduces the quality!!'), MessageBox.TYPE_YESNO, default=False, timeout=10) def __optimizeFileSizeWindowCallback(self, result): if result: