Commit 6e410949 authored by murban's avatar murban
Browse files

Raise warning when trying to access a folder without permission. Fix a small...

Raise warning when trying to access a folder without permission. Fix a small bug in the remote filesystem: Line indentation of the parentfolder has been wrong
parent 0ab07dc2
...@@ -89,19 +89,6 @@ class FSAjaxController(AbstractController): ...@@ -89,19 +89,6 @@ class FSAjaxController(AbstractController):
vispa.log_exception() vispa.log_exception()
return self.fail(msg='Couldn\'t load files: %s' % str(e), encode_json=True) return self.fail(msg='Couldn\'t load files: %s' % str(e), encode_json=True)
@cherrypy.expose
@cherrypy.tools.allow(methods=['POST', 'GET'])
@cherrypy.tools.json_out()
def folderup(self, path):
try:
path = os.path.expanduser(os.path.expandvars(path))
path = path[:-1] if path.endswith(os.sep) and path!=os.sep else path
path = os.path.dirname(path)
path = self.convert(path, 'string')
return self.success({'folderuppath': path})
except Exception, e:
return self.fail(msg='Couldn\'t load files: %s' % str(e))
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.allow(methods=['POST', 'GET']) @cherrypy.tools.allow(methods=['POST', 'GET'])
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
......
...@@ -72,38 +72,41 @@ class FileSystem(object): ...@@ -72,38 +72,41 @@ class FileSystem(object):
def get_file_list(self, path, deep=False, filter=[], reverse=False, hide_hidden=True, encode_json=False): def get_file_list(self, path, deep=False, filter=[], reverse=False, hide_hidden=True, encode_json=False):
filelist = [] filelist = []
path_expand = os.path.expanduser(os.path.expandvars(path)) path_expand = os.path.expanduser(os.path.expandvars(path))
for elem in os.listdir(path_expand): try:
# hide hidden files? for elem in os.listdir(path_expand):
if elem.startswith('.') and hide_hidden: # hide hidden files?
continue if elem.startswith('.') and hide_hidden:
continue
# excluded by filters?
match = False # excluded by filters?
for filter_elem in filter: match = False
if re.search(filter_elem, elem): for filter_elem in filter:
match = True if re.search(filter_elem, elem):
if match != reverse: match = True
continue if match != reverse:
continue
fullpath = os.path.join(path_expand, elem)
fullpath = os.path.join(path_expand, elem)
# get locales, mtime, etc
locale.setlocale(locale.LC_ALL, '') # get locales, mtime, etc
stats = os.stat(path_expand) locale.setlocale(locale.LC_ALL, '')
size = locale.format('%d', stats.st_size, grouping=True) stats = os.stat(path_expand)
mtime = datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S') size = locale.format('%d', stats.st_size, grouping=True)
mtime = datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S')
if os.path.isdir(fullpath):
filelist.append({'name': elem, 'type': 'd', 'parent': path, 'extension': '', 'mtime': mtime, 'size': size, 'path': fullpath}) if os.path.isdir(fullpath):
if deep: filelist.append({'name': elem, 'type': 'd', 'parent': path, 'extension': '', 'mtime': mtime, 'size': size, 'path': fullpath})
filelist.extend(self.get_file_list(fullpath, deep, filter, reverse)) if deep:
else: filelist.extend(self.get_file_list(fullpath, deep, filter, reverse))
extension = elem.split('.')[-1] else:
filelist.append({'name': elem, 'type': 'f', 'parent': path, 'extension': extension, 'mtime': mtime, 'size': size, 'path': fullpath}) extension = elem.split('.')[-1]
filelist.append({'name': elem, 'type': 'f', 'parent': path, 'extension': extension, 'mtime': mtime, 'size': size, 'path': fullpath})
# Determine the parent except Exception, e:
parentpath = path_expand[:-1] if path_expand.endswith(os.sep) and path_expand!=os.sep else path_expand filelist.append({'warning': str(e)})
parentpath = os.path.dirname(path_expand)
# Determine the parent
parentpath = path_expand[:-1] if path_expand.endswith(os.sep) and path_expand!=os.sep else path_expand
parentpath = os.path.dirname(path_expand)
data = {'filelist': filelist, 'parentpath': parentpath} data = {'filelist': filelist, 'parentpath': parentpath}
if encode_json: if encode_json:
return json.dumps(data) return json.dumps(data)
......
...@@ -48,7 +48,11 @@ var Symbolview = Class.extend({ ...@@ -48,7 +48,11 @@ var Symbolview = Class.extend({
_this.owner.view.mainContainer.append(folderup); _this.owner.view.mainContainer.append(folderup);
$.each(data.filelist, function(i, file) { $.each(data.filelist, function(i, file) {
var contentdiv = _this.makeIcon(file); if (file.warning) {
alert(file.warning)
} else {
var contentdiv = _this.makeIcon(file);
};
// owner.view.mainContainer.isotope('insert', contentdiv); // owner.view.mainContainer.isotope('insert', contentdiv);
_this.owner.view.mainContainer.append(contentdiv); _this.owner.view.mainContainer.append(contentdiv);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment