From 8ee7ec68bf10072d006d533a585908d27394bce2 Mon Sep 17 00:00:00 2001 From: doulam Date: Fri, 8 Mar 2019 14:46:06 -0700 Subject: [PATCH] Preliminary add connect all --- src/vpn.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/vpn.py b/src/vpn.py index 4a83840..9773656 100755 --- a/src/vpn.py +++ b/src/vpn.py @@ -9,7 +9,6 @@ # """vpn.py (list|connect|disconnect|app) [] [] - Usage: vpn.py list [] vpn.py connect [-a|--all] [] @@ -17,7 +16,6 @@ vpn.py app vpn.py conf [] vpn.py -h - Options: -a, --all Apply action to all connections. -h, --help Show this message and exit. @@ -162,6 +160,15 @@ def disconnect_all(self): for c in connections: self.disconnect(c.name) + def connect_all(self): + """Connect all VPNs.""" + connections = self.filter_connections(active=False) + for c in connection: + log.info(u'connecting "%s" ...', c.name) + + cmd = self.program + ['connect', c.name] + run_command(cmd) + def filter_connections(self, name=None, active=True): """Return connections with matching name and state.""" connections = self.connections @@ -414,6 +421,7 @@ def do_list(query): connections = app.connections active_connections = [c for c in connections if c.active] + inactive_connections = [c for c in connections if not c.active] if len(active_connections) > 0: connected = True @@ -437,6 +445,16 @@ def do_list(query): ) it.setvar('action', 'disconnect') + if len(inactive_connections) > 1: + it = wf.add_item( + 'Connect All', + 'Action this item to open all connections', + arg='--all', + valid=True, + icon=ICON_DISCONNECTED, + ) + it.setvar('action', 'connect') + for con in active_connections: it = wf.add_item( con.name, @@ -536,4 +554,4 @@ def main(wf): if __name__ == '__main__': wf = Workflow3(update_settings=UPDATE_SETTINGS) log = wf.logger - sys.exit(wf.run(main)) + sys.exit(wf.run(main)) \ No newline at end of file