Improved folder select
This commit is contained in:
@@ -27,6 +27,8 @@ class FileBrowser(Plugin):
|
||||
},
|
||||
'return': {'type': 'object', 'example': """{
|
||||
'is_root': bool, //is top most folder
|
||||
'parent': string, //parent folder of requested path
|
||||
'home': string, //user home folder
|
||||
'empty': bool, //directory is empty
|
||||
'dirs': array, //directory names
|
||||
}"""}
|
||||
@@ -64,14 +66,35 @@ class FileBrowser(Plugin):
|
||||
|
||||
path = getParam('path', '/')
|
||||
|
||||
# Set proper home dir for some systems
|
||||
try:
|
||||
import pwd
|
||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
||||
except:
|
||||
pass
|
||||
|
||||
home = os.path.expanduser('~')
|
||||
|
||||
if not path:
|
||||
path = home
|
||||
|
||||
try:
|
||||
dirs = self.getDirectories(path = path, show_hidden = getParam('show_hidden', True))
|
||||
except:
|
||||
dirs = []
|
||||
|
||||
parent = os.path.dirname(path.rstrip(os.path.sep))
|
||||
if parent == path.rstrip(os.path.sep):
|
||||
parent = '/'
|
||||
elif parent != '/' and parent[-2:] != ':\\':
|
||||
parent += os.path.sep
|
||||
|
||||
return jsonified({
|
||||
'is_root': path == '/' or not path,
|
||||
'is_root': path == '/',
|
||||
'empty': len(dirs) == 0,
|
||||
'parent': parent,
|
||||
'home': home + os.path.sep,
|
||||
'platform': os.name,
|
||||
'dirs': dirs,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user