Use str.format instead of C-style format

Signed-off-by: Antoine Bardoux <antoine.b@padoa-group.com>
This commit is contained in:
Antoine Bardoux 2021-08-19 15:16:52 +02:00 committed by enkore
parent 1498c44063
commit 3bd37173a1

View File

@ -28,9 +28,9 @@ class Wireguard(IntervalModule):
status_down = '' status_down = ''
format = "{vpn_name} {status}" format = "{vpn_name} {status}"
status_command = "systemctl is-active wg-quick@%(vpn_name)s" status_command = "systemctl is-active wg-quick@{vpn_name}"
vpn_up_command = "sudo /bin/systemctl start wg-quick@%(vpn_name)s.service" vpn_up_command = "sudo /bin/systemctl start wg-quick@{vpn_name}.service"
vpn_down_command = "sudo /bin/systemctl stop wg-quick@%(vpn_name)s.service" vpn_down_command = "sudo /bin/systemctl stop wg-quick@{vpn_name}.service"
connected = False connected = False
label = '' label = ''
@ -57,13 +57,13 @@ class Wireguard(IntervalModule):
command = self.vpn_down_command command = self.vpn_down_command
else: else:
command = self.vpn_up_command command = self.vpn_up_command
run_through_shell(command % {'vpn_name': self.vpn_name}) run_through_shell(command.format(vpn_name=self.vpn_name))
def on_click(self, button, **kwargs): def on_click(self, button, **kwargs):
self.toggle_connection() self.toggle_connection()
def run(self): def run(self):
command_result = run_through_shell(self.status_command % {'vpn_name': self.vpn_name}) command_result = run_through_shell(self.status_command.format(vpn_name=self.vpn_name))
self.connected = command_result.rc == 0 self.connected = command_result.rc == 0
if self.connected: if self.connected: