Settings, directory browser
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user