[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
This commit is contained in:
Tobias Witek 2016-11-05 16:33:35 +01:00
parent caceb6f20f
commit 4e0e3ef427
7 changed files with 16 additions and 22 deletions

View file

@ -26,13 +26,13 @@ class print_usage(argparse.Action):
def print_modules(self): def print_modules(self):
for m in bumblebee.module.modules(): for m in bumblebee.module.modules():
print textwrap.fill("{}: {}".format(m.name(), m.description()), print(textwrap.fill("{}: {}".format(m.name(), m.description()),
80, initial_indent=self._indent*2, subsequent_indent=self._indent*3) 80, initial_indent=self._indent*2, subsequent_indent=self._indent*3))
print "{}Parameters:".format(self._indent*2) print("{}Parameters:".format(self._indent*2))
for p in m.parameters(): for p in m.parameters():
print textwrap.fill("* {}".format(p), print(textwrap.fill("* {}".format(p),
80, initial_indent=self._indent*3, subsequent_indent=self._indent*4) 80, initial_indent=self._indent*3, subsequent_indent=self._indent*4))
print "" print("")
class ModuleConfig(object): class ModuleConfig(object):
def __init__(self, config, prefix): def __init__(self, config, prefix):

View file

@ -58,6 +58,6 @@ class Module(object):
return "default" return "default"
def instance(self, widget=None): 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -37,7 +37,7 @@ def get_dnf_info(obj):
bugfixes = 0 bugfixes = 0
enhancements = 0 enhancements = 0
other = 0 other = 0
for line in res.split("\n"): for line in res.decode().split("\n"):
if not line.startswith(" "): continue if not line.startswith(" "): continue
elif "ecurity" in line: elif "ecurity" in line:
for s in str.split(line): for s in str.split(line):

View file

@ -1,4 +1,3 @@
import pyroute2
import netifaces import netifaces
import bumblebee.module import bumblebee.module
@ -39,14 +38,9 @@ class Module(bumblebee.module.Module):
return result return result
def _iswlan(self, intf): def _iswlan(self, intf):
iw = pyroute2.IW() # wifi, wlan, wlp, seems to work for me
ip = pyroute2.IPRoute() if intf.startswith("w"): return True
idx = ip.link_lookup(ifname=intf)[0] return False
try:
iw.get_interface_by_ifindex(idx)
return True
except Exception as e:
return False
def _istunnel(self, intf): def _istunnel(self, intf):
return intf.startswith("tun") return intf.startswith("tun")

View file

@ -41,7 +41,7 @@ class Module(bumblebee.module.Module):
res = subprocess.check_output(shlex.split("pactl info")) res = subprocess.check_output(shlex.split("pactl info"))
channel = "sinks" if self._module == "pasink" else "sources" channel = "sinks" if self._module == "pasink" else "sources"
name = None name = None
for line in res.split("\n"): for line in res.decode().split("\n"):
if line.startswith("Default Sink: ") and channel == "sinks": if line.startswith("Default Sink: ") and channel == "sinks":
name = line[14:] name = line[14:]
if line.startswith("Default Source: ") and channel == "sources": 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))) res = subprocess.check_output(shlex.split("pactl list {}".format(channel)))
found = False found = False
for line in res.split("\n"): for line in res.decode().split("\n"):
if "Name:" in line and found == True: if "Name:" in line and found == True:
break break
if name in line: if name in line:
@ -72,7 +72,7 @@ class Module(bumblebee.module.Module):
self._left = m.group(1) self._left = m.group(1)
self._right = m.group(2) self._right = m.group(2)
result = "" result = ""
if self._mono > 0: if int(self._mono) > 0:
result = "{}%".format(self._mono) result = "{}%".format(self._mono)
elif self._left == self._right: elif self._left == self._right:
result = "{}%".format(self._left) result = "{}%".format(self._left)

View file

@ -26,7 +26,7 @@ class Module(bumblebee.module.Module):
module = self.__module__.split(".")[-1] 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): def widgets(self):
return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt)) return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))

View file

@ -38,7 +38,7 @@ class Output(bumblebee.output.Output):
self._thread.start() self._thread.start()
def start(self): def start(self):
print json.dumps({ "version": 1, "click_events": True }) + "[" print(json.dumps({ "version": 1, "click_events": True }) + "[")
def _draw(self, widgets, theme): def _draw(self, widgets, theme):
for widget in widgets: for widget in widgets: