summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-09-27 12:52:29 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-27 12:53:23 -0400
commitbe5feead1469863982560b7cf75f5bfca627e21c (patch)
treefefc12c281c9dbf158591458313c1c6d44487cd8 /src/leap/bitmask/cli
parent321dd225e40be8f3e0c2e058f831ab804ca622b0 (diff)
[feature] try to launch backend on cli commands
Diffstat (limited to 'src/leap/bitmask/cli')
-rwxr-xr-xsrc/leap/bitmask/cli/bitmask_cli.py15
-rw-r--r--src/leap/bitmask/cli/command.py16
-rw-r--r--src/leap/bitmask/cli/logs.py1
3 files changed, 21 insertions, 11 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py
index 64fe74b..736e737 100755
--- a/src/leap/bitmask/cli/bitmask_cli.py
+++ b/src/leap/bitmask/cli/bitmask_cli.py
@@ -95,7 +95,6 @@ GENERAL COMMANDS:
return defer.succeed(None)
def version(self, raw_args):
- print(Fore.GREEN + 'bitmaskctl: ' + Fore.RESET + '0.0.1')
self.data = ['version']
return self._send(printer=self._print_version)
@@ -117,10 +116,20 @@ GENERAL COMMANDS:
value + Fore.RESET)
+@defer.inlineCallbacks
def execute():
cli = BitmaskCLI()
- d = cli.execute(sys.argv[1:])
- d.addCallback(lambda _: reactor.stop())
+ cli.data = ['version']
+ yield cli._send(
+ timeout=0.1, printer=_null_printer,
+ errb=lambda: cli.start(None))
+ cli.data = []
+ yield cli.execute(sys.argv[1:])
+ yield reactor.stop()
+
+
+def _null_printer(*args):
+ pass
def main():
diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py
index 36552c0..1694956 100644
--- a/src/leap/bitmask/cli/command.py
+++ b/src/leap/bitmask/cli/command.py
@@ -96,10 +96,10 @@ class Command(object):
self.parser.print_help()
return defer.succeed(None)
- def _send(self, printer=_print_result):
- d = self._conn.sendMsg(*self.data, timeout=60)
+ def _send(self, printer=_print_result, timeout=60, errb=None):
+ d = self._conn.sendMsg(*self.data, timeout=timeout)
d.addCallback(self._check_err, printer)
- d.addErrback(self._timeout_handler)
+ d.addErrback(self._timeout_handler, errb)
return d
def _error(self, msg):
@@ -113,8 +113,10 @@ class Command(object):
else:
print Fore.RED + 'ERROR:' + '%s' % obj['error'] + Fore.RESET
- def _timeout_handler(self, failure):
- # TODO ---- could try to launch the bitmask daemon here and retry
+ def _timeout_handler(self, failure, errb):
if failure.trap(ZmqRequestTimeoutError) == ZmqRequestTimeoutError:
- print (Fore.RED + "[ERROR] Timeout contacting the bitmask daemon. "
- "Is it running?" + Fore.RESET)
+ if callable(errb):
+ errb()
+ else:
+ print (Fore.RED + "[ERROR] Timeout contacting the bitmask "
+ "daemon. Is it running?" + Fore.RESET)
diff --git a/src/leap/bitmask/cli/logs.py b/src/leap/bitmask/cli/logs.py
index 11903ee..59ed64d 100644
--- a/src/leap/bitmask/cli/logs.py
+++ b/src/leap/bitmask/cli/logs.py
@@ -29,7 +29,6 @@ from twisted.python.procutils import which
from leap.bitmask.cli import command
from leap.common.config import get_path_prefix
-
class Logs(command.Command):