From 4e0e3ef42776041b90efe35f0df11e7c29f44e22 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 5 Nov 2016 16:33:35 +0100 Subject: [PATCH] [general] Add Python3 support * Change some formatting to please python3 * remote pyroute2 dependency, for which I didn't find a python3 module in Fedora24 this solves #1 --- bumblebee/config.py | 12 ++++++------ bumblebee/module.py | 2 +- bumblebee/modules/dnf.py | 2 +- bumblebee/modules/nic.py | 12 +++--------- bumblebee/modules/pulseaudio.py | 6 +++--- bumblebee/modules/time.py | 2 +- bumblebee/outputs/i3.py | 2 +- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/bumblebee/config.py b/bumblebee/config.py index 4d45ab7..501393d 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -26,13 +26,13 @@ class print_usage(argparse.Action): def print_modules(self): for m in bumblebee.module.modules(): - print textwrap.fill("{}: {}".format(m.name(), m.description()), - 80, initial_indent=self._indent*2, subsequent_indent=self._indent*3) - print "{}Parameters:".format(self._indent*2) + print(textwrap.fill("{}: {}".format(m.name(), m.description()), + 80, initial_indent=self._indent*2, subsequent_indent=self._indent*3)) + print("{}Parameters:".format(self._indent*2)) for p in m.parameters(): - print textwrap.fill("* {}".format(p), - 80, initial_indent=self._indent*3, subsequent_indent=self._indent*4) - print "" + print(textwrap.fill("* {}".format(p), + 80, initial_indent=self._indent*3, subsequent_indent=self._indent*4)) + print("") class ModuleConfig(object): def __init__(self, config, prefix): diff --git a/bumblebee/module.py b/bumblebee/module.py index c842590..6152777 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -58,6 +58,6 @@ class Module(object): return "default" def instance(self, widget=None): - return self.__module__.split(".")[-1] + return self._alias if self._alias else self.__module__.split(".")[-1] # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/dnf.py b/bumblebee/modules/dnf.py index 8ccb7c4..c68d009 100644 --- a/bumblebee/modules/dnf.py +++ b/bumblebee/modules/dnf.py @@ -37,7 +37,7 @@ def get_dnf_info(obj): bugfixes = 0 enhancements = 0 other = 0 - for line in res.split("\n"): + for line in res.decode().split("\n"): if not line.startswith(" "): continue elif "ecurity" in line: for s in str.split(line): diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index fb954ea..cfb7fa4 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -1,4 +1,3 @@ -import pyroute2 import netifaces import bumblebee.module @@ -39,14 +38,9 @@ class Module(bumblebee.module.Module): return result def _iswlan(self, intf): - iw = pyroute2.IW() - ip = pyroute2.IPRoute() - idx = ip.link_lookup(ifname=intf)[0] - try: - iw.get_interface_by_ifindex(idx) - return True - except Exception as e: - return False + # wifi, wlan, wlp, seems to work for me + if intf.startswith("w"): return True + return False def _istunnel(self, intf): return intf.startswith("tun") diff --git a/bumblebee/modules/pulseaudio.py b/bumblebee/modules/pulseaudio.py index 8121dfc..a8cda45 100644 --- a/bumblebee/modules/pulseaudio.py +++ b/bumblebee/modules/pulseaudio.py @@ -41,7 +41,7 @@ class Module(bumblebee.module.Module): res = subprocess.check_output(shlex.split("pactl info")) channel = "sinks" if self._module == "pasink" else "sources" name = None - for line in res.split("\n"): + for line in res.decode().split("\n"): if line.startswith("Default Sink: ") and channel == "sinks": name = line[14:] if line.startswith("Default Source: ") and channel == "sources": @@ -50,7 +50,7 @@ class Module(bumblebee.module.Module): res = subprocess.check_output(shlex.split("pactl list {}".format(channel))) found = False - for line in res.split("\n"): + for line in res.decode().split("\n"): if "Name:" in line and found == True: break if name in line: @@ -72,7 +72,7 @@ class Module(bumblebee.module.Module): self._left = m.group(1) self._right = m.group(2) result = "" - if self._mono > 0: + if int(self._mono) > 0: result = "{}%".format(self._mono) elif self._left == self._right: result = "{}%".format(self._left) diff --git a/bumblebee/modules/time.py b/bumblebee/modules/time.py index 8f16753..4a19649 100644 --- a/bumblebee/modules/time.py +++ b/bumblebee/modules/time.py @@ -26,7 +26,7 @@ class Module(bumblebee.module.Module): module = self.__module__.split(".")[-1] - self._fmt = self._config.parameter("format", default_format(module_format(module))) + self._fmt = self._config.parameter("format", default_format(module)) def widgets(self): return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt)) diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index 0d83e7a..ac72855 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -38,7 +38,7 @@ class Output(bumblebee.output.Output): self._thread.start() def start(self): - print json.dumps({ "version": 1, "click_events": True }) + "[" + print(json.dumps({ "version": 1, "click_events": True }) + "[") def _draw(self, widgets, theme): for widget in widgets: