From 02a3919b0627dc27c4deecc38b17f6e75acb0051 Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Mon, 3 Apr 2017 18:55:21 +0530 Subject: [PATCH] As per Murtuza, we will have the '__module__', when running as a WSGI application, but - it will not have the '__file__' attribute. --- web/pgadmin/browser/server_groups/servers/types.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/types.py b/web/pgadmin/browser/server_groups/servers/types.py index a002d2cf5..697c8eafe 100644 --- a/web/pgadmin/browser/server_groups/servers/types.py +++ b/web/pgadmin/browser/server_groups/servers/types.py @@ -113,9 +113,17 @@ class ServerType(object): )) ) bin_path = self.utility_path.get() - # AS WSGI application, we will not find the '__main__' module. - if "__main__" in sys.modules: - bin_path = bin_path.replace("$DIR", os.path.dirname(sys.modules['__main__'].__file__)) + if "$DIR" in bin_path: + # When running as an WSGI application, we will not find the + # '__file__' attribute for the '__main__' module. + main_module_file = getattr( + sys.modules['__main__'], '__file__', None + ) + + if main_module_file is None: + bin_path = bin_path.replace( + "$DIR", os.path.dirname(main_module_file) + ) return os.path.abspath(os.path.join( bin_path,