From 598f3e70e97956ccc77be36c65a772bee491ec15 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 31 Oct 2016 15:49:15 +0100 Subject: [PATCH] [main] Initial support for "-l" parameter List all available modules and query their description, notes and usage. --- bumblebee/modules/battery.py | 9 +++++++++ i3bumblebee | 25 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 7b95480..2b27d97 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -1,6 +1,15 @@ import datetime import bumblebee.module +def usage(): + return "battery::" + +def notes(): + return "Reads /sys/class/power_supply//[capacity|status]" + +def description(): + return "Displays battery status, percentage and whether it's charging or discharging" + class Module(bumblebee.module.Module): def __init__(self, args): super(Module, self).__init__(args) diff --git a/i3bumblebee b/i3bumblebee index ca966e9..5ddd88d 100755 --- a/i3bumblebee +++ b/i3bumblebee @@ -1,22 +1,41 @@ #!/usr/bin/env python +import os import sys import time +import pkgutil import argparse +import textwrap import importlib import bumblebee.theme +import bumblebee.modules import bumblebee.outputs.i3 def print_module_list(): - # TODO - pass + print "available modules:" + path = os.path.dirname(bumblebee.modules.__file__) + for mod in [ name for _, name, _ in pkgutil.iter_modules([path])]: + m = importlib.import_module("bumblebee.modules.{}".format(mod)) + + desc = "n/a" if not hasattr(m, "description") else getattr(m, "description")() + usage = "n/a" if not hasattr(m, "usage") else getattr(m, "usage")() + notes = "n/a" if not hasattr(m, "notes") else getattr(m, "notes")() + + print " {}: ".format(mod) + print textwrap.fill("Description: {}".format(desc), 80, initial_indent=" ", subsequent_indent=" ") + print textwrap.fill("Usage : {}".format(usage), 80, initial_indent=" ", subsequent_indent=" ") + print textwrap.fill("Notes : {}".format(notes), 80, initial_indent=" ", subsequent_indent=" ") def main(): parser = argparse.ArgumentParser(description="display system data in the i3bar") parser.add_argument("-m", "--modules", nargs="+", help="List of modules to load. The order of the list determines their order in the i3bar (from left to right)") parser.add_argument("-l", "--list", action="store_true", help="List all available modules and themes") parser.add_argument("-t", "--theme", help="Specify which theme to use for drawing the modulemoduless") - parser.add_argument("-i", "--interval", help="Specify the update interaval", default=1, type=int) + parser.add_argument("-i", "--interval", help="Specify the update interval", default=1, type=int) + + if len(sys.argv) == 1: + parser.print_help() + parser.exit() args = parser.parse_args()