Settings, directory browser

This commit is contained in:
Ruud
2011-09-05 22:09:54 +02:00
parent 6430014c56
commit 1e36aeced3
13 changed files with 208 additions and 180 deletions
+17 -1
View File
@@ -1,6 +1,7 @@
from couchpotato.api import addApiView
from couchpotato.core.helpers.request import getParam, jsonified
from couchpotato.core.plugins.base import Plugin
import ctypes
import os
import string
@@ -23,7 +24,7 @@ class FileBrowser(Plugin):
dirs = []
for f in os.listdir(path):
p = os.path.join(path, f)
if(os.path.isdir(p)):
if os.path.isdir(p) and ((self.is_hidden(p) and bool(int(show_hidden))) or not self.is_hidden(p)):
dirs.append(p + '/')
return dirs
@@ -48,6 +49,21 @@ class FileBrowser(Plugin):
dirs = []
return jsonified({
'is_root': getParam('path', '/') == '/',
'empty': len(dirs) == 0,
'dirs': dirs,
})
def is_hidden(self, filepath):
name = os.path.basename(os.path.abspath(filepath))
return name.startswith('.') or self.has_hidden_attribute(filepath)
def has_hidden_attribute(self, filepath):
try:
attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath))
assert attrs != -1
result = bool(attrs & 2)
except (AttributeError, AssertionError):
result = False
return result