Fixed code smell 'String literals should not be duplicated'.

This commit is contained in:
Khushboo Vashi 2020-09-03 18:35:58 +05:30 committed by Akshay Joshi
parent 974d395a48
commit 31bbdd6a12
8 changed files with 79 additions and 68 deletions

View File

@ -19,6 +19,10 @@ from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.utils.ajax import internal_server_error
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.constants import DATATYPE_TIME_WITH_TIMEZONE,\
DATATYPE_TIME_WITHOUT_TIMEZONE,\
DATATYPE_TIMESTAMP_WITH_TIMEZONE,\
DATATYPE_TIMESTAMP_WITHOUT_TIMEZONE
class SchemaChildModule(CollectionNodeModule):
@ -205,20 +209,22 @@ class DataTypeReader:
1014, 'bpchar[]', 'character[]',
1015, 'varchar[]', 'character varying[]'):
typeval = 'L'
elif elemoid_or_name in (1083, 'time', 'time without time zone',
elif elemoid_or_name in (1083, 'time',
DATATYPE_TIME_WITHOUT_TIMEZONE,
1114, 'timestamp',
'timestamp without time zone',
DATATYPE_TIMESTAMP_WITHOUT_TIMEZONE,
1115, 'timestamp[]',
'timestamp without time zone[]',
1183, 'time[]',
'time without time zone[]',
1184, 'timestamptz',
'timestamp with time zone',
DATATYPE_TIMESTAMP_WITH_TIMEZONE,
1185, 'timestamptz[]',
'timestamp with time zone[]',
1186, 'interval',
1187, 'interval[]', 'interval[]',
1266, 'timetz', 'time with time zone',
1266, 'timetz',
DATATYPE_TIME_WITH_TIMEZONE,
1270, 'timetz', 'time with time zone[]'):
typeval = 'D'
elif elemoid_or_name in (1231, 'numeric[]',
@ -254,12 +260,12 @@ class DataTypeReader:
elif (
name == 'time' or
name == 'timetz' or
name == 'time without time zone' or
name == 'time with time zone' or
name == DATATYPE_TIME_WITHOUT_TIMEZONE or
name == DATATYPE_TIME_WITH_TIMEZONE or
name == 'timestamp' or
name == 'timestamptz' or
name == 'timestamp without time zone' or
name == 'timestamp with time zone' or
name == DATATYPE_TIMESTAMP_WITHOUT_TIMEZONE or
name == DATATYPE_TIMESTAMP_WITH_TIMEZONE or
name == 'bit' or
name == 'bit varying' or
name == 'varbit'
@ -300,13 +306,13 @@ class DataTypeReader:
"""
if name == 'char' and schema == 'pg_catalog':
return '"char"' + array
elif name == 'time with time zone':
elif name == DATATYPE_TIME_WITH_TIMEZONE:
return 'time' + length + ' with time zone' + array
elif name == 'time without time zone':
elif name == DATATYPE_TIME_WITHOUT_TIMEZONE:
return 'time' + length + ' without time zone' + array
elif name == 'timestamp with time zone':
elif name == DATATYPE_TIMESTAMP_WITH_TIMEZONE:
return 'timestamp' + length + ' with time zone' + array
elif name == 'timestamp without time zone':
elif name == DATATYPE_TIMESTAMP_WITHOUT_TIMEZONE:
return 'timestamp' + length + ' without time zone' + array
else:
return name + length + array

View File

@ -557,10 +557,9 @@ class Filemanager(object):
Filemanager.check_access_permission(in_dir, path)
except Exception as e:
Filemanager.resume_windows_warning()
err_msg = gettext("Error: {0}").format(e)
files = {
'Code': 0,
'Error': err_msg
'Error': str(e)
}
return files
@ -660,9 +659,9 @@ class Filemanager(object):
Filemanager.resume_windows_warning()
if (hasattr(e, 'strerror') and
e.strerror == gettext('Permission denied')):
err_msg = gettext("Error: {0}").format(e.strerror)
err_msg = str(e.strerror)
else:
err_msg = gettext("Error: {0}").format(e)
err_msg = str(e)
files = {
'Code': 0,
'Error': err_msg
@ -751,7 +750,7 @@ class Filemanager(object):
'Filename': split_path(path)[-1],
'FileType': '',
'Path': path,
'Error': gettext("Error: {0}").format(e),
'Error': str(e),
'Code': 0,
'Info': '',
'Properties': {
@ -835,7 +834,7 @@ class Filemanager(object):
Filemanager.check_access_permission(the_dir, new)
except Exception as e:
res = {
'Error': gettext("Error: {0}").format(e),
'Error': str(e),
'Code': 0
}
return res
@ -896,7 +895,7 @@ class Filemanager(object):
Filemanager.check_access_permission(the_dir, path)
except Exception as e:
res = {
'Error': gettext("Error: {0}").format(e),
'Error': str(e),
'Code': 0
}
return res
@ -910,7 +909,7 @@ class Filemanager(object):
os.remove(orig_path)
except Exception as e:
code = 0
err_msg = gettext("Error: {0}").format(e.strerror)
err_msg = str(e.strerror)
result = {
'Path': path,
@ -950,14 +949,13 @@ class Filemanager(object):
f.write(data)
except Exception as e:
code = 0
err_msg = gettext("Error: {0}").format(
e.strerror if hasattr(e, 'strerror') else gettext('Unknown'))
err_msg = str(e.strerror) if hasattr(e, 'strerror') else str(e)
try:
Filemanager.check_access_permission(the_dir, path)
except Exception as e:
res = {
'Error': gettext("Error: {0}").format(e),
'Error': str(e),
'Code': 0
}
return res
@ -991,9 +989,9 @@ class Filemanager(object):
except Exception as e:
code = 0
if hasattr(e, 'strerror'):
err_msg = gettext("Error: {0}").format(e.strerror)
err_msg = str(e.strerror)
else:
err_msg = gettext("Error: {0}").format(e)
err_msg = str(e)
result = {
'Path': path,
@ -1083,13 +1081,13 @@ class Filemanager(object):
# we don't want to expose real path of file
# so only show error message.
if ex.strerror == 'Permission denied':
err_msg = gettext("Error: {0}").format(ex.strerror)
err_msg = str(ex.strerror)
else:
err_msg = gettext("Error: {0}").format(str(ex))
err_msg = str(ex)
except Exception as ex:
status = False
err_msg = gettext("Error: {0}").format(str(ex))
err_msg = str(ex)
# Remove root storage path from error message
# when running in Server mode
@ -1117,7 +1115,7 @@ class Filemanager(object):
path, name))
except Exception as e:
res = {
'Error': gettext("Error: {0}").format(e),
'Error': str(e),
'Code': 0
}
return res
@ -1135,14 +1133,14 @@ class Filemanager(object):
os.mkdir(new_path)
except Exception as e:
code = 0
err_msg = gettext("Error: {0}").format(e.strerror)
err_msg = str(e.strerror)
else:
new_path, new_name = self.get_new_name(the_dir, path, name)
try:
os.mkdir(new_path)
except Exception as e:
code = 0
err_msg = gettext("Error: {0}").format(e.strerror)
err_msg = str(e.strerror)
result = {
'Parent': path,
@ -1171,7 +1169,7 @@ class Filemanager(object):
the_dir, "{}{}".format(path, path)
)
except Exception as e:
resp = Response(gettext("Error: {0}").format(e))
resp = Response(str(e))
resp.headers['Content-Disposition'] = \
'attachment; filename=' + name
return resp
@ -1188,7 +1186,7 @@ class Filemanager(object):
try:
Filemanager.check_access_permission(the_dir, path)
except Exception as e:
err_msg = gettext("Error: {0}").format(e)
err_msg = str(e)
res['Code'] = 0
res['Error'] = err_msg
return res

View File

@ -26,7 +26,8 @@ from pgadmin.tools.schema_diff.model import SchemaDiffModel
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.driver import get_driver
from pgadmin.utils.preferences import Preferences
from pgadmin.utils.constants import PREF_LABEL_DISPLAY, MIMETYPE_APP_JS
from pgadmin.utils.constants import PREF_LABEL_DISPLAY, MIMETYPE_APP_JS,\
ERROR_MSG_TRANS_ID_NOT_FOUND
from sqlalchemy import or_
MODULE_NAME = 'schema_diff'
@ -155,17 +156,13 @@ def check_transaction_status(trans_id):
"""
if 'schemaDiff' not in session:
return False, gettext(
'Transaction ID not found in the session.'
), None, None
return False, ERROR_MSG_TRANS_ID_NOT_FOUND, None, None
schema_diff_data = session['schemaDiff']
# Return from the function if transaction id not found
if str(trans_id) not in schema_diff_data:
return False, gettext(
'Transaction ID not found in the session.'
), None, None
return False, ERROR_MSG_TRANS_ID_NOT_FOUND, None, None
# Fetch the object for the specified transaction id.
# Use pickle.loads function to get the model object
@ -439,7 +436,7 @@ def compare(trans_id, source_sid, source_did, target_sid, target_did):
status, error_msg, diff_model_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg, status=404)
# Server version compatibility check
@ -566,7 +563,7 @@ def poll(trans_id):
status, error_msg, diff_model_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg, status=404)
msg, diff_percentage = diff_model_obj.get_comparison_info()
@ -599,7 +596,7 @@ def ddl_compare(trans_id, source_sid, source_did, source_scid,
status, error_msg, diff_model_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg, status=404)
view = SchemaDiffRegistry.get_node_view(node_type)

View File

@ -44,7 +44,8 @@ from pgadmin.tools.sqleditor.utils.query_tool_fs_utils import \
read_file_generator
from pgadmin.tools.sqleditor.utils.filter_dialog import FilterDialog
from pgadmin.tools.sqleditor.utils.query_history import QueryHistory
from pgadmin.utils.constants import MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED
from pgadmin.utils.constants import MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED,\
ERROR_MSG_TRANS_ID_NOT_FOUND
MODULE_NAME = 'sqleditor'
@ -139,17 +140,13 @@ def check_transaction_status(trans_id):
"""
if 'gridData' not in session:
return False, gettext(
'Transaction ID not found in the session.'
), None, None, None
return False, ERROR_MSG_TRANS_ID_NOT_FOUND, None, None, None
grid_data = session['gridData']
# Return from the function if transaction id not found
if str(trans_id) not in grid_data:
return False, gettext(
'Transaction ID not found in the session.'
), None, None, None
return False, ERROR_MSG_TRANS_ID_NOT_FOUND, None, None, None
# Fetch the object for the specified transaction id.
# Use pickle.loads function to get the command object
@ -199,7 +196,7 @@ def start_view_data(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -345,7 +342,7 @@ def poll(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -531,7 +528,7 @@ def fetch(trans_id, fetch_all=None):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -677,7 +674,7 @@ def save(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -750,7 +747,7 @@ def append_filter_inclusive(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -805,7 +802,7 @@ def append_filter_exclusive(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -857,7 +854,7 @@ def remove_filter(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -901,7 +898,7 @@ def set_limit(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -984,7 +981,7 @@ def cancel_transaction(trans_id):
if is_error:
return make_json_response(
success=0,
errormsg=gettext('Transaction ID not found in the session.'),
errormsg=ERROR_MSG_TRANS_ID_NOT_FOUND,
info='DATAGRID_TRANSACTION_REQUIRED', status=404)
# Fetch the object for the specified transaction id.
@ -1043,7 +1040,7 @@ def get_object_name(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -1079,7 +1076,7 @@ def set_auto_commit(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -1124,7 +1121,7 @@ def set_auto_rollback(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
@ -1176,7 +1173,7 @@ def auto_complete(trans_id):
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)

View File

@ -2071,7 +2071,7 @@ define('tools.querytool', [
if(!pgWindow.default.pgAdmin.selected_tree_map)
pgWindow.default.pgAdmin.selected_tree_map = new Map();
pgWindow.default.pgAdmin.selected_tree_map.set(d._id.toString(), selected_tree_node);
pgWindow.default.pgAdmin.selected_tree_map.set(d._pid.toString(), selected_tree_node);
};
_.extend(

View File

@ -16,6 +16,7 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error
from pgadmin.tools.sqleditor.utils.update_session_grid_transaction import \
update_session_grid_transaction
from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost
from pgadmin.utils.constants import ERROR_MSG_TRANS_ID_NOT_FOUND
class FilterDialog(object):
@ -23,7 +24,7 @@ class FilterDialog(object):
def get(*args):
"""To fetch the current sorted columns"""
status, error_msg, conn, trans_obj, session_obj = args
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(
success=0,
errormsg=error_msg,
@ -76,7 +77,7 @@ class FilterDialog(object):
else:
data = request.args or request.form
if error_msg == gettext('Transaction ID not found in the session.'):
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
return make_json_response(
success=0,
errormsg=error_msg,

View File

@ -27,6 +27,7 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error
from pgadmin.utils.driver import get_driver
from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost,\
CryptKeyMissing
from pgadmin.utils.constants import ERROR_MSG_TRANS_ID_NOT_FOUND
class StartRunningQuery:
@ -173,7 +174,7 @@ class StartRunningQuery:
if 'gridData' not in http_session:
return make_json_response(
success=0,
errormsg=gettext('Transaction ID not found in the session.'),
errormsg=ERROR_MSG_TRANS_ID_NOT_FOUND,
info='DATAGRID_TRANSACTION_REQUIRED', status=404
)
grid_data = http_session['gridData']
@ -181,7 +182,7 @@ class StartRunningQuery:
if str(transaction_id) not in grid_data:
return make_json_response(
success=0,
errormsg=gettext('Transaction ID not found in the session.'),
errormsg=ERROR_MSG_TRANS_ID_NOT_FOUND,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404
)

View File

@ -29,3 +29,14 @@ PGADMIN_NODE = 'pgadmin.node.%s'
UNAUTH_REQ = "Unauthorized request."
SERVER_CONNECTION_CLOSED = gettext(
'Not connected to server or connection with the server has been closed.')
# Data Types
DATATYPE_TIME_WITH_TIMEZONE = 'time with time zone'
DATATYPE_TIME_WITHOUT_TIMEZONE = 'time without time zone'
DATATYPE_TIMESTAMP_WITH_TIMEZONE = 'timestamp with time zone'
DATATYPE_TIMESTAMP_WITHOUT_TIMEZONE = 'timestamp without time zone'
# Error Messages
ERROR_MSG_TRANS_ID_NOT_FOUND = gettext(
'Transaction ID not found in the session.')