2016-11-05 07:54:36 +01:00
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
import bumblebee.theme
|
|
|
|
import bumblebee.module
|
|
|
|
|
|
|
|
class Config(object):
|
|
|
|
def __init__(self, args):
|
|
|
|
self._raw = args
|
2016-11-05 08:11:08 +01:00
|
|
|
self._parser = self._parser()
|
2016-11-05 07:59:58 +01:00
|
|
|
self._indent = " "*4
|
2016-11-05 11:57:09 +01:00
|
|
|
self._store = {}
|
2016-11-05 07:54:36 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2016-11-05 11:57:09 +01:00
|
|
|
def getstore(self, name, default=None):
|
|
|
|
if not name in self._store:
|
|
|
|
self._store[name] = default
|
|
|
|
return self._store.get(name, default)
|
|
|
|
|
|
|
|
def store(self, name, value):
|
|
|
|
self._store[name] = value
|
|
|
|
|
|
|
|
def increase(self, name, limit, default):
|
|
|
|
self._store[name] += 1
|
|
|
|
if self._store[name] >= limit:
|
|
|
|
self._store[name] = default
|
|
|
|
return self._store[name]
|
|
|
|
|
2016-11-05 08:11:08 +01:00
|
|
|
def parameter(self, name, default):
|
|
|
|
# TODO
|
|
|
|
return default
|
2016-11-05 07:54:36 +01:00
|
|
|
|
2016-11-05 08:11:08 +01:00
|
|
|
def theme(self):
|
|
|
|
return self._args.theme
|
|
|
|
|
|
|
|
def modules(self):
|
|
|
|
return self._args.modules
|
2016-11-05 07:54:36 +01:00
|
|
|
|
|
|
|
def print_themes(self):
|
|
|
|
print(textwrap.fill(", ".join(bumblebee.theme.themes()),
|
2016-11-05 07:59:58 +01:00
|
|
|
80, initial_indent = self._indent, subsequent_indent = self._indent
|
2016-11-05 07:54:36 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
def print_modules(self):
|
|
|
|
for m in bumblebee.module.modules():
|
|
|
|
|
2016-11-05 07:59:58 +01:00
|
|
|
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)
|
2016-11-05 07:54:36 +01:00
|
|
|
print ""
|
|
|
|
|
2016-11-05 08:11:08 +01:00
|
|
|
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" ],
|
|
|
|
)
|
|
|
|
parser.add_argument("-t", "--theme", help="Specify which theme to use for "
|
|
|
|
"drawing the modules",
|
|
|
|
default="default",
|
|
|
|
)
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
2016-11-05 07:54:36 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|