[config] Write custom action for printing theme/module details

This commit is contained in:
Tobias Witek 2016-11-05 12:07:54 +01:00
parent 998db40a2d
commit 2f0cc30c38

View file

@ -5,11 +5,41 @@ import textwrap
import bumblebee.theme
import bumblebee.module
class print_usage(argparse.Action):
def __init__(self, option_strings, dest, nargs=None, **kwargs):
argparse.Action.__init__(self, option_strings, dest, nargs, **kwargs)
self._indent = " "*4
def __call__(self, parser, namespace, value, option_string=None):
if value == "modules":
self.print_modules()
elif value == "themes":
self.print_themes()
else:
parser.print_help()
parser.exit()
def print_themes(self):
print(textwrap.fill(", ".join(bumblebee.theme.themes()),
80, initial_indent = self._indent, subsequent_indent = self._indent
))
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 ""
class Config(object):
def __init__(self, args):
self._raw = args
self._parser = self._parser()
self._indent = " "*4
self._store = {}
if len(args) == 0:
@ -18,13 +48,6 @@ class Config(object):
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 getstore(self, name, default=None):
if not name in self._store:
self._store[name] = default
@ -49,22 +72,6 @@ class Config(object):
def modules(self):
return self._args.modules
def print_themes(self):
print(textwrap.fill(", ".join(bumblebee.theme.themes()),
80, initial_indent = self._indent, subsequent_indent = self._indent
))
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 ""
def _parser(self):
parser = argparse.ArgumentParser(description="display system data in the i3bar")
@ -76,6 +83,7 @@ class Config(object):
parser.add_argument("-l", "--list",
help="List: 'modules', 'themes' ",
choices = [ "modules", "themes" ],
action=print_usage,
)
parser.add_argument("-t", "--theme", help="Specify which theme to use for "
"drawing the modules",
@ -84,5 +92,4 @@ class Config(object):
return parser
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4