Merge remote-tracking branch 'upstream/master'

This commit is contained in:
mw 2019-09-05 20:27:04 +02:00
commit 15fb6fc94d
10 changed files with 28 additions and 19 deletions

View file

@ -25,7 +25,7 @@ def all_modules():
"name": mod
})
return result
class Module(object):
"""Module instance base class
@ -231,14 +231,25 @@ class Engine(object):
button=button["id"], cmd=module.parameter(button["name"]))
def _read_aliases(self):
"""Retruns a dictionary that maps every alias to its real module name"""
result = {}
for module in all_modules():
m_path = os.path.abspath(bumblebee.modules.__file__)
m_path = os.path.dirname(m_path)
ALIASES_PATH = m_path + "/aliases/"
for name in os.listdir(ALIASES_PATH):
try:
mod = importlib.import_module("bumblebee.modules.{}".format(module["name"]))
for alias in getattr(mod, "ALIASES", []):
result[alias] = module["name"]
# listdir does not retur full paths
f_path = ALIASES_PATH + name
# skip any directory
if not os.path.isfile(f_path): continue
with open(f_path) as f:
for alias in f.readlines():
alias = alias.strip()
# skip empty lines
if len(alias) == 0: continue
result[alias] = name
except Exception as error:
log.warning("failed to import {}: {}".format(module["name"], str(error)))
log.warning("failed to load aliases of {}: {}".format(name, str(error)))
return result
def _load_module(self, module_name, config_name=None):

View file

@ -0,0 +1,2 @@
date
time

View file

@ -0,0 +1,2 @@
datetz
timetz

View file

@ -0,0 +1,2 @@
pasink
pasource

View file

@ -0,0 +1 @@
test-alias

View file

@ -25,11 +25,10 @@ except ImportError:
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
self._batteries = []
# TODO: list all batteries
self._batteries.append("/sys/class/power_supply/BAT0")
self._batteries.append("/sys/class/power_supply/BAT1")
self._batteries.append("/sys/class/power_supply/battery")
for battery in os.listdir('/sys/class/power_supply/'):
if not any(i in battery for i in ['AC', 'hidpp']):
self._batteries.append("/sys/class/power_supply/" + battery)
super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity))
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,

View file

@ -16,8 +16,6 @@ import datetime
import locale
import bumblebee.engine
ALIASES = ["date", "time"]
def default_format(module):
default = "%x %X"
if module == "date":

View file

@ -26,8 +26,6 @@ import bumblebee.input
import bumblebee.output
import bumblebee.engine
ALIASES = ["datetz", "timetz"]
def default_format(module):
default = "%x %X %Z"
if module == "datetz":

View file

@ -24,8 +24,6 @@ import bumblebee.input
import bumblebee.output
import bumblebee.engine
ALIASES = ["pasink", "pasource"]
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config,

View file

@ -5,8 +5,6 @@
import bumblebee.engine
ALIASES = ["test-alias"]
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config,