[doc] update API docs

This commit is contained in:
tobi-wan-kenobi 2020-05-10 13:25:13 +02:00
parent 8ca036bc4c
commit b4f8870a95
3 changed files with 72 additions and 2 deletions

View file

@ -27,7 +27,11 @@ THEME_HELP = "Specify the theme to use for drawing modules"
def all_modules(): def all_modules():
"""Return a list of available modules""" """Returns a list of all available modules (either core or contrib)
:return: list of modules
:rtype: list of strings
"""
result = {} result = {}
for path in [modules.core.__file__, modules.contrib.__file__]: for path in [modules.core.__file__, modules.contrib.__file__]:
@ -127,6 +131,11 @@ class print_usage(argparse.Action):
class Config(util.store.Store): class Config(util.store.Store):
"""Represents the configuration of bumblebee-status (either via config file or via CLI)
:param args: The arguments passed via the commandline
"""
def __init__(self, args): def __init__(self, args):
super(Config, self).__init__() super(Config, self).__init__()
@ -202,6 +211,11 @@ class Config(util.store.Store):
key, value = param.split("=", 1) key, value = param.split("=", 1)
self.set(key, value) self.set(key, value)
"""Loads parameters from an init-style configuration file
:param filename: path to the file to load
"""
def load_config(self, filename): def load_config(self, filename):
if os.path.exists(filename): if os.path.exists(filename):
log.info("loading {}".format(filename)) log.info("loading {}".format(filename))
@ -212,27 +226,75 @@ class Config(util.store.Store):
for key, value in tmp.items("module-parameters"): for key, value in tmp.items("module-parameters"):
self.set(key, value) self.set(key, value)
"""Returns a list of configured modules
:return: list of configured (active) modules
:rtype: list of strings
"""
def modules(self): def modules(self):
return [item for sub in self.__args.modules for item in sub] return [item for sub in self.__args.modules for item in sub]
"""Returns the global update interval
:return: update interval in seconds
:rtype: float
"""
def interval(self, default=1): def interval(self, default=1):
return util.format.seconds(self.get("interval", default)) return util.format.seconds(self.get("interval", default))
"""Returns whether debug mode is enabled
:return: True if debug is enabled, False otherwise
:rtype: boolean
"""
def debug(self): def debug(self):
return self.__args.debug return self.__args.debug
"""Returns whether module order should be reversed/inverted
:return: True if modules should be reversed, False otherwise
:rtype: boolean
"""
def reverse(self): def reverse(self):
return self.__args.right_to_left return self.__args.right_to_left
"""Returns the logfile location
:return: location where the logfile should be written
:rtype: string
"""
def logfile(self): def logfile(self):
return self.__args.logfile return self.__args.logfile
"""Returns the configured theme name
:return: name of the configured theme
:rtype: string
"""
def theme(self): def theme(self):
return self.__args.theme return self.__args.theme
"""Returns the configured iconset name
:return: name of the configured iconset
:rtype: string
"""
def iconset(self): def iconset(self):
return self.__args.iconset return self.__args.iconset
"""Returns which modules should be hidden if their state is not warning/critical
:return: list of modules to hide automatically
:rtype: list of strings
"""
def autohide(self, name): def autohide(self, name):
return name in self.__args.autohide return name in self.__args.autohide

View file

@ -8,16 +8,20 @@ def discover():
) )
sys.path.append(libdir) sys.path.append(libdir)
def utility(name): def utility(name):
current_path = os.path.dirname(os.path.abspath(__file__)) current_path = os.path.dirname(os.path.abspath(__file__))
for path in [ for path in [
os.path.join(current_path, "..", "bin"), os.path.join(current_path, "..", "bin"),
os.path.join(current_path, "..", "..", "..", "..", "share", "bumblebee-status", "utility"), os.path.join(
current_path, "..", "..", "..", "..", "share", "bumblebee-status", "utility"
),
"/usr/share/bumblebee-status/bin/", "/usr/share/bumblebee-status/bin/",
]: ]:
if os.path.exists(os.path.abspath(os.path.join(path, name))): if os.path.exists(os.path.abspath(os.path.join(path, name))):
return os.path.abspath(os.path.join(path, name)) return os.path.abspath(os.path.join(path, name))
raise Exception("{} not found".format(name)) raise Exception("{} not found".format(name))
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -24,6 +24,7 @@ class HBar(Bar):
:param value: percentage value to draw (float, between 0 and 100) :param value: percentage value to draw (float, between 0 and 100)
""" """
def __init__(self, value): def __init__(self, value):
super(HBar, self).__init__(value) super(HBar, self).__init__(value)
self.step = MAX_PERCENTS / len(HBar.bars) self.step = MAX_PERCENTS / len(HBar.bars)
@ -69,6 +70,7 @@ class VBar(Bar):
:param value: percentage value to draw (float, between 0 and 100) :param value: percentage value to draw (float, between 0 and 100)
:param width: maximum width of the bar in characters :param width: maximum width of the bar in characters
""" """
def __init__(self, value, width=1): def __init__(self, value, width=1):
super(VBar, self).__init__(value) super(VBar, self).__init__(value)
self.step = MAX_PERCENTS / (len(VBar.bars) * width) self.step = MAX_PERCENTS / (len(VBar.bars) * width)
@ -79,6 +81,7 @@ class VBar(Bar):
:return: characters representing the value passed during initialization :return: characters representing the value passed during initialization
:rtype: string :rtype: string
""" """
def get_chars(self): def get_chars(self):
if self.value == 100: if self.value == 100:
return self.bars[-1] * self.width return self.bars[-1] * self.width
@ -146,6 +149,7 @@ class BrailleGraph(object):
:param values: values to draw :param values: values to draw
""" """
def __init__(self, values): def __init__(self, values):
self.values = values self.values = values
# length of values list must be even # length of values list must be even