diff --git a/bumblebee-status b/bumblebee-status index 97eef23..d757abe 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -1,11 +1,13 @@ #!/usr/bin/env python +import sys +import bumblebee.config import bumblebee.engine def main(): - args = bumblebee.engine.Arguments() + config = bumblebee.config.Config(sys.argv[1:]) - engine = bumblebee.engine.Engine(args.args()) + engine = bumblebee.engine.Engine(config) engine.load_modules() engine.register_events() diff --git a/bumblebee/config.py b/bumblebee/config.py new file mode 100644 index 0000000..45669fd --- /dev/null +++ b/bumblebee/config.py @@ -0,0 +1,59 @@ +import os +import argparse +import textwrap + +import bumblebee.theme +import bumblebee.module + +class Config(object): + def __init__(self, args): + self._raw = args + self._parser = self.parser() + + if len(args) == 0: + self._parser.print_help() + self._parser.exit() + + self._args = self._parser.parse_args(args) + + if self._args.list == "modules": + self.print_modules() + if self._args.list == "themes": + self.print_themes() + if self._args.list: + self._parser.exit() + + def parser(self): + 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)", + default=[]) + parser.add_argument("-l", "--list", + help="List: 'modules', 'themes' ", + choices = [ "modules", "themes" ], + default="modules") + parser.add_argument("-t", "--theme", help="Specify which theme to use for " + "drawing the modules", + default="default") + + return parser + + def print_themes(self): + print(textwrap.fill(", ".join(bumblebee.theme.themes()), + 80, initial_indent = " ", subsequent_indent = " " + )) + + def print_modules(self): + for m in bumblebee.module.modules(): + + print " {}: ".format(m.name()) + print textwrap.fill("Description: {}".format(m.description()), + 80, initial_indent=" ", subsequent_indent=" ") + print textwrap.fill("Usage : {}".format(m.usage()), + 80, initial_indent=" ", subsequent_indent=" ") + print textwrap.fill("Notes : {}".format(m.notes()), + 80, initial_indent=" ", subsequent_indent=" ") + print "" + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/module.py b/bumblebee/module.py index 0106bc8..495d146 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -1,3 +1,35 @@ +import os +import pkgutil +import importlib + +import bumblebee.modules + +def modules(): + result = [] + path = os.path.dirname(bumblebee.modules.__file__) + for mod in [ name for _, name, _ in pkgutil.iter_modules([path])]: + result.append(ModuleDescription(mod)) + return result + +class ModuleDescription(object): + def __init__(self, name): + self._name = name + self._mod =importlib.import_module("bumblebee.modules.{}".format(name)) + + def name(self): + return str(self._name) + + def description(self): + return getattr(self._mod, "description", self.na)() + + 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" class Module(object): def __init__(self, args): diff --git a/bumblebee/theme.py b/bumblebee/theme.py index cda1883..8b7e9bd 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -1,9 +1,14 @@ import os import json +import glob def getpath(): return os.path.dirname("{}/themes/".format(os.path.dirname(os.path.realpath(__file__)))) +def themes(): + d = getpath() + return [ os.path.basename(f).replace(".json", "") for f in glob.iglob("{}/*.json".format(d)) ] + class Theme: _cycle_index = 0 _cycle = None