summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-05 12:18:02 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-07 10:22:36 -0400
commit4a471fb8b434d3df07c5de42fc41590b5d9fc5f5 (patch)
treeca72e66088ac8fea08c74e80405006afa66788c5 /src/leap
parent01ff6420b503ed98cc04f295fec1d803d31b97fb (diff)
[feature] logs watch command
Diffstat (limited to 'src/leap')
-rwxr-xr-xsrc/leap/bitmask/cli/bitmask_cli.py13
-rw-r--r--src/leap/bitmask/cli/logs.py28
2 files changed, 37 insertions, 4 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py
index 736e7376..ab3c2069 100755
--- a/src/leap/bitmask/cli/bitmask_cli.py
+++ b/src/leap/bitmask/cli/bitmask_cli.py
@@ -20,6 +20,7 @@ Bitmask Command Line interface: zmq client.
"""
import json
import sys
+import signal
from colorama import Fore
from twisted.internet import reactor, defer
@@ -125,15 +126,25 @@ def execute():
errb=lambda: cli.start(None))
cli.data = []
yield cli.execute(sys.argv[1:])
- yield reactor.stop()
+ try:
+ yield reactor.stop()
+ except:
+ pass
def _null_printer(*args):
pass
+
def main():
+ def signal_handler(signal, frame):
+ if reactor.running:
+ reactor.stop()
+ sys.exit(0)
+
reactor.callWhenRunning(reactor.callLater, 0, execute)
+ signal.signal(signal.SIGINT, signal_handler)
reactor.run()
if __name__ == "__main__":
diff --git a/src/leap/bitmask/cli/logs.py b/src/leap/bitmask/cli/logs.py
index 59ed64d6..0976ebc9 100644
--- a/src/leap/bitmask/cli/logs.py
+++ b/src/leap/bitmask/cli/logs.py
@@ -21,6 +21,7 @@ import argparse
import commands
import os.path
import sys
+import time
from colorama import Fore
@@ -39,6 +40,7 @@ Bitmask Log Handling
SUBCOMMANDS:
send Send last bitmaskd log
+ watch Display logs stream
'''.format(name=command.appname)
def send(self, raw_args):
@@ -46,14 +48,34 @@ SUBCOMMANDS:
if not _bin:
error('pastebinit not found. install it to upload logs.')
return defer.succeed(None)
- log_path = os.path.abspath(
- os.path.join(get_path_prefix(), 'leap', 'bitmaskd.log'))
output = commands.getoutput('{0} -b {1} {2}'.format(
- _bin[0], 'paste.debian.net', log_path))
+ _bin[0], 'paste.debian.net', _log_path))
uri = output.replace('debian.net/', 'debian.net/plain/')
success(uri)
return defer.succeed(None)
+ def watch(self, raw_args):
+ def tail(_file):
+ _file.seek(0,2) # Go to the end of the file
+ while True:
+ line = _file.readline()
+ if not line:
+ time.sleep(0.1)
+ continue
+ yield line
+
+ _file = open(_log_path, 'r')
+ print (Fore.GREEN + '[bitmask] ' +
+ Fore.RESET + 'Watching log file %s' % _log_path )
+ for line in _file.readlines():
+ print line,
+ for line in tail(_file):
+ print line,
+
+
+_log_path = os.path.abspath(
+ os.path.join(get_path_prefix(), 'leap', 'bitmaskd.log'))
+
def error(msg):
print Fore.RED + msg + Fore.RESET