Skip to content

Commit 7a0f48a

Browse files
committed
Couple of bug fixes
* Use integer division when calculating width for help formatter * In dbexec, if instance doesn't exist, don't just crash - report it as a runtime error properly
1 parent 283897c commit 7a0f48a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Diff for: dbsuite/instance.py

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def get_instance(name=None):
6969
close_fds=True
7070
)
7171
output = p.communicate()[0]
72+
if p.returncode != 0:
73+
raise ValueError(
74+
'Instance %s does not exist or cannot be sourced' % name)
7275
for line in output.splitlines():
7376
var, value = line.split('=', 1)
7477
result[var] = value

Diff for: dbsuite/main/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class HelpFormatter(optparse.IndentedHelpFormatter):
4646
# Customize the width of help output
4747
def __init__(self):
4848
width = min(130, terminal_size()[0] - 2)
49-
optparse.IndentedHelpFormatter.__init__(self, max_help_position=width/3, width=width)
49+
optparse.IndentedHelpFormatter.__init__(self, max_help_position=width // 3, width=width)
5050

5151

5252
class OptionParser(optparse.OptionParser):
@@ -103,6 +103,7 @@ def __init__(self, usage=None, version=None, description=None):
103103
help='enables debug mode (runs under PDB)')
104104

105105
def __call__(self, args=None):
106+
import pdb; pdb.set_trace()
106107
if args is None:
107108
args = sys.argv[1:]
108109
(options, args) = self.parser.parse_args(self.expand_args(args))

Diff for: dbsuite/script.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ def test_connection(self, connection):
308308
"""Utility routine for testing database logins prior to script execution."""
309309
saved_instance = None
310310
if connection.instance:
311-
saved_instance = get_instance()
312-
set_instance(get_instance(connection.instance))
311+
try:
312+
saved_instance = get_instance()
313+
set_instance(get_instance(connection.instance))
314+
except Exception, e:
315+
raise ScriptRuntimeError(str(e))
313316
try:
314317
args = [
315318
'-o', # enable output

0 commit comments

Comments
 (0)