mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-09 07:33:19 -06:00
1) Added logic to set the appropriate default binary path if DEFAULT_BINARY_PATH is
set in the config and the user not updated the preferences. 2) Remove 'gpdb' from DEFAULT_BINARY_PATH. 3) Fixed API test cases. refs #5370
This commit is contained in:
parent
065a3aa2f5
commit
07eb541806
@ -432,8 +432,7 @@ STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
|
||||
##########################################################################
|
||||
DEFAULT_BINARY_PATHS = {
|
||||
"pg": "",
|
||||
"ppas": "",
|
||||
"gpdb": ""
|
||||
"ppas": ""
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
|
@ -10,11 +10,14 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import config
|
||||
import subprocess
|
||||
|
||||
from flask import render_template
|
||||
from flask_babelex import gettext as _
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
from werkzeug.exceptions import InternalServerError
|
||||
from pgadmin.utils.constants import BINARY_PATHS, UTILITIES_ARRAY
|
||||
|
||||
|
||||
class ServerType(object):
|
||||
@ -57,19 +60,26 @@ class ServerType(object):
|
||||
@classmethod
|
||||
def register_preferences(cls):
|
||||
paths = Preferences('paths', _('Paths'))
|
||||
bin_paths = BINARY_PATHS
|
||||
|
||||
for key in cls.registry:
|
||||
st = cls.registry[key]
|
||||
|
||||
default_bin_path = config.DEFAULT_BINARY_PATHS.get(key, "")
|
||||
if default_bin_path != "":
|
||||
cls.set_default_binary_path(default_bin_path, bin_paths, key)
|
||||
if key == 'pg':
|
||||
st.utility_path = paths.register(
|
||||
'bin_paths', 'pg_bin_dir',
|
||||
_("PostgreSQL Binary Path"), 'selectFile', None,
|
||||
_("PostgreSQL Binary Path"), 'selectFile',
|
||||
json.dumps(bin_paths['pg_bin_paths']),
|
||||
category_label=_('Binary paths')
|
||||
)
|
||||
elif key == 'ppas':
|
||||
st.utility_path = paths.register(
|
||||
'bin_paths', 'ppas_bin_dir',
|
||||
_("EDB Advanced Server Binary Path"), 'selectFile', None,
|
||||
_("EDB Advanced Server Binary Path"), 'selectFile',
|
||||
json.dumps(bin_paths['as_bin_paths']),
|
||||
category_label=_('Binary paths')
|
||||
)
|
||||
|
||||
@ -162,6 +172,43 @@ class ServerType(object):
|
||||
|
||||
return default_path
|
||||
|
||||
@classmethod
|
||||
def set_default_binary_path(cls, binary_path, bin_paths, server_type):
|
||||
"""
|
||||
This function is used to iterate through the utilities and set the
|
||||
default binary path.
|
||||
"""
|
||||
for utility in UTILITIES_ARRAY:
|
||||
full_path = os.path.abspath(
|
||||
os.path.join(binary_path, (utility if os.name != 'nt' else
|
||||
(utility + '.exe'))))
|
||||
|
||||
try:
|
||||
# Get the output of the '--version' command
|
||||
version_string = subprocess.getoutput(full_path + ' --version')
|
||||
|
||||
# Get the version number by splitting the result string
|
||||
version_number = \
|
||||
version_string.split(") ", 1)[1].split('.', 1)[0]
|
||||
|
||||
# Get the paths array based on server type
|
||||
if 'pg_bin_paths' in bin_paths or 'as_bin_paths' in bin_paths:
|
||||
paths_array = bin_paths['pg_bin_paths']
|
||||
if server_type == 'ppas':
|
||||
paths_array = bin_paths['as_bin_paths']
|
||||
else:
|
||||
paths_array = bin_paths
|
||||
|
||||
for path in paths_array:
|
||||
if path['version'].find(version_number) == 0 and \
|
||||
path['binaryPath'] is None:
|
||||
path['binaryPath'] = binary_path
|
||||
path['isDefault'] = True
|
||||
break
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
|
||||
# Default Server Type
|
||||
ServerType('pg', _("PostgreSQL"), -1)
|
||||
|
@ -16,7 +16,7 @@ from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.csrf import pgCSRFProtect
|
||||
from pgadmin.utils.session import cleanup_session_files
|
||||
from pgadmin.misc.themes import get_all_themes
|
||||
from pgadmin.utils.constants import MIMETYPE_APP_JS
|
||||
from pgadmin.utils.constants import MIMETYPE_APP_JS, UTILITIES_ARRAY
|
||||
from pgadmin.utils.ajax import precondition_required, make_json_response
|
||||
import config
|
||||
import subprocess
|
||||
@ -191,23 +191,24 @@ def validate_binary_path():
|
||||
|
||||
version_str = ''
|
||||
if 'utility_path' in data and data['utility_path'] is not None:
|
||||
for utility in ['pg_dump', 'pg_dumpall', 'pg_restore', 'psql']:
|
||||
for utility in UTILITIES_ARRAY:
|
||||
full_path = os.path.abspath(
|
||||
os.path.join(data['utility_path'],
|
||||
(utility if os.name != 'nt' else
|
||||
(utility + '.exe'))))
|
||||
try:
|
||||
result = subprocess.Popen([full_path, '--version'],
|
||||
stdout=subprocess.PIPE)
|
||||
except FileNotFoundError:
|
||||
# Get the output of the '--version' command
|
||||
version_string = subprocess.getoutput(full_path + ' --version')
|
||||
# Get the version number by splitting the result string
|
||||
version_string.split(") ", 1)[1].split('.', 1)[0]
|
||||
except Exception:
|
||||
version_str += "<b>" + utility + ":</b> " + \
|
||||
"not found on the specified binary path.<br/>"
|
||||
continue
|
||||
|
||||
# Replace the name of the utility from the result to avoid
|
||||
# duplicate name.
|
||||
result_str = \
|
||||
result.stdout.read().decode("utf-8").replace(utility, '')
|
||||
result_str = version_string.replace(utility, '')
|
||||
|
||||
version_str += "<b>" + utility + ":</b> " + result_str + "<br/>"
|
||||
else:
|
||||
|
@ -1172,28 +1172,7 @@ define([
|
||||
}))(null);
|
||||
|
||||
let bin_value = JSON.parse(this.model.get(this.field.get('name')));
|
||||
if (this.field.get('label').indexOf('EDB') >= 0) {
|
||||
let as_bin_paths = _.extend([
|
||||
{'version': '90600', 'next_major_version': '100000', 'serverType': gettext('EDB Advanced Server 9.6'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '100000', 'next_major_version': '110000', 'serverType': gettext('EDB Advanced Server 10'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '110000', 'next_major_version': '120000', 'serverType': gettext('EDB Advanced Server 11'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '120000', 'next_major_version': '130000', 'serverType': gettext('EDB Advanced Server 12'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '130000', 'next_major_version': '140000', 'serverType': gettext('EDB Advanced Server 13'), 'binaryPath': null, 'isDefault': false},
|
||||
], bin_value);
|
||||
|
||||
this.BinPathCollection.add(as_bin_paths);
|
||||
} else {
|
||||
let pg_bin_paths = _.extend([
|
||||
{'version': '90600', 'next_major_version': '100000', 'serverType': gettext('PostgreSQL 9.6'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '100000', 'next_major_version': '110000', 'serverType': gettext('PostgreSQL 10'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '110000', 'next_major_version': '120000', 'serverType': gettext('PostgreSQL 11'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '120000', 'next_major_version': '130000', 'serverType': gettext('PostgreSQL 12'), 'binaryPath': null, 'isDefault': false},
|
||||
{'version': '130000', 'next_major_version': '140000', 'serverType': gettext('PostgreSQL 13'), 'binaryPath': null, 'isDefault': false}
|
||||
], bin_value);
|
||||
|
||||
this.BinPathCollection.add(pg_bin_paths);
|
||||
}
|
||||
|
||||
this.BinPathCollection.add(bin_value);
|
||||
this.listenTo(BinPathCollection, 'change', this.binPathCollectionChanged);
|
||||
},
|
||||
|
||||
|
@ -273,6 +273,11 @@ def does_utility_exist(file):
|
||||
:return:
|
||||
"""
|
||||
error_msg = None
|
||||
if file is None:
|
||||
error_msg = gettext("Utility file not found. Please correct the Binary"
|
||||
" Path in the Preferences dialog")
|
||||
return error_msg
|
||||
|
||||
if not os.path.exists(file):
|
||||
error_msg = gettext("'%s' file not found. Please correct the Binary"
|
||||
" Path in the Preferences dialog" % file)
|
||||
|
@ -56,3 +56,42 @@ KERBEROS = 'kerberos'
|
||||
SUPPORTED_AUTH_SOURCES = [INTERNAL,
|
||||
LDAP,
|
||||
KERBEROS]
|
||||
|
||||
BINARY_PATHS = {
|
||||
"as_bin_paths": [
|
||||
{"version": "90600", "next_major_version": "100000",
|
||||
"serverType": gettext("EDB Advanced Server 9.6"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "100000", "next_major_version": "110000",
|
||||
"serverType": gettext("EDB Advanced Server 10"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "110000", "next_major_version": "120000",
|
||||
"serverType": gettext("EDB Advanced Server 11"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "120000", "next_major_version": "130000",
|
||||
"serverType": gettext("EDB Advanced Server 12"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "130000", "next_major_version": "140000",
|
||||
"serverType": gettext("EDB Advanced Server 13"), "binaryPath": None,
|
||||
"isDefault": False}
|
||||
],
|
||||
"pg_bin_paths": [
|
||||
{"version": "90600", "next_major_version": "100000",
|
||||
"serverType": gettext("PostgreSQL 9.6"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "100000", "next_major_version": "110000",
|
||||
"serverType": gettext("PostgreSQL 10"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "110000", "next_major_version": "120000",
|
||||
"serverType": gettext("PostgreSQL 11"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "120000", "next_major_version": "130000",
|
||||
"serverType": gettext("PostgreSQL 12"), "binaryPath": None,
|
||||
"isDefault": False},
|
||||
{"version": "130000", "next_major_version": "140000",
|
||||
"serverType": gettext("PostgreSQL 13"), "binaryPath": None,
|
||||
"isDefault": False}
|
||||
]
|
||||
}
|
||||
|
||||
UTILITIES_ARRAY = ['pg_dump', 'pg_dumpall', 'pg_restore', 'psql']
|
||||
|
@ -8,7 +8,6 @@
|
||||
##########################################################################
|
||||
|
||||
|
||||
import fileinput
|
||||
import traceback
|
||||
import os
|
||||
import sys
|
||||
@ -36,6 +35,7 @@ import regression
|
||||
from regression import test_setup
|
||||
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
from pgadmin.utils.constants import BINARY_PATHS
|
||||
|
||||
from functools import wraps
|
||||
|
||||
@ -767,10 +767,15 @@ def configure_preferences(default_binary_path=None):
|
||||
if user_pref_data:
|
||||
cur.execute(
|
||||
'UPDATE user_preferences SET value = ? WHERE pid = ?',
|
||||
(default_binary_path[server], pref_bin_path.pid)
|
||||
(pref_bin_path.default, pref_bin_path.pid)
|
||||
)
|
||||
else:
|
||||
params = (pref_bin_path.pid, 1, default_binary_path[server])
|
||||
if server == 'ppas':
|
||||
params = (pref_bin_path.pid, 1,
|
||||
json.dumps(BINARY_PATHS['as_bin_paths']))
|
||||
else:
|
||||
params = (pref_bin_path.pid, 1,
|
||||
json.dumps(BINARY_PATHS['pg_bin_paths']))
|
||||
cur.execute(
|
||||
insert_preferences_query, params
|
||||
)
|
||||
|
@ -107,8 +107,7 @@
|
||||
"enabled": true,
|
||||
"default_binary_paths": {
|
||||
"pg": "/opt/PostgreSQL/9.4/bin/",
|
||||
"ppas": "/opt/edb/as10/bin/",
|
||||
"gpdb": ""
|
||||
"ppas": "/opt/edb/as10/bin/"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user