Fix problem with the logic of the top directory
authorDima73 <Dima-73@inbox.lv>
Sat, 13 Jun 2015 06:35:09 +0000 (09:35 +0300)
committerlittlesat <littlesat99@yahoo.com>
Sat, 13 Jun 2015 08:10:48 +0000 (10:10 +0200)
see
http://forums.openpli.org/topic/38123-bug-in-timesanitycheck/?view=findpost&p=493866

Signed-off-by: littlesat <littlesat99@yahoo.com>

lib/python/Components/FileList.py

index bfee642..9d4537d 100644 (file)
@@ -66,12 +66,15 @@ class FileList(MenuList):
                self.showDirectories = showDirectories
                self.showMountpoints = showMountpoints
                self.showFiles = showFiles
-               self.isTop = isTop
+               if isTop:
+                       self.topDirectory = directory
+               else:
+                       self.topDirectory = "/"
                # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
                if matchingPattern:
                        self.matchingPattern = re.compile(matchingPattern)
                else:
-                       self.matchingPattern = None
+                       self.matchingPattern = None
                self.inhibitDirs = inhibitDirs or []
                self.inhibitMounts = inhibitMounts or []
 
@@ -184,13 +187,12 @@ 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.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:
+                       if directory:
+                               if self.showMountpoints and directory == self.current_mountpoint:
+                                       self.list.append(FileEntryComponent(name = "<" +_("List of storage devices") + ">", absolute = None, isDir = True))
+                               elif (directory != self.topDirectory) 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))
                        for x in directories:
                                if not (self.inhibitMounts and self.getMountpoint(x) in self.inhibitMounts) and not self.inParentDirs(x, self.inhibitDirs):
                                        name = x.split('/')[-2]
@@ -301,7 +303,7 @@ class MultiFileSelectList(FileList):
                if preselectedFiles is None:
                        self.selectedFiles = []
                else:
-                       self.selectedFiles = preselectedFiles
+                       self.selectedFiles = preselectedFiles
                FileList.__init__(self, directory, showMountpoints = showMountpoints, matchingPattern = matchingPattern, showDirectories = showDirectories, showFiles = showFiles,  useServiceRef = useServiceRef, inhibitDirs = inhibitDirs, inhibitMounts = inhibitMounts, isTop = isTop, enableWrapAround = enableWrapAround, additionalExtensions = additionalExtensions)
                self.changeDir(directory)
                font = skin.fonts.get("FileListMulti", ("Regular", 20, 25))
@@ -330,7 +332,7 @@ class MultiFileSelectList(FileList):
                                        try:
                                                self.selectedFiles.remove(os.path.normpath(realPathname))
                                        except:
-                                               print "Couldn't remove:", realPathname
+                                               print "Couldn't remove:", realPathname
                        else:
                                SelectState = True
                                if (realPathname not in self.selectedFiles) and (os.path.normpath(realPathname) not in self.selectedFiles):
@@ -396,13 +398,12 @@ class MultiFileSelectList(FileList):
                                                directories.append(directory + x + "/")
                                                files.remove(x)
 
-               if directory is not None and self.showDirectories and not self.isTop:
-                       if directory == self.current_mountpoint and self.showMountpoints:
-                               self.list.append(MultiFileSelectEntryComponent(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(MultiFileSelectEntryComponent(name = "<" +_("Parent directory") + ">", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
-
                if self.showDirectories:
+                       if directory:
+                               if self.showMountpoints and directory == self.current_mountpoint:
+                                       self.list.append(FileEntryComponent(name = "<" +_("List of storage devices") + ">", absolute = None, isDir = True))
+                               elif (directory != self.topDirectory) 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))
                        for x in directories:
                                if not (self.inhibitMounts and self.getMountpoint(x) in self.inhibitMounts) and not self.inParentDirs(x, self.inhibitDirs):
                                        name = x.split('/')[-2]
@@ -438,4 +439,3 @@ class MultiFileSelectList(FileList):
                                if p == select:
                                        self.moveToIndex(i)
                                i += 1
-