1) Fixed import/export servers issue in server mode.

2) Fixed an issue where files are not showing as per the selected format in
   the file dialog when opened the first time.
pull/64/head
Akshay Joshi 2022-01-07 21:29:17 +05:30
parent af6ff20020
commit 4ecd05e33b
3 changed files with 60 additions and 20 deletions

View File

@ -1985,7 +1985,7 @@ define([
let response = getFileFormat(this.config.options.allowed_file_types);
let lastSelectedFormat = response.responseJSON.info;
if (_.isUndefined(lastSelectedFormat))
if (_.isUndefined(lastSelectedFormat) || allowed_types.indexOf(lastSelectedFormat) < 0)
set_type = allowed_types[0];
else
set_type = lastSelectedFormat;

View File

@ -24,6 +24,8 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error
from pgadmin.model import ServerGroup, Server
from pgadmin.utils import clear_database_servers, dump_database_servers,\
load_database_servers, validate_json_data
from urllib.parse import unquote
from pgadmin.utils.paths import get_storage_directory
MODULE_NAME = 'import_export_servers'
@ -130,9 +132,20 @@ def load_servers():
if 'filename' in data:
filename = data['filename']
if filename is not None and os.path.exists(filename):
file_path = unquote(filename)
# retrieve storage directory path
storage_manager_path = get_storage_directory()
if storage_manager_path:
# generate full path of file
file_path = os.path.join(
storage_manager_path,
file_path.lstrip('/').lstrip('\\')
)
if file_path is not None and os.path.exists(file_path):
try:
with open(filename, 'r') as j:
with open(file_path, 'r') as j:
data = json.loads(j.read())
# Validate the json file and data

View File

@ -22,8 +22,8 @@ from threading import Lock
from .paths import get_storage_directory
from .preferences import Preferences
from pgadmin.utils.constants import UTILITIES_ARRAY, USER_NOT_FOUND
from pgadmin.model import db, User, Version, ServerGroup, Server, \
SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
from pgadmin.model import db, User, ServerGroup, Server
from urllib.parse import unquote
ADD_SERVERS_MSG = "Added %d Server Group(s) and %d Server(s)."
@ -450,20 +450,36 @@ def dump_database_servers(output_file, selected_servers,
object_dict["Servers"] = server_dict
f = None
try:
f = open(output_file, "w")
except Exception as e:
return _handle_error("Error opening output file %s: [%d] %s" %
(output_file, e.errno, e.strerror), from_setup)
# retrieve storage directory path
storage_manager_path = get_storage_directory()
try:
f.write(json.dumps(object_dict, indent=4))
except Exception as e:
return _handle_error("Error writing output file %s: [%d] %s" %
(output_file, e.errno, e.strerror), from_setup)
# generate full path of file
file_path = unquote(output_file)
f.close()
from pgadmin.misc.file_manager import Filemanager
try:
Filemanager.check_access_permission(storage_manager_path, file_path)
except Exception as e:
return _handle_error(str(e), from_setup)
if storage_manager_path is not None:
file_path = os.path.join(
storage_manager_path,
file_path.lstrip('/').lstrip('\\')
)
# write to file
file_content = json.dumps(object_dict, indent=4)
error_str = gettext("Error: {0}")
try:
with open(file_path, 'w') as output_file:
output_file.write(file_content)
except IOError as e:
err_msg = error_str.format(e.strerror)
return _handle_error(err_msg, from_setup)
except Exception as e:
err_msg = error_str.format(e.strerror)
return _handle_error(err_msg, from_setup)
msg = "Configuration for %s servers dumped to %s." % \
(servers_dumped, output_file)
@ -541,15 +557,26 @@ def load_database_servers(input_file, selected_servers,
load_user=current_user, from_setup=False):
"""Load server groups and servers.
"""
# retrieve storage directory path
storage_manager_path = get_storage_directory()
# generate full path of file
file_path = unquote(input_file)
if storage_manager_path:
# generate full path of file
file_path = os.path.join(
storage_manager_path,
file_path.lstrip('/').lstrip('\\')
)
try:
with open(input_file) as f:
with open(file_path) as f:
data = json.load(f)
except json.decoder.JSONDecodeError as e:
return _handle_error("Error parsing input file %s: %s" %
(input_file, e), from_setup)
(file_path, e), from_setup)
except Exception as e:
return _handle_error("Error reading input file %s: [%d] %s" %
(input_file, e.errno, e.strerror), from_setup)
(file_path, e.errno, e.strerror), from_setup)
f.close()