From d806a9ce9ed269e53c256d747dba46810f78eb87 Mon Sep 17 00:00:00 2001 From: Surinder Kumar Date: Fri, 21 Oct 2016 12:43:02 +0100 Subject: [PATCH] Fix the file manager when used under Python 3. Fixes #1872 Issues fixed: 1) In Python 3, parameter "cmp" is removed from sorted method. So File Manager won't open. As we are sorting data on JS side using Natural sort, so on server side sorting is not required. 2) Improvement in Exception handling. --- web/pgadmin/misc/file_manager/__init__.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 5c6a908c7..4a8e7094c 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -441,11 +441,7 @@ class Filemanager(object): orig_path = unquote(orig_path) try: - def custom_sort(x, y): - return y.lower() > x.lower() - - mylist = [x for x in sorted(os.listdir(orig_path), - cmp=custom_sort)] + mylist = [x for x in sorted(os.listdir(orig_path))] for f in mylist: protected = 0 system_path = os.path.join(os.path.join(orig_path, f)) @@ -491,10 +487,11 @@ class Filemanager(object): } } except Exception as e: - if e.strerror == gettext('Permission denied'): + if (hasattr(e, 'strerror') and + e.strerror == gettext('Permission denied')): err_msg = "Error: {0}".format(e.strerror) else: - err_msg = "Error: {0}".format(e.strerror) + err_msg = "Error: {0}".format(e) files = { 'Code': 0, 'err_msg': err_msg