Fixed SonarQube issues.

This commit is contained in:
Akshay Joshi 2022-08-05 18:58:03 +05:30
parent fa6b77b42c
commit d1c94ac73d
7 changed files with 27 additions and 34 deletions

View File

@ -239,11 +239,11 @@ class AzureProvider(AbsProvider):
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception as e: except Exception as e:
error(args, e) error(str(e))
if svr is not None: if svr is not None:
error(args, 'Azure Database for PostgreSQL instance {} already ' error('Azure Database for PostgreSQL instance {} already '
'exists.'.format(args.name)) 'exists.'.format(args.name))
db_password = self._database_pass if self._database_pass is not None \ db_password = self._database_pass if self._database_pass is not None \
else args.db_password else args.db_password
@ -273,7 +273,7 @@ class AzureProvider(AbsProvider):
) )
) )
except Exception as e: except Exception as e:
error(e) error(str(e))
server = poller.result() server = poller.result()
@ -313,7 +313,7 @@ class AzureProvider(AbsProvider):
firewall_rules.append(firewall_rule.__dict__) firewall_rules.append(firewall_rule.__dict__)
return firewall_rules return firewall_rules
def _delete_azure_instance(self, args, name): def _delete_azure_instance(self, args):
""" Delete an Azure instance """ """ Delete an Azure instance """
# Obtain the management client object # Obtain the management client object
postgresql_client = self._get_azure_client('postgresql') postgresql_client = self._get_azure_client('postgresql')
@ -326,7 +326,7 @@ class AzureProvider(AbsProvider):
args.name args.name
) )
except Exception as e: except Exception as e:
error(args, e) error(str(e))
poller.result() poller.result()
@ -353,7 +353,7 @@ class AzureProvider(AbsProvider):
def cmd_delete_instance(self, args): def cmd_delete_instance(self, args):
""" Delete an Azure instance """ """ Delete an Azure instance """
self._delete_azure_instance(args, args.name) self._delete_azure_instance(args)
def load(): def load():

View File

@ -10,7 +10,6 @@
import datetime import datetime
import json import json
import sys import sys
import time
def debug(message): def debug(message):

View File

@ -828,7 +828,7 @@ class Filemanager(object):
path = old path = old
path = split_path(path)[0] # extract path path = split_path(path)[0] # extract path
if not path[-1] == '/': if path[-1] != '/':
path += '/' path += '/'
newname = new newname = new
@ -838,8 +838,6 @@ class Filemanager(object):
oldpath_sys = "{0}{1}".format(the_dir, old) oldpath_sys = "{0}{1}".format(the_dir, old)
newpath_sys = "{0}{1}".format(the_dir, newpath) newpath_sys = "{0}{1}".format(the_dir, newpath)
error_msg = gettext('Renamed successfully.')
code = 1
try: try:
os.rename(oldpath_sys, newpath_sys) os.rename(oldpath_sys, newpath_sys)
except Exception as e: except Exception as e:
@ -865,8 +863,6 @@ class Filemanager(object):
Filemanager.check_access_permission(the_dir, path) Filemanager.check_access_permission(the_dir, path)
err_msg = ''
code = 1
try: try:
if os.path.isdir(orig_path): if os.path.isdir(orig_path):
os.rmdir(orig_path) os.rmdir(orig_path)
@ -886,8 +882,7 @@ class Filemanager(object):
return unauthorized(self.ERROR_NOT_ALLOWED['Error']) return unauthorized(self.ERROR_NOT_ALLOWED['Error'])
the_dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
err_msg = ''
code = 1
try: try:
path = req.form.get('currentpath') path = req.form.get('currentpath')
@ -930,7 +925,6 @@ class Filemanager(object):
Checks whether given file exists or not Checks whether given file exists or not
""" """
the_dir = self.dir if self.dir is not None else '' the_dir = self.dir if self.dir is not None else ''
err_msg = ''
code = 1 code = 1
name = unquote(name) name = unquote(name)
@ -1087,16 +1081,16 @@ class Filemanager(object):
the_dir, "{}{}".format(path, path) the_dir, "{}{}".format(path, path)
) )
name = os.path.basename(path) filename = os.path.basename(path)
if orig_path and len(orig_path) > 0: if orig_path and len(orig_path) > 0:
dir_path = os.path.dirname(orig_path) dir_path = os.path.dirname(orig_path)
else: else:
dir_path = os.path.dirname(path) dir_path = os.path.dirname(path)
response = send_from_directory(dir_path, name, response = send_from_directory(dir_path, filename,
mimetype='application/octet-stream', mimetype='application/octet-stream',
as_attachment=True) as_attachment=True)
response.headers["filename"] = name response.headers["filename"] = filename
return response return response

View File

@ -148,13 +148,13 @@ function getTableData(res, node) {
} }
function createSingleLineStatistics(data, prettifyFields) { function createSingleLineStatistics(data, prettifyFields) {
var row = data['rows'][0], let row = data['rows'][0],
columns = data['columns'], columns = data['columns'],
res = [], res = [],
name, name,
value; value;
for (var idx in columns) { for (let idx in columns) {
name = columns[idx]['name']; name = columns[idx]['name'];
if (row && row[name]) { if (row && row[name]) {
value = value =
@ -227,11 +227,11 @@ export default function Statistics({ nodeData, item, node, ...props }) {
setLoaderText(''); setLoaderText('');
if (err?.response?.data?.info == 'CRYPTKEY_MISSING') { if (err?.response?.data?.info == 'CRYPTKEY_MISSING') {
Notify.pgNotifier('error', err.request, 'The master password is not set', function(msg) { Notify.pgNotifier('error', err.request, 'The master password is not set', function(mesg) {
setTimeout(function() { setTimeout(function() {
if (msg == 'CRYPTKEY_SET') { if (mesg == 'CRYPTKEY_SET') {
setMsg('No statistics are available for the selected object.'); setMsg('No statistics are available for the selected object.');
} else if (msg == 'CRYPTKEY_NOT_SET') { } else if (mesg == 'CRYPTKEY_NOT_SET') {
setMsg(gettext('The master password is not set.')); setMsg(gettext('The master password is not set.'));
} }
}, 100); }, 100);

View File

@ -79,7 +79,7 @@ function parseQuery(query, useRegex=false, matchCase=false) {
function getRegexFinder(query) { function getRegexFinder(query) {
return (stream) => { return (stream) => {
query.lastIndex = stream.pos; query.lastIndex = stream.pos;
var match = query.exec(stream.string); let match = query.exec(stream.string);
if (match && match.index == stream.pos) { if (match && match.index == stream.pos) {
stream.pos += match[0].length || 1; stream.pos += match[0].length || 1;
return 'searching'; return 'searching';
@ -94,7 +94,7 @@ function getRegexFinder(query) {
function getPlainStringFinder(query, matchCase) { function getPlainStringFinder(query, matchCase) {
return (stream) => { return (stream) => {
var matchIndex = (matchCase ? stream.string : stream.string.toLowerCase()).indexOf(query, stream.pos); let matchIndex = (matchCase ? stream.string : stream.string.toLowerCase()).indexOf(query, stream.pos);
if(matchIndex == -1) { if(matchIndex == -1) {
stream.skipToEnd(); stream.skipToEnd();
} else if(matchIndex == stream.pos) { } else if(matchIndex == stream.pos) {
@ -281,7 +281,7 @@ FindDialog.propTypes = {
}; };
function handleDrop(editor, e) { function handleDrop(editor, e) {
var dropDetails = null; let dropDetails = null;
try { try {
dropDetails = JSON.parse(e.dataTransfer.getData('text')); dropDetails = JSON.parse(e.dataTransfer.getData('text'));
@ -298,7 +298,7 @@ function handleDrop(editor, e) {
return; return;
} }
var cursor = editor.coordsChar({ let cursor = editor.coordsChar({
left: e.x, left: e.x,
top: e.y, top: e.y,
}); });
@ -324,7 +324,7 @@ function calcFontSize(fontSize) {
return '1em'; return '1em';
} }
function handlePaste(editor, e) { function handlePaste(_editor, e) {
let copiedText = e.clipboardData.getData('text'); let copiedText = e.clipboardData.getData('text');
checkTrojanSource(copiedText, true); checkTrojanSource(copiedText, true);
} }
@ -423,7 +423,7 @@ export default function CodeMirror({currEditor, name, value, options, events, re
let pref = pgWindow?.pgAdmin?.Browser?.get_preferences_for_module('sqleditor') || {}; let pref = pgWindow?.pgAdmin?.Browser?.get_preferences_for_module('sqleditor') || {};
if (autocomplete && pref.autocomplete_on_key_press) { if (autocomplete && pref.autocomplete_on_key_press) {
editor.current.on('keyup', (cm, event)=>{ editor.current.on('keyup', (cm, event)=>{
var pattern = new RegExp('^[ -~]{1}$'); let pattern = new RegExp('^[ -~]{1}$');
if (!cm.state.completionActive && (event.key == 'Backspace' || pattern.test(event.key))) { if (!cm.state.completionActive && (event.key == 'Backspace' || pattern.test(event.key))) {
OrigCodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); OrigCodeMirror.commands.autocomplete(cm, null, {completeSingle: false});
} }

View File

@ -484,7 +484,7 @@ export function downloadBlob(blob, fileName) {
document.body.appendChild(link); document.body.appendChild(link);
if (getBrowser() === 'IE' && window.navigator.msSaveBlob) { if (getBrowser() == 'IE' && window.navigator.msSaveBlob) {
// IE10+ : (has Blob, but not a[download] or URL) // IE10+ : (has Blob, but not a[download] or URL)
window.navigator.msSaveBlob(blob, fileName); window.navigator.msSaveBlob(blob, fileName);
} else { } else {

View File

@ -253,7 +253,7 @@ export class ResultSetUtils {
poll() { poll() {
let delay = 1; let delay = 1;
var seconds = parseInt((Date.now() - this.startTime.getTime()) / 1000); let seconds = parseInt((Date.now() - this.startTime.getTime()) / 1000);
// calculate & return fall back polling timeout // calculate & return fall back polling timeout
if (seconds >= 10 && seconds < 30) { if (seconds >= 10 && seconds < 30) {
delay = 500; delay = 500;
@ -389,7 +389,7 @@ export class ResultSetUtils {
document.body.appendChild(link); document.body.appendChild(link);
if (getBrowser() === 'IE' && window.navigator.msSaveBlob) { if (getBrowser() == 'IE' && window.navigator.msSaveBlob) {
// IE10+ : (has Blob, but not a[download] or URL) // IE10+ : (has Blob, but not a[download] or URL)
window.navigator.msSaveBlob(respBlob, fileName); window.navigator.msSaveBlob(respBlob, fileName);
} else { } else {
@ -539,7 +539,7 @@ export class ResultSetUtils {
// Create columns // Create columns
data.colinfo.forEach(function(c) { data.colinfo.forEach(function(c) {
var isPK = false, let isPK = false,
isEditable = data.can_edit && (!self.isQueryTool || c.is_editable); isEditable = data.can_edit && (!self.isQueryTool || c.is_editable);
// Check whether this column is a primary key // Check whether this column is a primary key