Remove Microsoft Carriage Return and Line Feed.

This patch get rid of the Microsoft CR and LF in the following modules:
- pihole.py
- vpn.py

Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2019-07-02 11:55:19 +02:00
parent 16a308a534
commit 49f32f9a49
2 changed files with 163 additions and 163 deletions

View file

@ -1,68 +1,68 @@
# pylint: disable=C0111,R0903 # pylint: disable=C0111,R0903
"""Displays the pi-hole status (up/down) together with the number of ads that were blocked today """Displays the pi-hole status (up/down) together with the number of ads that were blocked today
Parameters: Parameters:
* pihole.address : pi-hole address (e.q: http://192.168.1.3) * pihole.address : pi-hole address (e.q: http://192.168.1.3)
* pihole.pwhash : pi-hole webinterface password hash (can be obtained from the /etc/pihole/SetupVars.conf file) * pihole.pwhash : pi-hole webinterface password hash (can be obtained from the /etc/pihole/SetupVars.conf file)
""" """
import bumblebee.input import bumblebee.input
import bumblebee.output import bumblebee.output
import bumblebee.engine import bumblebee.engine
import requests import requests
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
super(Module, self).__init__(engine, config, super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.pihole_status) bumblebee.output.Widget(full_text=self.pihole_status)
) )
buttons = {"LEFT_CLICK":bumblebee.input.LEFT_MOUSE} buttons = {"LEFT_CLICK":bumblebee.input.LEFT_MOUSE}
self._pihole_address = self.parameter("address", "") self._pihole_address = self.parameter("address", "")
self._pihole_pw_hash = self.parameter("pwhash", "") self._pihole_pw_hash = self.parameter("pwhash", "")
self._pihole_status = None self._pihole_status = None
self._ads_blocked_today = "-" self._ads_blocked_today = "-"
self.update_pihole_status() self.update_pihole_status()
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=self.toggle_pihole_status) cmd=self.toggle_pihole_status)
def pihole_status(self, widget): def pihole_status(self, widget):
if self._pihole_status is None: if self._pihole_status is None:
return "pi-hole unknown" return "pi-hole unknown"
return "pi-hole " + ("up/" + self._ads_blocked_today if self._pihole_status else "down") return "pi-hole " + ("up/" + self._ads_blocked_today if self._pihole_status else "down")
def update_pihole_status(self): def update_pihole_status(self):
try: try:
data = requests.get(self._pihole_address + "/admin/api.php?summary").json() data = requests.get(self._pihole_address + "/admin/api.php?summary").json()
self._pihole_status = True if data["status"] == "enabled" else False self._pihole_status = True if data["status"] == "enabled" else False
self._ads_blocked_today = data["ads_blocked_today"] self._ads_blocked_today = data["ads_blocked_today"]
except: except:
self._pihole_status = None self._pihole_status = None
def toggle_pihole_status(self, widget): def toggle_pihole_status(self, widget):
if self._pihole_status is not None: if self._pihole_status is not None:
try: try:
req = None req = None
if self._pihole_status: if self._pihole_status:
req = requests.get(self._pihole_address + "/admin/api.php?disable&auth=" + self._pihole_pw_hash) req = requests.get(self._pihole_address + "/admin/api.php?disable&auth=" + self._pihole_pw_hash)
else: else:
req = requests.get(self._pihole_address + "/admin/api.php?enable&auth=" + self._pihole_pw_hash) req = requests.get(self._pihole_address + "/admin/api.php?enable&auth=" + self._pihole_pw_hash)
if req is not None: if req is not None:
if req.status_code == 200: if req.status_code == 200:
status = req.json()["status"] status = req.json()["status"]
self._pihole_status = False if status == "disabled" else True self._pihole_status = False if status == "disabled" else True
except: except:
pass pass
def update(self, widgets): def update(self, widgets):
self.update_pihole_status() self.update_pihole_status()
def state(self, widget): def state(self, widget):
if self._pihole_status is None: if self._pihole_status is None:
return [] return []
elif self._pihole_status: elif self._pihole_status:
return ["enabled"] return ["enabled"]
return ["disabled", "warning"] return ["disabled", "warning"]

View file

@ -1,95 +1,95 @@
# pylint: disable=C0111,R0903 # pylint: disable=C0111,R0903
""" Displays the VPN profile that is currently in use. """ Displays the VPN profile that is currently in use.
Left click opens a popup menu that lists all available VPN profiles and allows to establish Left click opens a popup menu that lists all available VPN profiles and allows to establish
a VPN connection using that profile. a VPN connection using that profile.
Prerequisites: Prerequisites:
* nmcli needs to be installed and configured properly. * nmcli needs to be installed and configured properly.
To quickly test, whether nmcli is working correctly, type "nmcli -g NAME,TYPE,DEVICE con" which To quickly test, whether nmcli is working correctly, type "nmcli -g NAME,TYPE,DEVICE con" which
lists all the connection profiles that are configured. Make sure that your VPN profile is in that list! lists all the connection profiles that are configured. Make sure that your VPN profile is in that list!
e.g: to import a openvpn profile via nmcli: e.g: to import a openvpn profile via nmcli:
sudo nmcli connection import type openvpn file </path/to/your/openvpn/profile.ovpn> sudo nmcli connection import type openvpn file </path/to/your/openvpn/profile.ovpn>
""" """
import logging import logging
import bumblebee.input import bumblebee.input
import bumblebee.output import bumblebee.output
import bumblebee.engine import bumblebee.engine
import functools import functools
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
super(Module, self).__init__(engine, config, super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.vpn_status) bumblebee.output.Widget(full_text=self.vpn_status)
) )
self._connected_vpn_profile = None self._connected_vpn_profile = None
self._selected_vpn_profile = None self._selected_vpn_profile = None
res = bumblebee.util.execute("nmcli -g NAME,TYPE c") res = bumblebee.util.execute("nmcli -g NAME,TYPE c")
lines = res.splitlines() lines = res.splitlines()
self._vpn_profiles = [] self._vpn_profiles = []
for line in lines: for line in lines:
info = line.split(':') info = line.split(':')
try: try:
if info[1] == "vpn": if info[1] == "vpn":
self._vpn_profiles.append(info[0]) self._vpn_profiles.append(info[0])
except: except:
pass pass
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=self.popup) cmd=self.popup)
def update(self, widgets): def update(self, widgets):
try: try:
res = bumblebee.util.execute("nmcli -g NAME,TYPE,DEVICE con") res = bumblebee.util.execute("nmcli -g NAME,TYPE,DEVICE con")
lines = res.splitlines() lines = res.splitlines()
self._connected_vpn_profile = None self._connected_vpn_profile = None
for line in lines: for line in lines:
info = line.split(':') info = line.split(':')
if info[1] == "vpn" and info[2] != "": if info[1] == "vpn" and info[2] != "":
self._connected_vpn_profile = info[0] self._connected_vpn_profile = info[0]
except Exception as e: except Exception as e:
logging.exception("Couldn't get VPN status") logging.exception("Couldn't get VPN status")
self._connected_vpn_profile = None self._connected_vpn_profile = None
def vpn_status(self, widget): def vpn_status(self, widget):
if self._connected_vpn_profile is None: if self._connected_vpn_profile is None:
return "off" return "off"
return self._connected_vpn_profile return self._connected_vpn_profile
def _on_vpn_disconnect(self): def _on_vpn_disconnect(self):
try: try:
bumblebee.util.execute("nmcli c down " + self._connected_vpn_profile) bumblebee.util.execute("nmcli c down " + self._connected_vpn_profile)
self._connected_vpn_profile = None self._connected_vpn_profile = None
except Exception as e: except Exception as e:
logging.exception("Couldn't disconnect VPN connection") logging.exception("Couldn't disconnect VPN connection")
def _on_vpn_connect(self, name): def _on_vpn_connect(self, name):
self._selected_vpn_profile = name self._selected_vpn_profile = name
try: try:
bumblebee.util.execute("nmcli c up " + self._selected_vpn_profile) bumblebee.util.execute("nmcli c up " + self._selected_vpn_profile)
self._connected_vpn_profile = name self._connected_vpn_profile = name
except Exception as e: except Exception as e:
logging.exception("Couldn't establish VPN connection") logging.exception("Couldn't establish VPN connection")
self._connected_vpn_profile = None self._connected_vpn_profile = None
def popup(self, widget): def popup(self, widget):
menu = bumblebee.popup_v2.PopupMenu() menu = bumblebee.popup_v2.PopupMenu()
if self._connected_vpn_profile is not None: if self._connected_vpn_profile is not None:
menu.add_menuitem("Disconnect", callback=self._on_vpn_disconnect) menu.add_menuitem("Disconnect", callback=self._on_vpn_disconnect)
for vpn_profile in self._vpn_profiles: for vpn_profile in self._vpn_profiles:
if self._connected_vpn_profile is not None and self._connected_vpn_profile == vpn_profile: if self._connected_vpn_profile is not None and self._connected_vpn_profile == vpn_profile:
continue continue
menu.add_menuitem(vpn_profile, callback=functools.partial(self._on_vpn_connect, vpn_profile)) menu.add_menuitem(vpn_profile, callback=functools.partial(self._on_vpn_connect, vpn_profile))
menu.show(widget) menu.show(widget)
def state(self, widget): def state(self, widget):
return [] return []