Fix LP#1004793 : Console: Enable use of connect in non-interactive mode
This commit is contained in:
parent
d1f2776463
commit
313a04f9a6
|
@ -55,8 +55,9 @@ class Command(BaseCommand):
|
|||
def do_connect():
|
||||
d = client.connect(host, port, username, password)
|
||||
def on_connect(result):
|
||||
self.console.write("{!success!}Connected to %s:%s!" % (host, port))
|
||||
component.start()
|
||||
if self.console.interactive:
|
||||
self.console.write("{!success!}Connected to %s:%s" % (host, port))
|
||||
return component.start()
|
||||
|
||||
def on_connect_fail(result):
|
||||
try:
|
||||
|
@ -64,6 +65,7 @@ class Command(BaseCommand):
|
|||
except:
|
||||
msg = result.value.args[0]
|
||||
self.console.write("{!error!}Failed to connect to %s:%s with reason: %s" % (host, port, msg))
|
||||
return result
|
||||
|
||||
d.addCallback(on_connect)
|
||||
d.addErrback(on_connect_fail)
|
||||
|
@ -71,7 +73,8 @@ class Command(BaseCommand):
|
|||
|
||||
if client.connected():
|
||||
def on_disconnect(result):
|
||||
do_connect()
|
||||
client.disconnect().addCallback(on_disconnect)
|
||||
self.console.statusbars.update_statusbars()
|
||||
return do_connect()
|
||||
return client.disconnect().addCallback(on_disconnect)
|
||||
else:
|
||||
do_connect()
|
||||
return do_connect()
|
||||
|
|
|
@ -160,10 +160,11 @@ class ConsoleUI(component.Component):
|
|||
# Set the interactive flag to indicate where we should print the output
|
||||
self.interactive = True
|
||||
if args:
|
||||
args = ' '.join(args)
|
||||
# Multiple commands split by ";"
|
||||
commands = [arg.strip() for arg in ' '.join(args).split(';')]
|
||||
self.interactive = False
|
||||
|
||||
# Try to connect to the localhost daemon
|
||||
# Try to connect to the daemon (localhost by default)
|
||||
def on_connect(result):
|
||||
def on_started(result):
|
||||
if not self.interactive:
|
||||
|
@ -172,9 +173,7 @@ class ConsoleUI(component.Component):
|
|||
return self.do_command(cmd)
|
||||
|
||||
d = defer.succeed(None)
|
||||
# If we have args, lets process them and quit
|
||||
# allow multiple commands split by ";"
|
||||
commands = [arg.strip() for arg in args.split(';')]
|
||||
# If we have commands, lets process them, then quit.
|
||||
for command in commands:
|
||||
d.addCallback(do_command, command)
|
||||
|
||||
|
@ -187,8 +186,17 @@ class ConsoleUI(component.Component):
|
|||
component.start().addCallback(on_started)
|
||||
|
||||
def on_connect_fail(result):
|
||||
pass
|
||||
d = client.connect()
|
||||
if not self.interactive:
|
||||
self.do_command('quit')
|
||||
|
||||
connect_cmd = 'connect'
|
||||
if not self.interactive:
|
||||
if commands[0].startswith(connect_cmd):
|
||||
connect_cmd = commands.pop(0)
|
||||
elif 'help' in commands:
|
||||
self.do_command('help')
|
||||
return
|
||||
d = self.do_command(connect_cmd)
|
||||
d.addCallback(on_connect)
|
||||
d.addErrback(on_connect_fail)
|
||||
|
||||
|
|
Loading…
Reference in New Issue