[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):
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):

View file

@ -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

View file

@ -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):

View file

@ -1,4 +1,3 @@
import pyroute2
import netifaces
import bumblebee.module
@ -39,13 +38,8 @@ 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:
# wifi, wlan, wlp, seems to work for me
if intf.startswith("w"): return True
return False
def _istunnel(self, intf):

View file

@ -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)

View file

@ -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))

View file

@ -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: