Skip to content

Commit

Permalink
[Piconsupdater] bugfix, thread method and error message logging added
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MrServo committed Jan 4, 2024
1 parent a5627dd commit eb3c88f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion PiconsUpdater/src/DownloadJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
24 changes: 12 additions & 12 deletions PiconsUpdater/src/Picon.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions PiconsUpdater/src/PiconsUpdaterView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit eb3c88f

Please sign in to comment.