1) Added browse button to select the binary path in the Preferences. Fixes #1561

2) Added support to set the binary path for the different database server versions. Fixes #5370
This commit is contained in:
Akshay Joshi
2021-06-04 17:55:35 +05:30
parent ac8e8961ce
commit 4bc4ca1ba9
26 changed files with 930 additions and 302 deletions
@@ -11,10 +11,11 @@ define('pgadmin.node.mview', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
'sources/pgadmin', 'pgadmin.alertifyjs', 'pgadmin.browser',
'pgadmin.backform', 'pgadmin.node.schema.dir/child',
'pgadmin.node.schema.dir/schema_child_tree_node', 'pgadmin.browser.server.privilege',
'pgadmin.node.schema.dir/schema_child_tree_node', 'sources/utils',
'pgadmin.browser.server.privilege',
], function(
gettext, url_for, $, _, pgAdmin, Alertify, pgBrowser, Backform,
schemaChild, schemaChildTreeNode
schemaChild, schemaChildTreeNode, commonUtils
) {
/**
@@ -316,25 +317,7 @@ define('pgadmin.node.mview', [
return;
}
var module = 'paths',
preference_name = 'pg_bin_dir',
msg = gettext('Please configure the PostgreSQL Binary Path in the Preferences dialog.');
if ((server_data.type && server_data.type == 'ppas') ||
server_data.server_type == 'ppas') {
preference_name = 'ppas_bin_dir';
msg = gettext('Please configure the EDB Advanced Server Binary Path in the Preferences dialog.');
}
var preference = pgBrowser.get_preference(module, preference_name);
if (preference) {
if (!preference.value) {
Alertify.alert(gettext('Configuration required'), msg);
return;
}
} else {
Alertify.alert(gettext('Failed to load preference %s of module %s', preference_name, module));
if (!commonUtils.hasBinariesConfiguration(pgBrowser, server_data, this.alertify)) {
return;
}
@@ -9,14 +9,13 @@
import os
import sys
import json
from flask import render_template
from flask_babelex import gettext as _
from pgadmin.utils.preferences import Preferences
from werkzeug.exceptions import InternalServerError
import config
class ServerType(object):
"""
@@ -61,14 +60,18 @@ class ServerType(object):
for key in cls.registry:
st = cls.registry[key]
default_path = config.DEFAULT_BINARY_PATHS.get(st.stype, "")
st.utility_path = paths.register(
'bin_paths', st.stype + '_bin_dir',
st.UTILITY_PATH_LABEL,
'text', default_path, category_label=_('Binary paths'),
help_str=st.UTILITY_PATH_HELP
)
if key == 'pg':
st.utility_path = paths.register(
'bin_paths', 'pg_bin_dir',
_("PostgreSQL Binary Path"), 'selectFile', None,
category_label=_('Binary paths')
)
elif key == 'ppas':
st.utility_path = paths.register(
'bin_paths', 'ppas_bin_dir',
_("EDB Advanced Server Binary Path"), 'selectFile', None,
category_label=_('Binary paths')
)
@property
def priority(self):
@@ -120,7 +123,8 @@ class ServerType(object):
operation
)
)
bin_path = self.utility_path.get()
bin_path = self.get_utility_path(sversion)
if "$DIR" in bin_path:
# When running as an WSGI application, we will not find the
# '__file__' attribute for the '__main__' module.
@@ -138,6 +142,26 @@ class ServerType(object):
(res if os.name != 'nt' else (res + '.exe'))
))
def get_utility_path(self, sverison):
"""
This function is used to get the utility path set by the user in
preferences for the specific server version, if not set then check
for any default path is set.
"""
default_path = None
bin_path_json = json.loads(self.utility_path.get())
# iterate through all the path and return appropriate value
for bin_path in bin_path_json:
if int(bin_path['version']) <= sverison < \
int(bin_path['next_major_version']) and \
bin_path['binaryPath'] is not None:
return bin_path['binaryPath']
if bin_path['isDefault']:
default_path = bin_path['binaryPath']
return default_path
# Default Server Type
ServerType('pg', _("PostgreSQL"), -1)