summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-08-28 17:04:14 +0200
committerRuben Pollan <meskio@sindominio.net>2017-08-31 11:04:38 +0200
commitf19bfeb73fc19747bd02cbbd5c024de4dc86b5a8 (patch)
tree2dc001b06043887c22fd40c966cb6af3f92de187
parentf476bdd9a769364bec7c342b5b6399530d4d454a (diff)
[refactor] make the VPN location formating in the cli
-rw-r--r--src/leap/bitmask/cli/vpn.py19
-rw-r--r--src/leap/bitmask/vpn/service.py8
2 files changed, 19 insertions, 8 deletions
diff --git a/src/leap/bitmask/cli/vpn.py b/src/leap/bitmask/cli/vpn.py
index 44556ac2..5a9cce9e 100644
--- a/src/leap/bitmask/cli/vpn.py
+++ b/src/leap/bitmask/cli/vpn.py
@@ -20,6 +20,8 @@ Bitmask Command Line interface: vpn module
import argparse
import sys
+from colorama import Fore
+
from leap.bitmask.cli import command
@@ -97,7 +99,7 @@ SUBCOMMANDS:
def list(self, raw_args):
self.data += ['list']
- return self._send(command.default_dict_printer)
+ return self._send(location_printer)
def get_cert(self, raw_args):
parser = argparse.ArgumentParser(
@@ -115,3 +117,18 @@ SUBCOMMANDS:
self.data += ['get_cert', uid]
return self._send(command.default_dict_printer)
+
+
+def location_printer(result):
+ def pprint(key, value):
+ print(Fore.RESET + key.ljust(20) + Fore.GREEN +
+ value + Fore.RESET)
+
+ for provider, locations in result.items():
+ for loc in locations.values():
+ location_str = ("[%(country_code)s] %(name)s "
+ "(UTC%(timezone)s %(hemisphere)s)" % loc)
+ pprint(provider, location_str)
+
+ if not locations.values():
+ pprint(provider, "---")
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index 71fb8651..f4af3036 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -194,13 +194,7 @@ class VPNService(HookableService):
config = yield bonafide.do_provider_read(provider, 'eip')
except ValueError:
continue
- locations = config.locations
- info = tuple([
- ('[%s]' % locations[loc]['country_code'],
- locations[loc]['name'],
- '(UTC%s)' % locations[loc]['timezone'])
- for loc in locations])
- provider_dict[provider] = info
+ provider_dict[provider] = config.locations
defer.returnValue(provider_dict)
@defer.inlineCallbacks