Fixed 'Remove the unused function parameter' code smell.

This commit is contained in:
Nikhil Mohite 2022-09-09 18:36:51 +05:30 committed by Akshay Joshi
parent 3b95a416ca
commit d967d5046d
30 changed files with 57 additions and 131 deletions

View File

@ -444,7 +444,7 @@ def create_app(app_name=None):
# Don't bother paths when running in cli mode
if not cli_mode:
import pgadmin.utils.paths as paths
paths.init_app(app)
paths.init_app()
# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
@ -578,7 +578,7 @@ def create_app(app_name=None):
maintenance_db='postgres',
username=superuser,
ssl_mode='prefer',
comment=svr_comment,
comment=comment,
discovery_id=discovery_id)
db.session.add(svr)
@ -700,7 +700,7 @@ def create_app(app_name=None):
for mdl in current_app.logout_hooks:
try:
mdl.on_logout(user)
mdl.on_logout()
except Exception as e:
current_app.logger.exception(e)

View File

@ -167,7 +167,6 @@ class AggregateView(PGChildNodeView):
# Set the template path for the SQL scripts
self.template_path = compile_template_path(
'aggregates/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -204,7 +204,6 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
# Set the template path for the SQL scripts
self.template_path = compile_template_path(
'collations/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -303,7 +303,6 @@ class DomainView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
# we will set template path for sql scripts
self.template_path = compile_template_path(
'domains/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -392,7 +392,6 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
# on the server version.
self.template_path = compile_template_path(
'foreign_tables/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -166,7 +166,6 @@ class OperatorView(PGChildNodeView):
# Set the template path for the SQL scripts
self.template_path = compile_template_path(
'operators/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -274,7 +274,6 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.server_type,
self.manager.version
)

View File

@ -248,14 +248,12 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
self.conn = self.manager.connection(did=kwargs['did'])
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.server_type,
self.manager.version
)
# we will set template path for sql scripts
self.template_path = compile_template_path(
'indexes/sql/',
self.manager.server_type,
self.manager.version
)

View File

@ -203,7 +203,6 @@ class RowSecurityView(PGChildNodeView):
# Set template path for the sql scripts
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.server_type,
self.manager.version
)
self.template_path = 'row_security_policies/sql/#{0}#'.format(

View File

@ -200,7 +200,6 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
self.template_path = 'rules/sql'
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.server_type,
self.manager.version
)

View File

@ -264,7 +264,6 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
# we will set template path for sql scripts
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.server_type,
self.manager.version
)
self.template_path = 'triggers/sql/{0}/#{1}#'.format(

View File

@ -117,11 +117,9 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
ver = self.manager.version
server_type = self.manager.server_type
# Set the template path for the SQL scripts
self.table_template_path = compile_template_path('tables/sql',
server_type, ver)
self.table_template_path = compile_template_path('tables/sql', ver)
self.data_type_template_path = compile_template_path(
'datatype/sql',
server_type, ver)
'datatype/sql', ver)
self.partition_template_path = \
'partitions/sql/{0}/#{0}#{1}#'.format(server_type, ver)
@ -131,7 +129,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
# Template for index node
self.index_template_path = compile_template_path(
'indexes/sql', server_type, ver)
'indexes/sql', ver)
# Template for index node
self.row_security_policies_template_path = \

View File

@ -133,7 +133,7 @@ class ServerType(object):
self.stype, self.desc, self.spriority
)
def instance_of(self, version):
def instance_of(self):
return True
@property

View File

@ -275,20 +275,3 @@ def remove_saved_passwords(user_id):
except Exception:
db.session.rollback()
raise
def does_server_exists(sid, user_id):
"""
This function will return True if server is existing for a user
:param sid: server id
:param user_id: user id
:return: Boolean
"""
# **kwargs parameter can be added to function to filter with more
# parameters.
try:
return True if Server.query.filter_by(
id=sid).first() is not None else False
except Exception:
return False

View File

@ -111,14 +111,14 @@ class UTC(tzinfo):
def dst(self, dt):
return _ZERO
def localize(self, dt, is_dst=False):
'''Convert naive time to local time'''
def localize(self, dt):
"""Convert naive time to local time"""
if dt.tzinfo is not None:
raise ValueError('Not naive datetime (tzinfo is already set)')
return dt.replace(tzinfo=self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime'''
def normalize(self, dt):
"""Correct the timezone information on the given datetime"""
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:

View File

@ -25,7 +25,6 @@ import shutil
from pgadmin.utils import u_encode, file_quote, fs_encoding, \
get_complete_file_path, get_storage_directory, IS_WIN
from pgadmin.browser.server_groups.servers.utils import does_server_exists
from pgadmin.utils.constants import KERBEROS
from pgadmin.utils.locker import ConnectionLocker
from pgadmin.utils.preferences import Preferences

View File

@ -741,57 +741,7 @@ class Filemanager(object):
trans_data = Filemanager.get_trasaction_selection(self.trans_id)
return False if capability not in trans_data['capabilities'] else True
def getinfo(self, path=None, get_size=True, name=None, req=None):
"""
Returns a JSON object containing information
about the given file.
"""
date_created = 'Date Created'
date_modified = 'Date Modified'
path = unquote(path)
if self.dir is None:
self.dir = ""
orig_path = "{0}{1}".format(self.dir, path)
Filemanager.check_access_permission(self.dir, path)
user_dir = path
thefile = {
'Filename': split_path(orig_path)[-1],
'FileType': '',
'Path': user_dir,
'Info': '',
'Properties': {
date_created: '',
date_modified: '',
'Width': '',
'Height': '',
'Size': ''
}
}
if not path_exists(orig_path):
return make_json_response(
status=404,
errormsg=gettext("'{0}' file does not exist.").format(path))
if split_path(user_dir)[-1] == '/'\
or os.path.isfile(orig_path) is False:
thefile['FileType'] = 'Directory'
else:
thefile['FileType'] = splitext(user_dir)
created = time.ctime(os.path.getctime(orig_path))
modified = time.ctime(os.path.getmtime(orig_path))
thefile['Properties'][date_created] = created
thefile['Properties'][date_modified] = modified
thefile['Properties']['Size'] = sizeof_fmt(getsize(orig_path))
return thefile
def getfolder(self, path=None, file_type="", name=None, req=None,
show_hidden=False):
def getfolder(self, path=None, file_type="", show_hidden=False):
"""
Returns files and folders in give path
"""
@ -806,7 +756,7 @@ class Filemanager(object):
the_dir, path, trans_data, file_type, show_hidden)
return filelist
def rename(self, old=None, new=None, req=None):
def rename(self, old=None, new=None):
"""
Rename file or folder
"""
@ -850,7 +800,7 @@ class Filemanager(object):
'New Name': newname,
}
def delete(self, path=None, req=None):
def delete(self, path=None):
"""
Delete file or folder
"""
@ -919,7 +869,7 @@ class Filemanager(object):
'Name': new_name,
}
def is_file_exist(self, path, name, req=None):
def is_file_exist(self, path, name):
"""
Checks whether given file exists or not
"""
@ -1038,7 +988,7 @@ class Filemanager(object):
return status, err_msg, is_binary, is_startswith_bom, enc
def addfolder(self, path, name, req=None):
def addfolder(self, path, name):
"""
Functionality to create new folder
"""
@ -1066,7 +1016,7 @@ class Filemanager(object):
return result
def download(self, path=None, name=None, req=None):
def download(self, path=None):
"""
Functionality to download file
"""
@ -1093,7 +1043,7 @@ class Filemanager(object):
return response
def permission(self, path=None, req=None):
def permission(self, path=None):
the_dir = self.dir if self.dir is not None else ''
res = {'Code': 1}
Filemanager.check_access_permission(the_dir, path)
@ -1130,9 +1080,15 @@ def file_manager(trans_id):
'name': req.args['name'] if 'name' in req.args else ''
}
mode = req.args['mode']
func = getattr(my_fm, mode)
try:
if mode in ['getfolder', 'download']:
kwargs.pop('name', None)
if mode in ['addfolder', 'getfolder', 'rename', 'delete',
'is_file_exist', 'req', 'permission']:
kwargs.pop('req', None)
res = func(**kwargs)
except PermissionError as e:
return unauthorized(str(e))

View File

@ -224,7 +224,7 @@ class DebuggerModule(PgAdminModule):
'debugger.poll_end_execution_result', 'debugger.poll_result'
]
def on_logout(self, user):
def on_logout(self):
"""
This is a callback function when user logout from pgAdmin
:param user:

View File

@ -36,7 +36,7 @@ class ERDSql(BaseTestGenerator):
# Iterate the version mapping directories.
for version_mapping in \
get_version_mapping_directories(self.server['type']):
get_version_mapping_directories():
if version_mapping['number'] > \
self.server_information['server_version']:
continue

View File

@ -94,8 +94,7 @@ class SchemaDiffTestCase(BaseTestGenerator):
absolute_path = tests_folder_path
# Iterate the version mapping directories.
for version_mapping in get_version_mapping_directories(
self.server['type']):
for version_mapping in get_version_mapping_directories():
if version_mapping['number'] > \
self.server_information['server_version']:
continue

View File

@ -138,7 +138,7 @@ class SqlEditorModule(PgAdminModule):
'sqleditor.connect_server',
]
def on_logout(self, user):
def on_logout(self):
"""
This is a callback function when user logout from pgAdmin
:param user:

View File

@ -22,7 +22,6 @@ def apply_explain_plan_wrapper_if_needed(manager, sql):
template_path = compile_template_name(
'sqleditor/sql',
'explain_plan.sql',
server_type,
ver
)
return render_template(template_path, sql=sql['sql'], **explain_plan)

View File

@ -9,16 +9,16 @@
def compile_template_name(
template_prefix, template_file_name, server_type, version):
template_prefix, template_file_name, version):
# Template path concatenation should be same as
# Ref: ../pgadmin4/web/pgadmin/utils/versioned_template_loader.py +54
# to avoid path mismatch in windows
return compile_template_path(template_prefix, server_type, version) + \
return compile_template_path(template_prefix, version) + \
'/' + template_file_name
def compile_template_path(template_prefix, server_type, version):
def compile_template_path(template_prefix, version):
version_path = '#{0}#'.format(version)

View File

@ -621,10 +621,16 @@ WHERE db.datname = current_database()""")
server_types = ServerType.types()
for st in server_types:
if st.instance_of(manager.ver):
manager.server_type = st.stype
manager.server_cls = st
break
if st.stype == 'ppas':
if st.instance_of(manager.ver):
manager.server_type = st.stype
manager.server_cls = st
break
else:
if st.instance_of():
manager.server_type = st.stype
manager.server_cls = st
break
def __cursor(self, server_cursor=False):
@ -783,8 +789,8 @@ WHERE db.datname = current_database()""")
if self.async_ == 1:
self._wait(cur.connection)
def execute_on_server_as_csv(self, params=None,
formatted_exception_msg=False, records=2000):
def execute_on_server_as_csv(self, formatted_exception_msg=False,
records=2000):
"""
To fetch query result and generate CSV output

View File

@ -76,7 +76,7 @@ def get_storage_directory(user=current_user):
return storage_dir
def init_app(app):
def init_app():
import config
if config.SERVER_MODE is not True:
return None

View File

@ -25,6 +25,6 @@ class TestCompileTemplateName(BaseTestGenerator):
def runTest(self):
result = compile_template_name(
'some/prefix', 'some_file.sql', self.server_type, self.version
'some/prefix', 'some_file.sql', self.version
)
self.assertEqual(result, self.expected_return_value)

View File

@ -64,14 +64,13 @@ def parse_template(template):
def get_version_mapping(template):
template_path_parts = template.split("#", 3)
server_type = None
if len(template_path_parts) == 4:
_, server_type, _, _ = template_path_parts
return get_version_mapping_directories(server_type)
return get_version_mapping_directories()
def get_version_mapping_directories(server_type):
def get_version_mapping_directories():
"""
This function will return all the version mapping directories
:param server_type:

View File

@ -236,13 +236,13 @@ CREATE TABLE public.nonintpkey
self._update_numeric_cell(xpath, value):
break
elif cell_type in ['text', 'text[]', 'boolean[]'] and \
self._update_text_cell(cell_el, value):
self._update_text_cell(value):
break
elif cell_type in ['json', 'jsonb'] and \
self._update_json_cell(cell_el, value):
self._update_json_cell(value):
retry = 0
elif cell_type in ['bool'] and \
self._update_boolean_cell(cell_el, value):
self._update_boolean_cell(value):
retry = 0
else:
print('Unable to update cell in try ' + str(retry),
@ -269,7 +269,7 @@ CREATE TABLE public.nonintpkey
file=sys.stderr)
return False
def _update_text_cell(self, cell_el, value):
def _update_text_cell(self, value):
try:
text_area_ele = WebDriverWait(self.driver, 3).until(
EC.visibility_of_element_located(
@ -289,7 +289,7 @@ CREATE TABLE public.nonintpkey
file=sys.stderr)
return False
def _update_json_cell(self, cell_el, value):
def _update_json_cell(self, value):
platform = 'mac'
if "platform" in self.driver.capabilities:
platform = (self.driver.capabilities["platform"]).lower()
@ -318,7 +318,7 @@ CREATE TABLE public.nonintpkey
file=sys.stderr)
return False
def _update_boolean_cell(self, cell_el, value):
def _update_boolean_cell(self, value):
# Boolean editor test for to True click
try:
checkbox_el = self.page.find_by_css_selector(

View File

@ -69,7 +69,7 @@ class SQLTemplateTestBase(BaseTestGenerator):
"""
# Iterate all the mapping directories and check the file is exist
# in the specified folder. If it exists then return the path.
for directory in get_version_mapping_directories(self.server['type']):
for directory in get_version_mapping_directories():
if directory['number'] > version:
continue

View File

@ -358,8 +358,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
absolute_path = tests_folder_path
# Iterate the version mapping directories.
for version_mapping in get_version_mapping_directories(
self.server['type']):
for version_mapping in get_version_mapping_directories():
if version_mapping['number'] > \
self.server_information['server_version']:
continue
@ -392,8 +391,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
absolute_path = tests_folder_path
# Iterate the version mapping directories.
for version_mapping in get_version_mapping_directories(
self.server['type']):
for version_mapping in get_version_mapping_directories():
if version_mapping['number'] > \
self.server_information['server_version']:
continue