flying-sheep via GS
This commit is contained in:
parent
c96410e92d
commit
3f46ab24c6
@ -37,15 +37,19 @@ as you like.
|
|||||||
|
|
||||||
### batterychecker
|
### batterychecker
|
||||||
|
|
||||||
|
|
||||||
This class uses the /proc/acpi/battery interface to check for the
|
This class uses the /proc/acpi/battery interface to check for the
|
||||||
battery status
|
battery status
|
||||||
|
|
||||||
|
|
||||||
* battery_ident — (default: BAT0)
|
* battery_ident — (default: BAT0)
|
||||||
|
|
||||||
### clock
|
### clock
|
||||||
|
|
||||||
|
|
||||||
This class shows a clock
|
This class shows a clock
|
||||||
|
|
||||||
|
|
||||||
* format — stftime format string
|
* format — stftime format string
|
||||||
|
|
||||||
### mail
|
### mail
|
||||||
@ -57,9 +61,11 @@ This class shows a clock
|
|||||||
|
|
||||||
### modsde
|
### modsde
|
||||||
|
|
||||||
|
|
||||||
This class returns i3status parsable output of the number of
|
This class returns i3status parsable output of the number of
|
||||||
unread posts in any bookmark in the mods.de forums.
|
unread posts in any bookmark in the mods.de forums.
|
||||||
|
|
||||||
|
|
||||||
* format — Use {unread} as the formatter for number of unread posts (default: {unread} new posts in bookmarks)
|
* format — Use {unread} as the formatter for number of unread posts (default: {unread} new posts in bookmarks)
|
||||||
* offset — subtract number of posts before output
|
* offset — subtract number of posts before output
|
||||||
* color — (default: #7181fe)
|
* color — (default: #7181fe)
|
||||||
@ -68,8 +74,10 @@ unread posts in any bookmark in the mods.de forums.
|
|||||||
|
|
||||||
### regex
|
### regex
|
||||||
|
|
||||||
|
|
||||||
Simple regex file watcher
|
Simple regex file watcher
|
||||||
|
|
||||||
|
|
||||||
* format — format string used for output (default: {0})
|
* format — format string used for output (default: {0})
|
||||||
* regex — (required)
|
* regex — (required)
|
||||||
* file — file to search for regex matches
|
* file — file to search for regex matches
|
||||||
|
@ -4,6 +4,7 @@ import sys
|
|||||||
import io
|
import io
|
||||||
import pkgutil
|
import pkgutil
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
import textwrap
|
||||||
|
|
||||||
import i3pystatus
|
import i3pystatus
|
||||||
|
|
||||||
@ -15,31 +16,6 @@ MODULE_FORMAT = """
|
|||||||
|
|
||||||
{settings}\n"""
|
{settings}\n"""
|
||||||
|
|
||||||
def trim(docstring):
|
|
||||||
if not docstring:
|
|
||||||
return ''
|
|
||||||
# Convert tabs to spaces (following the normal Python rules)
|
|
||||||
# and split into a list of lines:
|
|
||||||
lines = docstring.expandtabs().splitlines()
|
|
||||||
# Determine minimum indentation (first line doesn't count):
|
|
||||||
indent = sys.maxsize
|
|
||||||
for line in lines[1:]:
|
|
||||||
stripped = line.lstrip()
|
|
||||||
if stripped:
|
|
||||||
indent = min(indent, len(line) - len(stripped))
|
|
||||||
# Remove indentation (first line is special):
|
|
||||||
trimmed = [lines[0].strip()]
|
|
||||||
if indent < sys.maxsize:
|
|
||||||
for line in lines[1:]:
|
|
||||||
trimmed.append(line[indent:].rstrip())
|
|
||||||
# Strip off trailing and leading blank lines:
|
|
||||||
while trimmed and not trimmed[-1]:
|
|
||||||
trimmed.pop()
|
|
||||||
while trimmed and not trimmed[0]:
|
|
||||||
trimmed.pop(0)
|
|
||||||
# Return a single string:
|
|
||||||
return '\n'.join(trimmed)
|
|
||||||
|
|
||||||
class Module:
|
class Module:
|
||||||
name = ""
|
name = ""
|
||||||
doc = ""
|
doc = ""
|
||||||
@ -53,11 +29,12 @@ class Module:
|
|||||||
else:
|
else:
|
||||||
self.name = "{module}.{cls}".format(module=module_name, cls=self.cls.__name__)
|
self.name = "{module}.{cls}".format(module=module_name, cls=self.cls.__name__)
|
||||||
|
|
||||||
if hasattr(self.cls, "__doc__"):
|
if self.cls.__doc__ is not None:
|
||||||
self.doc = self.cls.__doc__
|
self.doc = self.cls.__doc__
|
||||||
elif hasattr(module, "__doc__"):
|
elif module.__doc__ is not None:
|
||||||
self.doc = module.__doc__
|
self.doc = module.__doc__
|
||||||
|
else:
|
||||||
|
self.doc = ""
|
||||||
self.get_settings()
|
self.get_settings()
|
||||||
|
|
||||||
def get_settings(self):
|
def get_settings(self):
|
||||||
@ -65,12 +42,12 @@ class Module:
|
|||||||
self.settings.append(Setting(self, setting))
|
self.settings.append(Setting(self, setting))
|
||||||
|
|
||||||
def format_settings(self):
|
def format_settings(self):
|
||||||
return "\n".join(map(lambda setting: setting.format(), self.settings))
|
return "\n".join(map(str, self.settings))
|
||||||
|
|
||||||
def format(self):
|
def __str__(self):
|
||||||
return MODULE_FORMAT.format(
|
return MODULE_FORMAT.format(
|
||||||
name=self.name,
|
name=self.name,
|
||||||
doc=trim(self.doc),
|
doc=textwrap.dedent(self.doc),
|
||||||
settings=self.format_settings(),
|
settings=self.format_settings(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,7 +69,7 @@ class Setting:
|
|||||||
elif hasattr(mod.cls, self.name):
|
elif hasattr(mod.cls, self.name):
|
||||||
self.default = getattr(mod.cls, self.name)
|
self.default = getattr(mod.cls, self.name)
|
||||||
|
|
||||||
def format(self):
|
def __str__(self):
|
||||||
attrs = []
|
attrs = []
|
||||||
if self.required:
|
if self.required:
|
||||||
attrs.append("required")
|
attrs.append("required")
|
||||||
@ -134,6 +111,6 @@ def get_all():
|
|||||||
return sorted(mods, key=lambda module: module.name)
|
return sorted(mods, key=lambda module: module.name)
|
||||||
|
|
||||||
with open("template.md", "r") as template:
|
with open("template.md", "r") as template:
|
||||||
moddoc = "".join(map(lambda module: module.format(), get_all()))
|
moddoc = "".join(map(str, get_all()))
|
||||||
|
|
||||||
print(template.read().replace("!!module_doc!!", moddoc))
|
print(template.read().replace("!!module_doc!!", moddoc))
|
||||||
|
Loading…
Reference in New Issue
Block a user