From caceb6f20f978c7f04be748724b8f48549dbcb78 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 5 Nov 2016 16:18:53 +0100 Subject: [PATCH] [help] Update and beautify the commandline help output --- bumblebee/config.py | 13 ++++++------- bumblebee/module.py | 12 +++--------- bumblebee/modules/battery.py | 9 +++------ bumblebee/modules/cpu.py | 12 ++++++------ bumblebee/modules/disk.py | 12 ++++++------ bumblebee/modules/dnf.py | 9 +++------ bumblebee/modules/memory.py | 12 ++++++------ bumblebee/modules/nic.py | 9 +++------ bumblebee/modules/pulseaudio.py | 16 ++++------------ bumblebee/modules/spacer.py | 11 ++++------- bumblebee/modules/time.py | 32 +++++++++++++++----------------- 11 files changed, 59 insertions(+), 88 deletions(-) diff --git a/bumblebee/config.py b/bumblebee/config.py index a990c7f..4d45ab7 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -26,13 +26,12 @@ class print_usage(argparse.Action): def print_modules(self): for m in bumblebee.module.modules(): - print("{}{}: ".format(self._indent, m.name())) - print textwrap.fill("About : {}".format(m.description()), - 80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) - print textwrap.fill("Usage : {}".format(m.usage()), - 80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) - print textwrap.fill("Notes : {}".format(m.notes()), - 80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) + 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 "" class ModuleConfig(object): diff --git a/bumblebee/module.py b/bumblebee/module.py index aac2c3a..c842590 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -21,16 +21,10 @@ class ModuleDescription(object): return str(self._name) def description(self): - return getattr(self._mod, "description", self.na)() + return getattr(self._mod, "description", lambda: "n/a")() - def usage(self): - return getattr(self._mod, "usage", self.na)() - - def notes(self): - return getattr(self._mod, "notes", self.na)() - - def na(self): - return "n/a" + def parameters(self): + return getattr(self._mod, "parameters", lambda: [ "n/a" ])() class Module(object): def __init__(self, output, config, alias=None): diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 4b4e96f..10a2600 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -1,15 +1,12 @@ import datetime import bumblebee.module -def usage(): - return "battery or battery::" - -def notes(): - return "Reads /sys/class/power_supply//[capacity|status]. Warning is at 20% remaining charge, Critical at 10%." - def description(): return "Displays battery status, percentage and whether it's charging or discharging." +def parameters(): + return [ "battery.device: The device to read from (defaults to BAT0)" ] + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/cpu.py b/bumblebee/modules/cpu.py index 46d6614..b156b37 100644 --- a/bumblebee/modules/cpu.py +++ b/bumblebee/modules/cpu.py @@ -1,15 +1,15 @@ import bumblebee.module import psutil -def usage(): - return "cpu" - -def notes(): - return "Warning is at 70%, Critical at 80%." - def description(): return "Displays CPU utilization across all CPUs." +def parameters(): + return [ + "cpu.warning: Warning threshold in % of disk usage (defaults to 70%)", + "cpu.critical: Critical threshold in % of disk usage (defaults to 80%)", + ] + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/disk.py b/bumblebee/modules/disk.py index 17c8e40..3cc3b6c 100644 --- a/bumblebee/modules/disk.py +++ b/bumblebee/modules/disk.py @@ -2,15 +2,15 @@ import os import bumblebee.util import bumblebee.module -def usage(): - return "disk or disk::" - -def notes(): - return "Warning is at 20% free diskspace, Critical at 10%." - def description(): return "Shows free diskspace, total diskspace and the percentage of free disk space." +def parameters(): + return [ + "disk.warning: Warning threshold in % (defaults to 80%)", + "disk.critical: Critical threshold in % (defaults to 90%)" + ] + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/dnf.py b/bumblebee/modules/dnf.py index bff25d7..8ccb7c4 100644 --- a/bumblebee/modules/dnf.py +++ b/bumblebee/modules/dnf.py @@ -8,15 +8,12 @@ import subprocess import bumblebee.module import bumblebee.util -def usage(): - return "dnf or dnf::" - -def notes(): - return "Spawns a separate thread that invokes 'dnf updateinfo' every seconds. Critical status is if there is either more than 50 updates pending, or at least one of them is a security update." - def description(): return "Checks DNF for updated packages and displays the number of /// pending updates." +def parameters(): + return [ "dnf.interval: Time in seconds between two checks for updates (defaults to 1800)" ] + def get_dnf_info(obj): loops = obj.interval() diff --git a/bumblebee/modules/memory.py b/bumblebee/modules/memory.py index 6b7070d..d8d08b2 100644 --- a/bumblebee/modules/memory.py +++ b/bumblebee/modules/memory.py @@ -2,15 +2,15 @@ import psutil import bumblebee.module import bumblebee.util -def usage(): - return "memory" - -def notes(): - return "Warning is at 20% available RAM, Critical at 10%." - def description(): return "Shows available RAM, total amount of RAM and the percentage of available RAM." +def parameters(): + return [ + "memory.warning: Warning threshold in % of memory still available (defaults to 20%)", + "memory.critical: Critical threshold in % of memory still available (defaults to 10%)", + ] + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index 6cff11f..fb954ea 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -2,15 +2,12 @@ import pyroute2 import netifaces import bumblebee.module -def usage(): - return "nic" - -def notes(): - return "Interfaces starting with 'lo' or 'virbr' are ignored. Critical if the status of an interface is 'down', Warning if it is anything else but 'up'. Interface status is derived from whether an IP address is available or not." - def description(): return "Displays the names, IP addresses and status of each available interface." +def parameters(): + return [ "none" ] + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/pulseaudio.py b/bumblebee/modules/pulseaudio.py index 66412b8..8121dfc 100644 --- a/bumblebee/modules/pulseaudio.py +++ b/bumblebee/modules/pulseaudio.py @@ -5,18 +5,6 @@ import subprocess import bumblebee.module import bumblebee.util -def usage(): - module = __name__.split(".")[-1] - if module == "pasource": - return "pasource" - if module == "pasink": - return "pasink" - return "pulseaudio" - -def notes(): - return "Invokes 'pactl' to retrieve information." - pass - def description(): module = __name__.split(".")[-1] if module == "pasink": @@ -25,6 +13,10 @@ def description(): return "Shows volume and mute status of the default PulseAudio Source." return "See 'pasource'." +def parameters(): + return [ "none" ] + + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) diff --git a/bumblebee/modules/spacer.py b/bumblebee/modules/spacer.py index d72cc1d..798338e 100644 --- a/bumblebee/modules/spacer.py +++ b/bumblebee/modules/spacer.py @@ -1,14 +1,11 @@ import bumblebee.module import bumblebee.util -def usage(): - return "spacer" - -def notes(): - return "none" - def description(): - return "Draws an empty field." + return "Draws a widget with configurable content." + +def parameters(): + return [ "spacer.text: Text to draw (defaults to '')" ] class Module(bumblebee.module.Module): def __init__(self, output, config, alias): diff --git a/bumblebee/modules/time.py b/bumblebee/modules/time.py index 2046d46..8f16753 100644 --- a/bumblebee/modules/time.py +++ b/bumblebee/modules/time.py @@ -3,32 +3,30 @@ from __future__ import absolute_import import datetime import bumblebee.module -def usage(): - module = __name__.split(".")[-1] - if module == "date": - return "date::" - if module == "time": - return "time::" - return "datetime::" - -def notes(): - return "none" - def description(): return "Displays the current time, using the optional format string as input for strftime." +def parameters(): + module = __name__.split(".")[-1] + return [ + "{}.format: strftime specification (defaults to {})".format(module, default_format(module)) + ] + +def default_format(module): + default = "%x %X" + if module == "date": + default = "%x" + if module == "time": + default = "%X" + return default + class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) module = self.__module__.split(".")[-1] - default = "%x %X" - if module == "date": - default = "%x" - if module == "time": - default = "%X" - self._fmt = self._config.parameter("format", default) + self._fmt = self._config.parameter("format", default_format(module_format(module))) def widgets(self): return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))