aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/Components')
-rw-r--r--lib/python/Components/FileList.py94
-rw-r--r--lib/python/Components/config.py321
2 files changed, 292 insertions, 123 deletions
diff --git a/lib/python/Components/FileList.py b/lib/python/Components/FileList.py
index fcd1555f..5824747d 100644
--- a/lib/python/Components/FileList.py
+++ b/lib/python/Components/FileList.py
@@ -42,23 +42,52 @@ def FileEntryComponent(name, absolute = None, isDir = False):
return res
class FileList(MenuList):
- def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False, enableWrapAround = False, additionalExtensions = None):
+ def __init__(self, directory, showDirectories = True, showFiles = True, showMountpoints = True, matchingPattern = None, useServiceRef = False, inhibitDirs = False, inhibitMounts = False, enableWrapAround = False, additionalExtensions = None):
MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
self.additional_extensions = additionalExtensions
- self.mount_point = None
+ self.mountpoints = []
self.current_directory = None
+ self.current_mountpoint = None
self.useServiceRef = useServiceRef
self.showDirectories = showDirectories
+ self.showMountpoints = showMountpoints
self.showFiles = showFiles
- self.isTop = isTop
# example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
self.matchingPattern = matchingPattern
- self.changeDir(directory)
+ self.inhibitDirs = inhibitDirs or []
+ self.inhibitMounts = inhibitMounts or []
+ self.refreshMountpoints()
+ self.changeDir(directory)
self.l.setFont(0, gFont("Regular", 18))
self.l.setItemHeight(23)
self.serviceHandler = eServiceCenter.getInstance()
+ def refreshMountpoints(self):
+ self.mountpoints = [os_path.join(p.mountpoint, "") for p in harddiskmanager.getMountedPartitions()]
+ self.mountpoints.sort(reverse = True)
+
+ def getMountpoint(self, file):
+ file = os_path.join(os_path.realpath(file), "")
+ for m in self.mountpoints:
+ if file.startswith(m):
+ return m
+ return False
+
+ def getMountpointLink(self, file):
+ if os_path.realpath(file) == file:
+ return self.getMountpoint(file)
+ else:
+ if file[-1] == "/":
+ file = file[:-1]
+ mp = self.getMountpoint(file)
+ last = file
+ file = os_path.dirname(file)
+ while last != "/" and mp == self.getMountpoint(file):
+ last = file
+ file = os_path.dirname(file)
+ return os_path.join(last, "")
+
def getSelection(self):
if self.l.getCurrentSelection() is None:
return None
@@ -74,36 +103,33 @@ class FileList(MenuList):
def getFileList(self):
return self.list
+ def inParentDirs(self, dir, parents):
+ dir = os_path.realpath(dir)
+ for p in parents:
+ if dir.startswith(p):
+ return True
+ return False
+
def changeDir(self, directory, select = None):
self.list = []
+ if directory and not os_path.isdir(directory):
+ directory = None
# if we are just entering from the list of mount points:
if self.current_directory is None:
- if directory is None:
- self.mount_point = None
+ if directory and self.showMountpoints:
+ self.current_mountpoint = self.getMountpointLink(directory)
else:
- # Sort Mountpoints by length (longest first)
- sortedp = harddiskmanager.getMountedPartitions()
- sortedp.sort(key=lambda p: 0 - len(p.mountpoint))
-
- # Search for the longest matching mp (should at least match /)
- for p in sortedp:
- if directory.startswith(p.mountpoint):
- self.mount_point = p.mountpoint
- if p.mountpoint != "/":
- self.mount_point += "/"
- break
+ self.current_mountpoint = None
self.current_directory = directory
directories = []
files = []
- if directory is None: # present available mountpoints
- print "listing partitions:"
+ if directory is None and self.showMountpoints: # present available mountpoints
for p in harddiskmanager.getMountedPartitions():
- if p.mountpoint == "/":
- self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint, isDir = True))
- else:
- self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint + "/", isDir = True))
+ path = os_path.join(p.mountpoint,"")
+ if not self.inhibitMounts or ((not path in self.inhibitMounts) and (not self.inParentDirs(path, self.inhibitDirs))):
+ self.list.append(FileEntryComponent(name = p.description, absolute = path, isDir = True))
files = [ ]
directories = [ ]
elif self.useServiceRef:
@@ -122,7 +148,6 @@ class FileList(MenuList):
directories.append(s.getPath())
else:
files.append(s)
- print s.getName(), s.flags
directories.sort()
files.sort()
else:
@@ -135,16 +160,17 @@ class FileList(MenuList):
directories.append(directory + x + "/")
files.remove(x)
- if directory is not None and self.showDirectories and not self.isTop:
- if directory == self.mount_point:
- self.list.append(FileEntryComponent(name = ".. (" +_("List of Storage Devices") + ")", absolute = None, isDir = True))
- else:
- self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
+ if directory is not None and self.showDirectories:
+ if directory == self.current_mountpoint and self.showMountpoints:
+ self.list.append(FileEntryComponent(name = "<" +_("List of Storage Devices") + ">", absolute = None, isDir = True))
+ elif (directory != "/") and not (self.inhibitMounts and self.getMountpoint(directory) in self.inhibitMounts):
+ self.list.append(FileEntryComponent(name = "<" +_("Parent Directory") + ">", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
if self.showDirectories:
for x in directories:
- name = x.split('/')[-2]
- self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True))
+ if not (self.inhibitMounts and self.getMountpoint(x) in self.inhibitMounts) and not self.inParentDirs(x, self.inhibitDirs):
+ name = x.split('/')[-2]
+ self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True))
if self.showFiles:
for x in files:
@@ -155,10 +181,7 @@ class FileList(MenuList):
path = directory + x
name = x
- if self.matchingPattern is not None:
- if re.compile(self.matchingPattern).search(path):
- self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
- else:
+ if (self.matchingPattern is None) or re.compile(self.matchingPattern).search(path):
self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
self.l.setList(self.list)
@@ -215,5 +238,6 @@ class FileList(MenuList):
self.changeDir(self.current_directory, self.getFilename())
def partitionListChanged(self, action, device):
+ self.refreshMountpoints()
if self.current_directory is None:
self.refresh()
diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py
index b0f5fe6d..529b6020 100644
--- a/lib/python/Components/config.py
+++ b/lib/python/Components/config.py
@@ -2,8 +2,9 @@ import time
from enigma import getPrevAsciiCode
from Tools.NumericalTextInput import NumericalTextInput
from Tools.Directories import resolveFilename, SCOPE_CONFIG
+from Components.Harddisk import harddiskmanager
import copy
-
+import os
# ConfigElement, the base class of all ConfigElements.
@@ -845,6 +846,237 @@ class ConfigSatlist(ConfigSelection):
orbital_position = property(getOrbitalPosition)
+class ConfigSet(ConfigElement):
+ def __init__(self, choices, default = []):
+ ConfigElement.__init__(self)
+ self.choices = []
+ self.description = {}
+ if isinstance(choices, list):
+ choices.sort()
+ for x in choices:
+ if isinstance(x, tuple):
+ self.choices.append(x[0])
+ self.description[x[0]] = str(x[1])
+ else:
+ self.choices.append(x)
+ self.description[x] = str(x)
+ else:
+ assert False, "ConfigSet choices must be a list!"
+ if len(self.choices) == 0:
+ self.choices = [""]
+ self.description[""] = ""
+ if default is None:
+ default = []
+ self.pos = -1
+ default.sort()
+ self.default = default
+ self.value = default+[]
+
+ def toggleChoice(self, choice):
+ if choice in self.value:
+ self.value.remove(choice)
+ else:
+ self.value.append(choice)
+ self.value.sort()
+
+ def handleKey(self, key):
+ if key in KEY_NUMBERS + [KEY_DELETE, KEY_BACKSPACE]:
+ if self.pos != -1:
+ self.toggleChoice(self.choices[self.pos])
+ elif key == KEY_LEFT:
+ self.pos -= 1
+ if self.pos < -1:
+ self.pos = len(self.choices)-1
+ elif key == KEY_RIGHT:
+ self.pos += 1
+ if self.pos >= len(self.choices):
+ self.pos = -1
+ elif key in [KEY_HOME, KEY_END]:
+ self.pos = -1
+
+ def genString(self, lst):
+ res = ""
+ for x in lst:
+ res += self.description[x]+" "
+ return res
+
+ def getText(self):
+ return self.genString(self.value)
+
+ def getMulti(self, selected):
+ if not selected or self.pos == -1:
+ return ("text", self.genString(self.value))
+ else:
+ tmp = self.value+[]
+ ch = self.choices[self.pos]
+ mem = ch in self.value
+ if not mem:
+ tmp.append(ch)
+ tmp.sort()
+ ind = tmp.index(ch)
+ val1 = self.genString(tmp[:ind])
+ val2 = " "+self.genString(tmp[ind+1:])
+ if mem:
+ chstr = " "+self.description[ch]+" "
+ else:
+ chstr = "("+self.description[ch]+")"
+ return ("mtext", val1+chstr+val2, range(len(val1),len(val1)+len(chstr)))
+
+ def onDeselect(self, session):
+ self.pos = -1
+ self.changed()
+
+ def tostring(self, value):
+ return str(value)
+
+ def fromstring(self, val):
+ return eval(val)
+
+class ConfigLocations(ConfigElement):
+ def __init__(self, default = [], visible_width = False):
+ ConfigElement.__init__(self)
+ self.pos = -1
+ self.default = default
+ self.locations = []
+ self.mountpoints = []
+ harddiskmanager.on_partition_list_change.append(self.mountpointsChanged)
+
+ def setValue(self, value):
+ loc = [x[0] for x in self.locations if x[3]]
+ add = [x for x in value if not x in loc]
+ diff = add + [x for x in loc if not x in value]
+ self.locations = [x for x in self.locations if not x[0] in diff] + [[x, self.getMountpoint(x), True, True] for x in add]
+ self.locations.sort(key = lambda x: x[0])
+ self.changed()
+
+ def getValue(self):
+ self.checkChangedMountpoints()
+ for x in self.locations:
+ x[3] = x[2]
+ return [x[0] for x in self.locations if x[3]]
+
+ value = property(getValue, setValue)
+
+ def tostring(self, value):
+ return str(value)
+
+ def fromstring(self, val):
+ return eval(val)
+
+ def load(self):
+ if self.saved_value is None:
+ tmp = self.default
+ else:
+ tmp = self.fromstring(self.saved_value)
+ self.locations = [[x, None, False, False] for x in tmp]
+ self.refreshMountpoints()
+ for x in self.locations:
+ if os.path.exists(x[0]):
+ x[1] = self.getMountpoint(x[0])
+ x[2] = True
+
+ def save(self):
+ if self.save_disabled or self.locations == []:
+ self.saved_value = None
+ else:
+ self.saved_value = self.tostring([x[0] for x in self.locations])
+
+ def isChanged(self):
+ if self.saved_value is None and self.locations == []:
+ return False
+ return self.tostring([x[0] for x in self.locations]) != self.saved_value
+
+ def mountpointsChanged(self, action, dev):
+ print "Mounts changed: ", action, dev
+ mp = dev.mountpoint+"/"
+ if action == "add":
+ self.addedMount(mp)
+ elif action == "remove":
+ self.removedMount(mp)
+ self.refreshMountpoints()
+
+ def addedMount(self, mp):
+ for x in self.locations:
+ if x[1] == mp:
+ x[2] = True
+ elif x[1] == None and os.path.exists(x[0]):
+ x[1] = self.getMountpoint(x[0])
+ x[2] = True
+
+ def removedMount(self, mp):
+ for x in self.locations:
+ if x[1] == mp:
+ x[2] = False
+
+ def refreshMountpoints(self):
+ self.mountpoints = [p.mountpoint + "/" for p in harddiskmanager.getMountedPartitions() if p.mountpoint != "/"]
+ self.mountpoints.sort(key = lambda x: -len(x))
+
+ def checkChangedMountpoints(self):
+ oldmounts = self.mountpoints
+ self.refreshMountpoints()
+ if oldmounts == self.mountpoints:
+ return
+ for x in oldmounts:
+ if not x in self.mountpoints:
+ self.removedMount(x)
+ for x in self.mountpoints:
+ if not x in oldmounts:
+ self.addedMount(x)
+
+ def getMountpoint(self, file):
+ file = os.path.realpath(file)+"/"
+ for m in self.mountpoints:
+ if file.startswith(m):
+ return m
+ return None
+
+ def handleKey(self, key):
+ if key == KEY_LEFT:
+ self.pos -= 1
+ if self.pos < -1:
+ self.pos = len(self.value)-1
+ elif key == KEY_RIGHT:
+ self.pos += 1
+ if self.pos >= len(self.value):
+ self.pos = -1
+ elif key in [KEY_HOME, KEY_END]:
+ self.pos = -1
+
+ def getText(self):
+ return " ".join(self.value)
+
+ def getMulti(self, selected):
+ if not selected:
+ valstr = " ".join(self.value)
+ if self.visible_width and len(valstr) > self.visible_width:
+ return ("text", valstr[0:self.visible_width])
+ else:
+ return ("text", valstr)
+ else:
+ i = 0
+ valstr = ""
+ ind1 = 0
+ ind2 = 0
+ for val in self.value:
+ if i == self.pos:
+ ind1 = len(valstr)
+ valstr += str(val)+" "
+ if i == self.pos:
+ ind2 = len(valstr)
+ i += 1
+ if self.visible_width and len(valstr) > self.visible_width:
+ if ind1+1 < self.visible_width/2:
+ off = 0
+ else:
+ off = min(ind1+1-self.visible_width/2, len(valstr)-self.visible_width)
+ return ("mtext", valstr[off:off+self.visible_width], range(ind1-off,ind2-off))
+ else:
+ return ("mtext", valstr, range(ind1,ind2))
+
+ def onDeselect(self, session):
+ self.pos = -1
+
# nothing.
class ConfigNothing(ConfigSelection):
def __init__(self):
@@ -1023,93 +1255,6 @@ class ConfigSubsection(object):
def dict(self):
return self.content.items
-class ConfigSet(ConfigElement):
- def __init__(self, choices, default = []):
- ConfigElement.__init__(self)
- self.choices = []
- self.description = {}
- if isinstance(choices, list):
- choices.sort()
- for x in choices:
- if isinstance(x, tuple):
- self.choices.append(x[0])
- self.description[x[0]] = str(x[1])
- else:
- self.choices.append(x)
- self.description[x] = str(x)
- else:
- assert False, "ConfigSet choices must be a list!"
- if len(self.choices) == 0:
- self.choices = [""]
- self.description[""] = ""
- if default is None:
- default = []
- self.pos = -1
- default.sort()
- self.default = default
- self.value = default+[]
-
- def toggleChoice(self, choice):
- if choice in self.value:
- self.value.remove(choice)
- else:
- self.value.append(choice)
- self.value.sort()
-
- def handleKey(self, key):
- if key in KEY_NUMBERS + [KEY_DELETE, KEY_BACKSPACE]:
- if self.pos != -1:
- self.toggleChoice(self.choices[self.pos])
- elif key == KEY_LEFT:
- self.pos -= 1
- if self.pos < -1:
- self.pos = len(self.choices)-1
- elif key == KEY_RIGHT:
- self.pos += 1
- if self.pos >= len(self.choices):
- self.pos = -1
- elif key in [KEY_HOME, KEY_END]:
- self.pos = -1
-
- def genString(self, lst):
- res = ""
- for x in lst:
- res += self.description[x]+" "
- return res
-
- def getText(self):
- return self.genString(self.value)
-
- def getMulti(self, selected):
- if not selected or self.pos == -1:
- return ("text", self.genString(self.value))
- else:
- tmp = self.value+[]
- ch = self.choices[self.pos]
- mem = ch in self.value
- if not mem:
- tmp.append(ch)
- tmp.sort()
- ind = tmp.index(ch)
- val1 = self.genString(tmp[:ind])
- val2 = " "+self.genString(tmp[ind+1:])
- if mem:
- chstr = " "+self.description[ch]+" "
- else:
- chstr = "("+self.description[ch]+")"
- return ("mtext", val1+chstr+val2, range(len(val1),len(val1)+len(chstr)))
-
- def onDeselect(self, session):
- self.pos = -1
- self.changed()
-
- def tostring(self, value):
- return str(value)
-
- def fromstring(self, val):
- return eval(val)
-
-
# the root config object, which also can "pickle" (=serialize)
# down the whole config tree.
#