[help] Update and beautify the commandline help output

This commit is contained in:
Tobias Witek 2016-11-05 16:18:53 +01:00
parent 3af8ee771d
commit caceb6f20f
11 changed files with 59 additions and 88 deletions

View file

@ -26,13 +26,12 @@ 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("{}{}: ".format(self._indent, m.name())) print textwrap.fill("{}: {}".format(m.name(), m.description()),
print textwrap.fill("About : {}".format(m.description()), 80, initial_indent=self._indent*2, subsequent_indent=self._indent*3)
80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) print "{}Parameters:".format(self._indent*2)
print textwrap.fill("Usage : {}".format(m.usage()), for p in m.parameters():
80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) print textwrap.fill("* {}".format(p),
print textwrap.fill("Notes : {}".format(m.notes()), 80, initial_indent=self._indent*3, subsequent_indent=self._indent*4)
80, initial_indent=self._indent*2, subsequent_indent=self._indent*4)
print "" print ""
class ModuleConfig(object): class ModuleConfig(object):

View file

@ -21,16 +21,10 @@ class ModuleDescription(object):
return str(self._name) return str(self._name)
def description(self): def description(self):
return getattr(self._mod, "description", self.na)() return getattr(self._mod, "description", lambda: "n/a")()
def usage(self): def parameters(self):
return getattr(self._mod, "usage", self.na)() return getattr(self._mod, "parameters", lambda: [ "n/a" ])()
def notes(self):
return getattr(self._mod, "notes", self.na)()
def na(self):
return "n/a"
class Module(object): class Module(object):
def __init__(self, output, config, alias=None): def __init__(self, output, config, alias=None):

View file

@ -1,15 +1,12 @@
import datetime import datetime
import bumblebee.module import bumblebee.module
def usage():
return "battery or battery::<battery ID, defaults to BAT0>"
def notes():
return "Reads /sys/class/power_supply/<ID>/[capacity|status]. Warning is at 20% remaining charge, Critical at 10%."
def description(): def description():
return "Displays battery status, percentage and whether it's charging or discharging." 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -1,15 +1,15 @@
import bumblebee.module import bumblebee.module
import psutil import psutil
def usage():
return "cpu"
def notes():
return "Warning is at 70%, Critical at 80%."
def description(): def description():
return "Displays CPU utilization across all CPUs." 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -2,15 +2,15 @@ import os
import bumblebee.util import bumblebee.util
import bumblebee.module import bumblebee.module
def usage():
return "disk or disk::<path, defaults to '/'>"
def notes():
return "Warning is at 20% free diskspace, Critical at 10%."
def description(): def description():
return "Shows free diskspace, total diskspace and the percentage of free disk space." 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -8,15 +8,12 @@ import subprocess
import bumblebee.module import bumblebee.module
import bumblebee.util import bumblebee.util
def usage():
return "dnf or dnf::<interval in seconds, defaults to 3600>"
def notes():
return "Spawns a separate thread that invokes 'dnf updateinfo' every <interval> 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(): def description():
return "Checks DNF for updated packages and displays the number of <security>/<bugfixes>/<enhancements>/<other> pending updates." return "Checks DNF for updated packages and displays the number of <security>/<bugfixes>/<enhancements>/<other> pending updates."
def parameters():
return [ "dnf.interval: Time in seconds between two checks for updates (defaults to 1800)" ]
def get_dnf_info(obj): def get_dnf_info(obj):
loops = obj.interval() loops = obj.interval()

View file

@ -2,15 +2,15 @@ import psutil
import bumblebee.module import bumblebee.module
import bumblebee.util import bumblebee.util
def usage():
return "memory"
def notes():
return "Warning is at 20% available RAM, Critical at 10%."
def description(): def description():
return "Shows available RAM, total amount of RAM and the percentage of available RAM." 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -2,15 +2,12 @@ import pyroute2
import netifaces import netifaces
import bumblebee.module 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(): def description():
return "Displays the names, IP addresses and status of each available interface." return "Displays the names, IP addresses and status of each available interface."
def parameters():
return [ "none" ]
class Module(bumblebee.module.Module): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -5,18 +5,6 @@ import subprocess
import bumblebee.module import bumblebee.module
import bumblebee.util 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(): def description():
module = __name__.split(".")[-1] module = __name__.split(".")[-1]
if module == "pasink": if module == "pasink":
@ -25,6 +13,10 @@ def description():
return "Shows volume and mute status of the default PulseAudio Source." return "Shows volume and mute status of the default PulseAudio Source."
return "See 'pasource'." return "See 'pasource'."
def parameters():
return [ "none" ]
class Module(bumblebee.module.Module): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)

View file

@ -1,14 +1,11 @@
import bumblebee.module import bumblebee.module
import bumblebee.util import bumblebee.util
def usage():
return "spacer"
def notes():
return "none"
def description(): 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):

View file

@ -3,32 +3,30 @@ from __future__ import absolute_import
import datetime import datetime
import bumblebee.module import bumblebee.module
def usage():
module = __name__.split(".")[-1]
if module == "date":
return "date::<strftime format string, defaults to %x>"
if module == "time":
return "time::<strftime format string, defaults to %X>"
return "datetime::<strftime format string, defaults to '%x %X'>"
def notes():
return "none"
def description(): def description():
return "Displays the current time, using the optional format string as input for strftime." 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): class Module(bumblebee.module.Module):
def __init__(self, output, config, alias): def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias) super(Module, self).__init__(output, config, alias)
module = self.__module__.split(".")[-1] 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): 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))