diff --git a/indicator_alertmanager.py b/indicator_alertmanager.py index af083d146953e03dd1e1f498a6fd9f2492785983..257ac8dbbea6333f1db88f35394981bd72f30464 100755 --- a/indicator_alertmanager.py +++ b/indicator_alertmanager.py @@ -12,15 +12,14 @@ from threading import Thread import plac import gi -gi.require_version('Gtk', '3.0') -gi.require_version('AppIndicator3', '0.1') -#pylint: disable=wrong-import-position -from gi.repository import Gtk, AppIndicator3, GLib import yaml +from gi.repository import Gtk, AppIndicator3, GLib # type: ignore from query_alertmanager import get_alerts -#pylint: enable=wrong-import-position +gi.require_version('Gtk', '3.0') +gi.require_version('AppIndicator3', '0.1') +# pylint: disable=too-many-instance-attributes class Indicator(): """Main class.""" @@ -29,7 +28,8 @@ class Indicator(): """Initialize idicator.""" # Load config - config_file = open(Path.expanduser(config)) + config_file = open(Path.expanduser(config), + encoding="UTF8") # type:ignore opts = yaml.load(config_file, Loader=yaml.FullLoader) self.url = opts.get('url') self.port = opts.get('port', 443) @@ -48,6 +48,7 @@ class Indicator(): # the thread: self.update = Thread(target=self.show_alerts) # daemonize the thread to make the indicator stopable + # pylint: disable=deprecated-method self.update.setDaemon(True) self.update.start() @@ -75,22 +76,22 @@ class Indicator(): """Show alerts.""" while True: alerts = get_alerts(url=self.url, port=self.port, user=self.user, - password=self.password) + password=self.password) # print(alerts) # apply the interface update GLib.idle_add( self.indicator.set_label, alerts['summary'], self.app, - priority=GLib.PRIORITY_DEFAULT ) + priority=GLib.PRIORITY_DEFAULT) if alerts['count'] > 0: - icon = self.icon_red + icon = self.icon_red else: - icon = self.icon_green + icon = self.icon_green - GLib.idle_add( self.indicator.set_icon, icon) + GLib.idle_add(self.indicator.set_icon, icon) time.sleep(30) - def alert_details(self, source): + def alert_details(self): """Open browser with alertmanager URL.""" # alerts = get_alerts() # alert_count = len(alerts) @@ -100,8 +101,7 @@ class Indicator(): # self.menu.append(alerts_item) os.system(f"xdg-open {self.url}:{self.port}") - - def stop(self, source): + def stop(self): """Exit indicator.""" Gtk.main_quit()