Skip to content

Commit 49cdc19

Browse files
committed
fixed codacy issues and code formatting
1 parent 7fbad4d commit 49cdc19

5 files changed

Lines changed: 76 additions & 72 deletions

File tree

SQLTools.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -121,36 +121,36 @@ def toNewTab(content, name="", suffix="SQLTools Saved Query"):
121121

122122

123123
def getOutputPlace(syntax=None, name="SQLTools Result"):
124-
if not settings.get('show_result_on_window', True):
125-
resultContainer = Window().create_output_panel(name)
126-
Window().run_command("show_panel", {"panel": "output." + name})
127-
else:
128-
resultContainer = None
129-
views = Window().views()
130-
for view in views:
131-
if view.name() == name:
132-
resultContainer = view
133-
Window().focus_view(resultContainer)
134-
break
135-
if not resultContainer:
136-
resultContainer = Window().new_file()
137-
resultContainer.set_name(name)
138-
139-
resultContainer.set_scratch(True) # avoids prompting to save
140-
resultContainer.settings().set("word_wrap", "false")
141-
resultContainer.set_read_only(False)
142-
# set custom syntax highlight, only if one was passed explicitly,
143-
# otherwise use Plain Text syntax
144-
if syntax:
145-
resultContainer.set_syntax_file(syntax)
146-
else:
147-
resultContainer.set_syntax_file(PLAIN_TEXT_SYNTAX)
148-
149-
if settings.get('clear_output', False):
150-
resultContainer.run_command('select_all')
151-
resultContainer.run_command('left_delete')
152-
153-
return resultContainer
124+
if not settings.get('show_result_on_window', True):
125+
resultContainer = Window().create_output_panel(name)
126+
Window().run_command("show_panel", {"panel": "output." + name})
127+
else:
128+
resultContainer = None
129+
views = Window().views()
130+
for view in views:
131+
if view.name() == name:
132+
resultContainer = view
133+
Window().focus_view(resultContainer)
134+
break
135+
if not resultContainer:
136+
resultContainer = Window().new_file()
137+
resultContainer.set_name(name)
138+
139+
resultContainer.set_scratch(True) # avoids prompting to save
140+
resultContainer.settings().set("word_wrap", "false")
141+
resultContainer.set_read_only(False)
142+
# set custom syntax highlight, only if one was passed explicitly,
143+
# otherwise use Plain Text syntax
144+
if syntax:
145+
resultContainer.set_syntax_file(syntax)
146+
else:
147+
resultContainer.set_syntax_file(PLAIN_TEXT_SYNTAX)
148+
149+
if settings.get('clear_output', False):
150+
resultContainer.run_command('select_all')
151+
resultContainer.run_command('left_delete')
152+
153+
return resultContainer
154154

155155

156156
def getSelection():
@@ -237,7 +237,7 @@ def selectConnection(tablesCallback=None, columnsCallback=None, functionsCallbac
237237

238238
menu = []
239239
for name, conn in ST.connectionList.items():
240-
menu.append([name, conn._info()])
240+
menu.append([name, conn.info()])
241241
menu.sort()
242242
Window().show_quick_panel(menu, lambda index: ST.setConnection(index, tablesCallback, columnsCallback, functionsCallback))
243243

SQLToolsAPI/Command.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
class Command:
1111
timeout = 15
1212

13-
def __init__(self, args, callback, query=None, encoding='utf-8', options=None):
14-
self.query = query
15-
self.process = None
13+
def __init__(self, args, callback, query=None, encoding='utf-8',
14+
options=None, timeout=15):
15+
if options is None:
16+
options = {}
17+
1618
self.args = args
17-
self.encoding = encoding
1819
self.callback = callback
20+
self.query = query
21+
self.encoding = encoding
1922
self.options = options
20-
# Don't allow empty dicts or lists as defaults in method signature,
21-
# cfr http://nedbatchelder.com/blog/200806/pylint.html
22-
if self.options is None:
23-
self.options = {}
24-
Thread.__init__(self)
23+
self.timeout = timeout
24+
self.process = None
2525

2626
def run(self):
2727
if not self.query:
@@ -79,17 +79,16 @@ def createAndRun(args, query, callback, options=None):
7979
class ThreadCommand(Command, Thread):
8080
def __init__(self, args, callback, query=None, encoding='utf-8',
8181
options=None, timeout=Command.timeout):
82-
self.query = query
83-
self.process = None
82+
if options is None:
83+
options = {}
84+
8485
self.args = args
85-
self.encoding = encoding
8686
self.callback = callback
87+
self.query = query
88+
self.encoding = encoding
8789
self.options = options
8890
self.timeout = timeout
89-
# Don't allow empty dicts or lists as defaults in method signature,
90-
# cfr http://nedbatchelder.com/blog/200806/pylint.html
91-
if self.options is None:
92-
self.options = {}
91+
self.process = None
9392
Thread.__init__(self)
9493

9594
def stop(self):

SQLToolsAPI/Connection.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,46 @@ class Connection:
1818
}}
1919
You might need to restart the editor for settings to be refreshed."""
2020

21-
timeout = None
22-
history = None
23-
settings = None
24-
rowsLimit = None
25-
options = None
2621
name = None
22+
options = None
23+
settings = None
2724
type = None
28-
database = None
2925
host = None
3026
port = None
27+
database = None
3128
username = None
32-
encoding = None
3329
password = None
30+
encoding = None
3431
service = None
3532
safe_limit = None
3633
show_query = None
34+
rowsLimit = None
35+
history = None
36+
timeout = None
3737

38-
def __init__(self, name, options, settings={}, commandClass='ThreadCommand'):
38+
def __init__(self, name, options, settings=None, commandClass='ThreadCommand'):
3939
self.Command = getattr(C, commandClass)
4040

41-
self.cli = settings.get('cli')[options['type']]
42-
self.settings = settings
43-
self.rowsLimit = settings.get('show_records', {}).get('limit', 50)
44-
self.options = options
45-
self.name = name
46-
self.type = options.get('type', None)
47-
self.database = options.get('database', None)
48-
self.host = options.get('host', None)
49-
self.port = options.get('port', None)
50-
self.username = options.get('username', None)
51-
self.encoding = options.get('encoding', None)
52-
self.password = options.get('password', None)
53-
self.service = options.get('service', None)
41+
self.name = name
42+
self.options = options
43+
44+
if settings is None:
45+
settings = {}
46+
self.settings = settings
47+
48+
self.type = options.get('type', None)
49+
self.host = options.get('host', None)
50+
self.port = options.get('port', None)
51+
self.database = options.get('database', None)
52+
self.username = options.get('username', None)
53+
self.password = options.get('password', None)
54+
self.encoding = options.get('encoding', None)
55+
self.service = options.get('service', None)
56+
5457
self.safe_limit = settings.get('safe_limit', None)
5558
self.show_query = settings.get('show_query', None)
59+
self.rowsLimit = settings.get('show_records', {}).get('limit', 50)
60+
self.cli = settings.get('cli')[options['type']]
5661

5762
cli_path = shutil.which(self.cli)
5863
if cli_path is None:
@@ -62,7 +67,7 @@ def __init__(self, name, options, settings={}, commandClass='ThreadCommand'):
6267
def __str__(self):
6368
return self.name
6469

65-
def _info(self):
70+
def info(self):
6671
return 'DB: {0}, Connection: {1}@{2}:{3}'.format(
6772
self.database, self.username, self.host, self.port)
6873

SQLToolsAPI/Utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
if dirpath not in sys.path:
1010
sys.path.append(dirpath)
1111

12-
from sqlparse import format
12+
import sqlparse
1313

1414
# Regular expression for comments
1515
comment_re = re.compile(
@@ -66,7 +66,7 @@ def getResultAsList(results):
6666

6767
def formatSql(raw, settings):
6868
try:
69-
result = format(raw, **settings)
69+
result = sqlparse.format(raw, **settings)
7070

7171
return result
7272
except Exception:

SQLToolsAPI/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
'Command',
88
'Connection',
99
'History',
10-
'Settings',
1110
'Storage',
11+
'Settings'
1212
]

0 commit comments

Comments
 (0)