From: ghost Date: Thu, 12 Feb 2009 20:25:08 +0000 (+0100) Subject: small speedups/cleanups by moritz venn X-Git-Tag: 2.6.0~438^2~2 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/76e5181cade262b86610dcc851bcb4452196ccdc small speedups/cleanups by moritz venn --- diff --git a/RecordTimer.py b/RecordTimer.py index 897c281a..f8e0dbd7 100644 --- a/RecordTimer.py +++ b/RecordTimer.py @@ -363,7 +363,7 @@ class RecordTimerEntry(timer.TimerEntry, object): elif event == iRecordableService.evStart: text = _("A record has been started:\n%s") % self.name if self.dirnameHadToFallback: - text = '\n'.join([text, _("Please note that the previously selected media could not be accessed and therefore the default directory is being used instead.")]) + text = '\n'.join((text, _("Please note that the previously selected media could not be accessed and therefore the default directory is being used instead."))) # maybe this should be configurable? Notifications.AddPopup(text = text, type = MessageBox.TYPE_INFO, timeout = 3) @@ -657,7 +657,7 @@ class RecordTimer(timer.Timer): chktimecmp = chktime.tm_wday * 1440 + chktime.tm_hour * 60 + chktime.tm_min chktimecmp_end = chktimecmp + (duration / 60) time = localtime(x.begin) - for y in range(7): + for y in (0, 1, 2, 3, 4, 5, 6): if x.repeated & (2 ** y): timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min if timecmp <= chktimecmp < (timecmp + ((x.end - x.begin) / 60)): diff --git a/lib/python/Components/About.py b/lib/python/Components/About.py index ce1328cf..bb2d7568 100644 --- a/lib/python/Components/About.py +++ b/lib/python/Components/About.py @@ -23,7 +23,7 @@ class About: month = version[8:10] day = version[10:12] - return '-'.join(["dev", year, month, day]) + return '-'.join(("dev", year, month, day)) file.close() except IOError: pass diff --git a/lib/python/Components/ActionMap.py b/lib/python/Components/ActionMap.py index b65d6ebc..a018983a 100644 --- a/lib/python/Components/ActionMap.py +++ b/lib/python/Components/ActionMap.py @@ -56,7 +56,7 @@ class ActionMap: class NumberActionMap(ActionMap): def action(self, contexts, action): - numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + numbers = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9") if (action in numbers and self.actions.has_key(action)): res = self.actions[action](int(action)) if res is not None: @@ -83,7 +83,7 @@ class HelpableActionMap(ActionMap): adict = { } for (action, funchelp) in actions.iteritems(): # check if this is a tuple - if type(funchelp) is type(()): + if isinstance(funchelp, tuple): alist.append((action, funchelp[1])) adict[action] = funchelp[0] else: diff --git a/lib/python/Components/EpgList.py b/lib/python/Components/EpgList.py index 8a7c8d45..8bd8e759 100644 --- a/lib/python/Components/EpgList.py +++ b/lib/python/Components/EpgList.py @@ -35,7 +35,7 @@ class Rect: class EPGList(HTMLComponent, GUIComponent): def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None): - self.days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ] + self.days = (_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")) self.timer = timer self.onSelChanged = [ ] if selChangedCB is not None: @@ -43,6 +43,8 @@ class EPGList(HTMLComponent, GUIComponent): GUIComponent.__init__(self) self.type=type self.l = eListboxPythonMultiContent() + self.l.setFont(0, gFont("Regular", 22)) + self.l.setFont(1, gFont("Regular", 16)) if type == EPG_TYPE_SINGLE: self.l.setBuildFunc(self.buildSingleEntry) elif type == EPG_TYPE_MULTI: @@ -116,8 +118,6 @@ class EPGList(HTMLComponent, GUIComponent): def recalcEntrySize(self): esize = self.l.getItemSize() - self.l.setFont(0, gFont("Regular", 22)) - self.l.setFont(1, gFont("Regular", 16)) width = esize.width() height = esize.height() if self.type == EPG_TYPE_SINGLE: @@ -169,14 +169,18 @@ class EPGList(HTMLComponent, GUIComponent): r1=self.weekday_rect r2=self.datetime_rect r3=self.descr_rect - res = [ None ] # no private data needed t = localtime(beginTime) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]])) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))) + res = [ + None, # no private data needed + (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]), + (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4])) + ] if rec: clock_pic = self.getClockPixmap(service, beginTime, duration, eventId) - res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic)) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)) + res.extend(( + (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic), + (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName) + )) else: res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)) return res @@ -186,14 +190,18 @@ class EPGList(HTMLComponent, GUIComponent): r1=self.weekday_rect r2=self.datetime_rect r3=self.service_rect - res = [ None ] # no private data needed t = localtime(beginTime) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]])) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))) + res = [ + None, # no private data needed + (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]), + (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4])) + ] if rec: clock_pic = self.getClockPixmap(service, beginTime, duration, eventId) - res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic)) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)) + res.extend(( + (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic), + (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name) + )) else: res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)) return res @@ -207,8 +215,10 @@ class EPGList(HTMLComponent, GUIComponent): res = [ None ] # no private data needed if rec: clock_pic = self.getClockPixmap(service, begTime, duration, eventId) - res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name)) - res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic)) + res.extend(( + (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name), + (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic) + )) else: res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name)) if begTime is not None: @@ -217,12 +227,16 @@ class EPGList(HTMLComponent, GUIComponent): end = localtime(begTime+duration) # print "begin", begin # print "end", end - res.append((eListboxPythonMultiContent.TYPE_TEXT, r4.left(), r4.top(), r4.width(), r4.height(), 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER, "%02d.%02d - %02d.%02d"%(begin[3],begin[4],end[3],end[4]))); - res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)) + res.extend(( + (eListboxPythonMultiContent.TYPE_TEXT, r4.left(), r4.top(), r4.width(), r4.height(), 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER, "%02d.%02d - %02d.%02d"%(begin[3],begin[4],end[3],end[4])), + (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName) + )) else: percent = (nowTime - begTime) * 100 / duration - res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent)); - res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)) + res.extend(( + (eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent), + (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName) + )) return res def queryEPG(self, list, buildFunc=None): @@ -234,16 +248,16 @@ class EPGList(HTMLComponent, GUIComponent): return [ ] def fillMultiEPG(self, services, stime=-1): - t = time() + #t = time() test = [ (service.ref.toString(), 0, stime) for service in services ] test.insert(0, 'X0RIBDTCn') self.list = self.queryEPG(test) self.l.setList(self.list) - print time() - t + #print time() - t self.selectionChanged() def updateMultiEPG(self, direction): - t = time() + #t = time() test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ] test.insert(0, 'XRIBDTCn') tmp = self.queryEPG(test) @@ -255,40 +269,40 @@ class EPGList(HTMLComponent, GUIComponent): self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6]) cnt+=1 self.l.setList(self.list) - print time() - t + #print time() - t self.selectionChanged() def fillSingleEPG(self, service): - t = time() + #t = time() test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ] self.list = self.queryEPG(test) self.l.setList(self.list) - print time() - t + #print time() - t self.selectionChanged() def sortSingleEPG(self, type): - if len(self.list): + list = self.list + if list: + event_id = self.getSelectedEventId() if type == 1: - event_id = self.getSelectedEventId() - self.list.sort(key=lambda x: (x[4] and x[4].lower(), x[2])) - self.l.setList(self.list) - self.moveToEventId(event_id) + list.sort(key=lambda x: (x[4] and x[4].lower(), x[2])) else: assert(type == 0) - event_id = self.getSelectedEventId() - self.list.sort(key=lambda x: x[2]) - self.l.setList(self.list) - self.moveToEventId(event_id) + list.sort(key=lambda x: x[2]) + self.moveToEventId(event_id) def getSelectedEventId(self): x = self.l.getCurrentSelection() return x and x[1] def moveToService(self,serviceref): - for x in range(len(self.list)): - if self.list[x][1] == serviceref.toString(): - self.instance.moveSelectionTo(x) + index = 0 + refstr = serviceref.toString() + for x in self.list: + if x[1] == refstr: + self.instance.moveSelectionTo(index) break + index += 1 def moveToEventId(self, eventId): index = 0 diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py index 6c6c3c6c..d165e26c 100644 --- a/lib/python/Components/Harddisk.py +++ b/lib/python/Components/Harddisk.py @@ -2,7 +2,7 @@ from os import system, listdir, statvfs, popen, makedirs, readlink, stat, major, from Tools.Directories import SCOPE_HDD, resolveFilename from Tools.CList import CList from SystemInfo import SystemInfo -import string, time +import time from Components.Console import Console def tryOpen(filename): @@ -442,7 +442,7 @@ class HarddiskManager: # see if this is a harddrive l = len(device) - if l and device[l-1] not in string.digits: + if l and not device[l-1].isdigit(): error, blacklisted, removable, is_cdrom, partitions, medium_found = self.getBlockDevInfo(device) if not blacklisted and not removable and not is_cdrom and medium_found: self.hdd.append(Harddisk(device)) @@ -456,7 +456,7 @@ class HarddiskManager: self.partitions.remove(x) self.on_partition_list_change("remove", x) l = len(device) - if l and device[l-1] not in string.digits: + if l and not device[l-1].isdigit(): idx = 0 for hdd in self.hdd: if hdd.device == device: @@ -499,7 +499,7 @@ class HarddiskManager: dev = devname[:3] part = devname[3:] for p in part: - if p not in string.digits: + if not p.isdigit(): return devname, 0 return dev, part and int(part) or 0 diff --git a/lib/python/Components/HelpMenuList.py b/lib/python/Components/HelpMenuList.py index 04815c8d..2a7bd995 100755 --- a/lib/python/Components/HelpMenuList.py +++ b/lib/python/Components/HelpMenuList.py @@ -38,7 +38,7 @@ class HelpMenuList(GUIComponent): entry.append( (actionmap, context, action, name ) ) - if type(help).__name__== 'list': + if isinstance(help, list): self.extendedHelp = True print "extendedHelpEntry found" entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 26, 0, 0, help[0]) ) diff --git a/lib/python/Components/PluginComponent.py b/lib/python/Components/PluginComponent.py index d72e2af3..6e357cd0 100644 --- a/lib/python/Components/PluginComponent.py +++ b/lib/python/Components/PluginComponent.py @@ -63,7 +63,7 @@ class PluginComponent: continue # allow single entry not to be a list - if type(plugins) is not list: + if not isinstance(plugins, list): plugins = [ plugins ] for p in plugins: @@ -91,7 +91,7 @@ class PluginComponent: def getPlugins(self, where): """Get list of plugins in a specific category""" - if type(where) is not list: + if not isinstance(where, list): where = [ where ] res = [ ] diff --git a/lib/python/Components/Scanner.py b/lib/python/Components/Scanner.py index 86a5431d..17c4aaa8 100644 --- a/lib/python/Components/Scanner.py +++ b/lib/python/Components/Scanner.py @@ -2,41 +2,29 @@ from Plugins.Plugin import PluginDescriptor from Components.PluginComponent import plugins from os import path as os_path, walk as os_walk -from string import lower -from mimetypes import guess_type +from mimetypes import guess_type, add_type -def getExtension(file): - p = file.rfind('.') - if p == -1: - ext = "" - else: - ext = file[p+1:] - - return lower(ext) +add_type("application/x-debian-package", ".ipk") +add_type("application/ogg", ".ogg") +add_type("audio/x-flac", ".flac") +add_type("application/x-dream-package", ".dmpkg") +add_type("application/x-dream-image", ".nfi") +add_type("video/MP2T", ".ts") +add_type("video/x-dvd-iso", ".iso") def getType(file): (type, _) = guess_type(file) if type is None: - # Detect some mimetypes unknown to dm7025 - # TODO: do mimetypes.add_type once should be better - ext = getExtension(file) - if ext == "ipk": - return "application/x-debian-package" - elif ext == "ogg": - return "application/ogg" - elif ext == "flac": - return "audio/x-flac" - elif ext == "dmpkg": - return "application/x-dream-package" - elif ext == "nfi": - return "application/x-dream-image" - elif ext == "ts": - return "video/MP2T" - elif ext == "iso": - return "video/x-dvd-iso" - elif file[-12:].lower() == "video_ts.ifo": + # Detect some unknown types + if file[-12:].lower() == "video_ts.ifo": return "video/x-dvd" - elif ext == "dat" and file[-11:-6].lower() == "avseq": + + p = file.rfind('.') + if p == -1: + return None + ext = file[p+1:].lower() + + if ext == "dat" and file[-11:-6].lower() == "avseq": return "video/x-vcd" return type diff --git a/lib/python/Components/ServiceList.py b/lib/python/Components/ServiceList.py index b5e44b4d..b0283c11 100644 --- a/lib/python/Components/ServiceList.py +++ b/lib/python/Components/ServiceList.py @@ -5,8 +5,6 @@ from skin import parseColor, parseFont from enigma import eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect from Tools.LoadPixmap import LoadPixmap -from string import upper - from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE class ServiceList(HTMLComponent, GUIComponent): @@ -113,7 +111,7 @@ class ServiceList(HTMLComponent, GUIComponent): # TODO fill with life print "Next char: " index = self.l.getNextBeginningWithChar(char) - indexup = self.l.getNextBeginningWithChar(upper(char)) + indexup = self.l.getNextBeginningWithChar(char.upper()) if indexup != 0: if (index > indexup or index == 0): index = indexup diff --git a/lib/python/Components/TimerList.py b/lib/python/Components/TimerList.py index f8474374..a237c364 100644 --- a/lib/python/Components/TimerList.py +++ b/lib/python/Components/TimerList.py @@ -25,7 +25,7 @@ class TimerList(HTMLComponent, GUIComponent, object): if timer.repeated: flags = timer.repeated count = 0 - for x in range(0, 7): + for x in (0, 1, 2, 3, 4, 5, 6): if (flags & 1 == 1): if (count != 0): repeatedtext += ", " diff --git a/lib/python/Components/TimerSanityCheck.py b/lib/python/Components/TimerSanityCheck.py index 99b2fba5..cf02459d 100644 --- a/lib/python/Components/TimerSanityCheck.py +++ b/lib/python/Components/TimerSanityCheck.py @@ -37,7 +37,7 @@ class TimerSanityCheck: if timer.begin == self.newtimer.begin: getUnsignedDataRef1 = timer.service_ref.ref.getUnsignedData getUnsignedDataRef2 = self.newtimer.service_ref.ref.getUnsignedData - for x in range(1,5): + for x in (1, 2, 3, 4): if getUnsignedDataRef1(x) != getUnsignedDataRef2(x): break; else: diff --git a/lib/python/Components/UsageConfig.py b/lib/python/Components/UsageConfig.py index 21e057f2..26138f20 100644 --- a/lib/python/Components/UsageConfig.py +++ b/lib/python/Components/UsageConfig.py @@ -118,7 +118,7 @@ def updateChoices(sel, choices): defval = None val = int(sel.value) if not val in choices: - tmp = choices+[] + tmp = choices[:] tmp.reverse() for x in tmp: if x < val: diff --git a/lib/python/Plugins/Extensions/DVDBurn/DVDProject.py b/lib/python/Plugins/Extensions/DVDBurn/DVDProject.py index b0b8197a..7ea32dfe 100644 --- a/lib/python/Plugins/Extensions/DVDBurn/DVDProject.py +++ b/lib/python/Plugins/Extensions/DVDBurn/DVDProject.py @@ -41,8 +41,7 @@ class DVDProject: return title def saveProject(self, path): - import xml.dom.minidom - from Tools.XMLTools import elementsWithTag, mergeText, stringToXML + from Tools.XMLTools import stringToXML list = [] list.append('\n') list.append('\n') diff --git a/lib/python/Plugins/Plugin.py b/lib/python/Plugins/Plugin.py index 6df4fce7..53e7b0b8 100644 --- a/lib/python/Plugins/Plugin.py +++ b/lib/python/Plugins/Plugin.py @@ -52,13 +52,13 @@ class PluginDescriptor: def __init__(self, name = "Plugin", where = [ ], description = "", icon = None, fnc = None, wakeupfnc = None, internal = False): self.name = name self.internal = internal - if type(where) is list: + if isinstance(where, list): self.where = where else: self.where = [ where ] self.description = description - if type(icon) is str or icon is None: + if icon is None or isinstance(icon, str): self.iconstr = icon self.icon = None else: @@ -69,8 +69,8 @@ class PluginDescriptor: self.__call__ = fnc def updateIcon(self, path): - if type(self.iconstr) is str: - self.icon = LoadPixmap(path + "/" + self.iconstr) + if isinstance(self.iconstr, str): + self.icon = LoadPixmap('/'.join((path, self.iconstr))) else: self.icon = None diff --git a/lib/python/Screens/InfoBar.py b/lib/python/Screens/InfoBar.py index 31a32563..bd9ea182 100644 --- a/lib/python/Screens/InfoBar.py +++ b/lib/python/Screens/InfoBar.py @@ -159,15 +159,19 @@ class MoviePlayer(InfoBarBase, InfoBarShowHide, \ def handleLeave(self, how): self.is_closing = True if how == "ask": - list = [] - list.append((_("Yes"), "quit")) - if config.usage.setup_level.index >= 2: # expert+ - list.append((_("Yes, returning to movie list"), "movielist")) - if config.usage.setup_level.index >= 2: # expert+ - list.append((_("Yes, and delete this movie"), "quitanddelete")) - list.append((_("No"), "continue")) - if config.usage.setup_level.index >= 2: # expert+ - list.append((_("No, but restart from begin"), "restart")) + if config.usage.setup_level.index < 2: # -expert + list = ( + (_("Yes"), "quit"), + (_("No"), "continue") + ) + else: + list = ( + (_("Yes"), "quit"), + (_("Yes, returning to movie list"), "movielist"), + (_("Yes, and delete this movie"), "quitanddelete"), + (_("No"), "continue"), + (_("No, but restart from begin"), "restart") + ) from Screens.ChoiceBox import ChoiceBox self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list) @@ -184,26 +188,26 @@ class MoviePlayer(InfoBarBase, InfoBarShowHide, \ def leavePlayerConfirmed(self, answer): answer = answer and answer[1] - if answer in ["quitanddelete", "quitanddeleteconfirmed"]: + if answer in ("quitanddelete", "quitanddeleteconfirmed"): ref = self.session.nav.getCurrentlyPlayingServiceReference() from enigma import eServiceCenter serviceHandler = eServiceCenter.getInstance() info = serviceHandler.info(ref) name = info and info.getName(ref) or _("this recording") - if answer == "quitanddelete": - from Screens.MessageBox import MessageBox - self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % name) - return - - if answer == "quitanddeleteconfirmed": - offline = serviceHandler.offlineOperations(ref) - if offline.deleteFromDisk(0): + if answer == "quitanddelete": from Screens.MessageBox import MessageBox - self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR) + self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % name) return - if answer in ["quit", "quitanddeleteconfirmed"]: + elif answer == "quitanddeleteconfirmed": + offline = serviceHandler.offlineOperations(ref) + if offline.deleteFromDisk(0): + from Screens.MessageBox import MessageBox + self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR) + return + + if answer in ("quit", "quitanddeleteconfirmed"): config.movielist.last_videodir.cancel() self.close() elif answer == "movielist": diff --git a/lib/python/Screens/InfoBarGenerics.py b/lib/python/Screens/InfoBarGenerics.py index 627a53d2..ddd4366c 100644 --- a/lib/python/Screens/InfoBarGenerics.py +++ b/lib/python/Screens/InfoBarGenerics.py @@ -490,10 +490,9 @@ class InfoBarEPG: self.session.open(EPGSelection, ref) def showEventInfoPlugins(self): - list = [] - for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EVENTINFO): - list.append((p.name, boundFunction(self.runPlugin, p))) - if len(list): + list = [(p.name, boundFunction(self.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EVENTINFO)] + + if list: list.append((_("show single service EPG..."), self.openSingleServiceEPG)) self.session.openWithCallback(self.EventInfoPluginChosen, ChoiceBox, title=_("Please choose an extension..."), list = list) else: @@ -510,38 +509,40 @@ class InfoBarEPG: self.session.open(EPGSelection, refstr, None, eventid) def getNowNext(self): - self.epglist = [ ] + epglist = [ ] service = self.session.nav.getCurrentService() info = service and service.info() ptr = info and info.getEvent(0) if ptr: - self.epglist.append(ptr) + epglist.append(ptr) ptr = info and info.getEvent(1) if ptr: - self.epglist.append(ptr) + epglist.append(ptr) + self.epglist = epglist def __evEventInfoChanged(self): if self.is_now_next and len(self.dlg_stack) == 1: self.getNowNext() assert self.eventView - if len(self.epglist): + if self.epglist: self.eventView.setEvent(self.epglist[0]) def openEventView(self): ref = self.session.nav.getCurrentlyPlayingServiceReference() self.getNowNext() - if len(self.epglist) == 0: + epglist = self.epglist + if not epglist: self.is_now_next = False epg = eEPGCache.getInstance() ptr = ref and ref.valid() and epg.lookupEventTime(ref, -1) if ptr: - self.epglist.append(ptr) + epglist.append(ptr) ptr = epg.lookupEventTime(ref, ptr.getBeginTime(), +1) if ptr: - self.epglist.append(ptr) + epglist.append(ptr) else: self.is_now_next = True - if len(self.epglist) > 0: + if epglist: self.eventView = self.session.openWithCallback(self.closed, EventViewEPGSelect, self.epglist[0], ServiceReference(ref), self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList) self.dlg_stack.append(self.eventView) else: @@ -549,11 +550,12 @@ class InfoBarEPG: self.openMultiServiceEPG(False) def eventViewCallback(self, setEvent, setService, val): #used for now/next displaying - if len(self.epglist) > 1: - tmp = self.epglist[0] - self.epglist[0]=self.epglist[1] - self.epglist[1]=tmp - setEvent(self.epglist[0]) + epglist = self.epglist + if len(epglist) > 1: + tmp = epglist[0] + epglist[0]=epglist[1] + epglist[1]=tmp + setEvent(epglist[0]) class InfoBarRdsDecoder: """provides RDS and Rass support/display""" @@ -712,7 +714,7 @@ class InfoBarSeek: return False def getLower(self, n, lst): - lst = lst+[] + lst = lst[:] lst.reverse() for x in lst: if x < n: @@ -782,7 +784,7 @@ class InfoBarSeek: oldstate = self.seekstate self.seekstate = state - for i in range(3): + for i in (0, 1, 2): if oldstate[i] != self.seekstate[i]: (self.session.nav.pause, pauseable.setFastForward, pauseable.setSlowMotion)[i](self.seekstate[i]) @@ -1269,8 +1271,8 @@ class InfoBarExtensions: extensionsList.remove(extension) else: extensionsList.remove(extension) - for x in extensionsList: - list.append((x[0](), x)) + list.extend([(x[0](), x) for x in extensionsList]) + keys += [""] * len(extensionsList) self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list, keys = keys) @@ -1290,10 +1292,7 @@ class InfoBarPlugins: return name def getPluginList(self): - list = [] - for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EXTENSIONSMENU): - list.append(((boundFunction(self.getPluginName, p.name), boundFunction(self.runPlugin, p), lambda: True), None)) - return list + return [((boundFunction(self.getPluginName, p.name), boundFunction(self.runPlugin, p), lambda: True), None) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EXTENSIONSMENU)] def runPlugin(self, plugin): if isinstance(self, InfoBarChannelSelection): @@ -1307,10 +1306,7 @@ class InfoBarJobman: self.addExtension(extension = self.getJobList, type = InfoBarExtensions.EXTENSION_LIST) def getJobList(self): - list = [] - for job in job_manager.getPendingJobs(): - list.append(((boundFunction(self.getJobName, job), boundFunction(self.showJobView, job), lambda: True), None)) - return list + return [((boundFunction(self.getJobName, job), boundFunction(self.showJobView, job), lambda: True), None) for job in job_manager.getPendingJobs()] def getJobName(self, job): return "%s: %s (%d%%)" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end))) @@ -1468,7 +1464,7 @@ class InfoBarInstantRecord: simulTimerList = self.session.nav.RecordTimer.record(recording) if simulTimerList is not None: # conflict with other recording name = simulTimerList[1].name - name_date = name + strftime(" %c", localtime(simulTimerList[1].begin)) + name_date = ' '.join((name, strftime('%c', localtime(simulTimerList[1].begin)))) print "[TIMER] conflicts with", name_date recording.autoincrease = True # start with max available length, then increment if recording.setAutoincreaseEnd(): @@ -1550,10 +1546,11 @@ class InfoBarInstantRecord: def inputCallback(self, value): if value is not None: print "stopping recording after", int(value), "minutes." + entry = self.recording[self.selectedEntry] if int(value) != 0: - self.recording[self.selectedEntry].autoincrease = False - self.recording[self.selectedEntry].end = int(time()) + 60 * int(value) - self.session.nav.RecordTimer.timeChanged(self.recording[self.selectedEntry]) + entry.autoincrease = False + entry.end = int(time()) + 60 * int(value) + self.session.nav.RecordTimer.timeChanged(entry) def instantRecord(self): dir = config.movielist.last_videodir.value @@ -1569,22 +1566,22 @@ class InfoBarInstantRecord: if self.isInstantRecordRunning(): self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \ title=_("A recording is currently running.\nWhat do you want to do?"), \ - list=[(_("add recording (stop after current event)"), "event"), \ + list=((_("add recording (stop after current event)"), "event"), \ (_("add recording (enter recording duration)"), "manualduration"), \ (_("add recording (enter recording endtime)"), "manualendtime"), \ (_("add recording (indefinitely)"), "indefinitely"), \ (_("change recording (duration)"), "changeduration"), \ (_("change recording (endtime)"), "changeendtime"), \ (_("stop recording"), "stop"), \ - (_("do nothing"), "no")]) + (_("do nothing"), "no"))) else: self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \ title=_("Start recording?"), \ - list=[(_("add recording (stop after current event)"), "event"), \ + list=((_("add recording (stop after current event)"), "event"), \ (_("add recording (enter recording duration)"), "manualduration"), \ (_("add recording (enter recording endtime)"), "manualendtime"), \ (_("add recording (indefinitely)"), "indefinitely"), \ - (_("don't record"), "no")]) + (_("don't record"), "no"))) from Tools.ISO639 import LanguageCodes @@ -1603,8 +1600,9 @@ class InfoBarAudioSelection: if n > 0: self.audioChannel = service.audioChannel() - for x in range(n): - i = audio.getTrackInfo(x) + idx = 0 + while idx < n: + i = audio.getTrackInfo(idx) language = i.getLanguage() description = i.getDescription() @@ -1616,7 +1614,8 @@ class InfoBarAudioSelection: else: description = language - tlist.append((description, x)) + tlist.append((description, idx)) + idx += 1 tlist.sort(key=lambda x: x[0]) @@ -1663,7 +1662,7 @@ class InfoBarAudioSelection: if audio[1] == "mode": keys = ["red", "green", "yellow"] selection = self.audioChannel.getCurrentChannel() - tlist = [(_("left"), 0), (_("stereo"), 1), (_("right"), 2)] + tlist = ((_("left"), 0), (_("stereo"), 1), (_("right"), 2)) self.session.openWithCallback(self.modeSelected, ChoiceBox, title=_("Select audio mode"), list = tlist, selection = selection, keys = keys) else: del self.audioChannel @@ -1718,9 +1717,12 @@ class InfoBarSubserviceSelection: if n and n > 0: selection = -1 ref = self.session.nav.getCurrentlyPlayingServiceReference() - for x in range(n): - if subservices.getSubservice(x).toString() == ref.toString(): - selection = x + idx = 0 + while idx < n: + if subservices.getSubservice(idx).toString() == ref.toString(): + selection = idx + break + idx += 1 if selection != -1: selection += direction if selection >= n: @@ -1742,11 +1744,13 @@ class InfoBarSubserviceSelection: if n and n > 0: ref = self.session.nav.getCurrentlyPlayingServiceReference() tlist = [] - for x in range(n): - i = subservices.getSubservice(x) + idx = 0 + while idx < n: + i = subservices.getSubservice(idx) if i.toString() == ref.toString(): - selection = x + selection = idx tlist.append((i.getName(), i)) + idx += 1 if self.bouquets and len(self.bouquets): keys = ["red", "blue", "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n @@ -1823,10 +1827,11 @@ class InfoBarNotifications: self.checkNotifications() def checkNotifications(self): - if len(Notifications.notifications): - n = Notifications.notifications[0] + notifications = Notifications.notifications + if notifications: + n = notifications[0] - Notifications.notifications = Notifications.notifications[1:] + del notifications[0] cb = n[0] if n[3].has_key("onSessionOpenCallback"): @@ -1979,7 +1984,7 @@ class InfoBarCueSheetSupport: if bestdiff >= 0: nearest = [0, False] for cp in self.cut_list: - if beforecut and cp[1] in [self.CUT_TYPE_IN, self.CUT_TYPE_OUT]: + if beforecut and cp[1] in (self.CUT_TYPE_IN, self.CUT_TYPE_OUT): beforecut = False if cp[1] == self.CUT_TYPE_IN: # Start is here, disregard previous marks diff = cmp(cp[0] - pts) @@ -1988,7 +1993,7 @@ class InfoBarCueSheetSupport: bestdiff = diff else: nearest = None - if cp[1] in [self.CUT_TYPE_MARK, self.CUT_TYPE_LAST]: + if cp[1] in (self.CUT_TYPE_MARK, self.CUT_TYPE_LAST): diff = cmp(cp[0] - pts) if diff >= 0 and (nearest is None or bestdiff > diff): nearest = cp diff --git a/lib/python/Screens/LocationBox.py b/lib/python/Screens/LocationBox.py index 68d4f772..389d3624 100644 --- a/lib/python/Screens/LocationBox.py +++ b/lib/python/Screens/LocationBox.py @@ -326,7 +326,7 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen): def selectConfirmed(self, ret): if ret: - ret = ''.join([self.getPreferredFolder(), self.filename]) + ret = ''.join((self.getPreferredFolder(), self.filename)) if self.realBookmarks: if self.autoAdd and not ret in self.bookmarks: self.bookmarks.append(self.getPreferredFolder()) @@ -390,23 +390,28 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen): # Write Combination of Folder & Filename when Folder is valid currFolder = self.getPreferredFolder() if currFolder is not None: - self["target"].setText(''.join([currFolder, self.filename])) + self["target"].setText(''.join((currFolder, self.filename))) # Display a Warning otherwise else: self["target"].setText(_("Invalid Location")) def showMenu(self): if not self.userMode and self.realBookmarks: - menu = [] if self.currList == "filelist": - menu.append((_("switch to bookmarks"), self.switchToBookList)) - menu.append((_("add bookmark"), self.addRemoveBookmark)) + menu = [ + (_("switch to bookmarks"), self.switchToBookList), + (_("add bookmark"), self.addRemoveBookmark) + ] if self.editDir: - menu.append((_("create directory"), self.createDir)) - menu.append((_("remove directory"), self.removeDir)) + menu.extend(( + (_("create directory"), self.createDir), + (_("remove directory"), self.removeDir) + )) else: - menu.append((_("switch to filelist"), self.switchToFileList)) - menu.append((_("remove bookmark"), self.addRemoveBookmark)) + menu = ( + (_("switch to filelist"), self.switchToFileList) + (_("remove bookmark"), self.addRemoveBookmark) + ) self.session.openWithCallback( self.menuCallback, diff --git a/lib/python/Screens/PluginBrowser.py b/lib/python/Screens/PluginBrowser.py index 520d6d7a..0f6ee746 100644 --- a/lib/python/Screens/PluginBrowser.py +++ b/lib/python/Screens/PluginBrowser.py @@ -106,17 +106,18 @@ class PluginDownloadBrowser(Screen): if sel is None: return - if type(sel[0]) is str: # category - if sel[0] in self.expanded: - self.expanded.remove(sel[0]) + sel = sel[0] + if isinstance(sel, str): # category + if sel in self.expanded: + self.expanded.remove(sel) else: - self.expanded.append(sel[0]) + self.expanded.append(sel) self.updateList() else: if self.type == self.DOWNLOAD: - self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel[0].name) + self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name) elif self.type == self.REMOVE: - self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel[0].name) + self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name) def runInstall(self, val): if val: diff --git a/lib/python/Screens/ServiceInfo.py b/lib/python/Screens/ServiceInfo.py index e07b3208..df8af4b4 100644 --- a/lib/python/Screens/ServiceInfo.py +++ b/lib/python/Screens/ServiceInfo.py @@ -25,7 +25,7 @@ def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4): res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 30, 0, RT_HALIGN_LEFT, "")) res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 25, 0, RT_HALIGN_LEFT, a)) print "b:", b - if type(b) is not str: + if not isinstance(b, str): if valueType == TYPE_VALUE_HEX: b = ("0x%0" + str(param) + "x") % to_unsigned(b) elif valueType == TYPE_VALUE_DEC: diff --git a/lib/python/Screens/TimerEdit.py b/lib/python/Screens/TimerEdit.py index bb2d3c76..cdff4c5b 100644 --- a/lib/python/Screens/TimerEdit.py +++ b/lib/python/Screens/TimerEdit.py @@ -95,10 +95,11 @@ class TimerEditList(Screen): else: if t.isRunning(): if t.repeated: - list = [] - list.append((_("Stop current event but not coming events"), "stoponlycurrent")) - list.append((_("Stop current event and disable coming events"), "stopall")) - list.append((_("Don't stop current event but disable coming events"), "stoponlycoming")) + list = ( + (_("Stop current event but not coming events"), "stoponlycurrent"), + (_("Stop current event and disable coming events"), "stopall"), + (_("Don't stop current event but disable coming events"), "stoponlycoming") + ) self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list) else: t.disable() diff --git a/lib/python/Screens/TimerEntry.py b/lib/python/Screens/TimerEntry.py index 0544eff1..92a16af8 100644 --- a/lib/python/Screens/TimerEntry.py +++ b/lib/python/Screens/TimerEntry.py @@ -97,7 +97,7 @@ class TimerEntry(Screen, ConfigListScreen): self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type) self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False) self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False) - self.timerentry_tags = self.timer.tags + [] + self.timerentry_tags = self.timer.tags[:] self.timerentry_tagsset = ConfigSelection(choices = [len(self.timerentry_tags) == 0 and "None" or " ".join(self.timerentry_tags)]) self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))]) diff --git a/lib/python/Screens/Wizard.py b/lib/python/Screens/Wizard.py index feba8ac2..2326b915 100755 --- a/lib/python/Screens/Wizard.py +++ b/lib/python/Screens/Wizard.py @@ -1,7 +1,5 @@ from Screen import Screen -import string - from Screens.HelpMenu import HelpableScreen from Components.config import config, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS @@ -87,9 +85,9 @@ class Wizard(Screen): timeoutstep = '' self.wizard[self.lastStep] = {"id": id, "condition": "", "text": "", "timeout": timeout, "timeoutaction": timeoutaction, "timeoutstep": timeoutstep, "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": "", "codeafter": "", "code_async": "", "codeafter_async": "", "nextstep": nextstep} elif (name == "text"): - self.wizard[self.lastStep]["text"] = string.replace(str(attrs.get('value')), "\\n", "\n") + self.wizard[self.lastStep]["text"] = str(attrs.get('value')).replace("\\n", "\n") elif (name == "displaytext"): - self.wizard[self.lastStep]["displaytext"] = string.replace(str(attrs.get('value')), "\\n", "\n") + self.wizard[self.lastStep]["displaytext"] = str(attrs.get('value')).replace("\\n", "\n") elif (name == "list"): if (attrs.has_key('type')): if attrs["type"] == "dynamic": diff --git a/lib/python/Tools/Directories.py b/lib/python/Tools/Directories.py index 0d238b30..7dcd5876 100644 --- a/lib/python/Tools/Directories.py +++ b/lib/python/Tools/Directories.py @@ -172,7 +172,7 @@ def getRecordingFilename(basename, dirname = None): filename += c if dirname is not None: - filename = ''.join([dirname, filename]) + filename = ''.join((dirname, filename)) i = 0 while True: diff --git a/lib/python/Tools/RedirectOutput.py b/lib/python/Tools/RedirectOutput.py index b4d4e401..d03a1d97 100644 --- a/lib/python/Tools/RedirectOutput.py +++ b/lib/python/Tools/RedirectOutput.py @@ -3,7 +3,7 @@ from enigma import ePythonOutput class EnigmaOutput: def write(self, data): - if type(data) is unicode: + if isinstance(data, unicode): data = data.encode("UTF-8") ePythonOutput(data) diff --git a/skin.py b/skin.py index 011110a2..c8805f01 100644 --- a/skin.py +++ b/skin.py @@ -14,8 +14,6 @@ from Tools.Directories import resolveFilename, SCOPE_SKIN, SCOPE_SKIN_IMAGE, SCO from Tools.Import import my_import from Tools.LoadPixmap import LoadPixmap -from Tools.XMLTools import mergeText - colorNames = dict() def dump(x, i=0): @@ -474,13 +472,12 @@ def readSkin(screen, skin, names, desktop): ctype = converter.get('type') assert ctype, "'convert'-tag needs a 'type'-attribute" #print "Converter:", ctype - #parms = mergeText(converter.childNodes).strip() try: parms = converter.text.strip() except: parms = "" - #print "Params:", ctype - converter_class = my_import('.'.join(["Components", "Converter", ctype])).__dict__.get(ctype) + #print "Params:", parms + converter_class = my_import('.'.join(("Components", "Converter", ctype))).__dict__.get(ctype) c = None @@ -497,7 +494,7 @@ def readSkin(screen, skin, names, desktop): source = c - renderer_class = my_import('.'.join(["Components", "Renderer", wrender])).__dict__.get(wrender) + renderer_class = my_import('.'.join(("Components", "Renderer", wrender))).__dict__.get(wrender) renderer = renderer_class() # instantiate renderer diff --git a/timer.py b/timer.py index 750a8c03..fd5bb5af 100644 --- a/timer.py +++ b/timer.py @@ -66,7 +66,7 @@ class TimerEntry: day = [] flags = self.repeated - for x in range(0, 7): + for x in (0, 1, 2, 3, 4, 5, 6): if (flags & 1 == 1): day.append(0) print "Day: " + str(x)