aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components
diff options
context:
space:
mode:
authorghost <andreas.monzner@multimedia-labs.de>2009-02-12 21:25:08 +0100
committerghost <andreas.monzner@multimedia-labs.de>2009-02-12 21:25:08 +0100
commit76e5181cade262b86610dcc851bcb4452196ccdc (patch)
tree25831b32e1543b893a033729e472dd679dffdc64 /lib/python/Components
parent00248c1a8794e64b8ce82d9cdefdd3ddae98dffd (diff)
downloadenigma2-76e5181cade262b86610dcc851bcb4452196ccdc.tar.gz
enigma2-76e5181cade262b86610dcc851bcb4452196ccdc.zip
small speedups/cleanups by moritz venn
Diffstat (limited to 'lib/python/Components')
-rw-r--r--lib/python/Components/About.py2
-rw-r--r--lib/python/Components/ActionMap.py4
-rw-r--r--lib/python/Components/EpgList.py88
-rw-r--r--lib/python/Components/Harddisk.py8
-rwxr-xr-xlib/python/Components/HelpMenuList.py2
-rw-r--r--lib/python/Components/PluginComponent.py4
-rw-r--r--lib/python/Components/Scanner.py46
-rw-r--r--lib/python/Components/ServiceList.py4
-rw-r--r--lib/python/Components/TimerList.py2
-rw-r--r--lib/python/Components/TimerSanityCheck.py2
-rw-r--r--lib/python/Components/UsageConfig.py2
11 files changed, 82 insertions, 82 deletions
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: