Regex module. Batteries... eh.. example included.

*gotta get some sleep. maybe.
This commit is contained in:
enkore 2013-02-21 04:56:34 +01:00
parent d3228cc8be
commit 426f57d97d
2 changed files with 44 additions and 3 deletions

View File

@ -5,12 +5,22 @@ from i3pystatus import (
I3statusHandler,
mailchecker,
modsde,
notmuchmailchecker,
notmuch,
thunderbird,
regex,
)
status = I3statusHandler()
# Regular expression file watcher
# If you're using a thinkpad, chances are that this displays your fan speed and level
regexsettings = {
"regex": "speed:\s+([0-9]+)\nlevel:\s+([a-zA-Z0-9]+)",
"file": "/proc/acpi/ibm/fan",
"format": "{0} [{1}]",
}
status.register(regex.Regex(regexsettings))
# The imap checker module
mailsettings = {
"color": "#ff0000",
@ -46,8 +56,9 @@ status.register_module(mde)
# the notmuch mail checker module
db_path = "path_to_your_notmuch_database"
notmuch = notmuchmailchecker.NotmuchMailChecker(db_path)
status.register_module(notmuch)
nm = notmuch.NotmuchMailChecker(db_path)
status.register_module(nm)
# the thunderbird dbus new mail checker module
tb = thunderbirdnewmail.ThunderbirdMailChecker()

30
i3pystatus/regex.py Normal file
View File

@ -0,0 +1,30 @@
import re
from i3pystatus import IntervalModule
class Regex(IntervalModule):
"""
Simple regex file watcher
Settings:
* flags Python.re flags
* regex regular expression
* file file to search for regex matches
* format new-style format string used for output, default is "{0}"
"""
flags = 0
format = "{0}"
def __init__(self, settings):
self.__dict__.update(settings)
self.re = re.compile(self.regex, self.flags)
def run(self):
with open(self.file, "r") as f:
match = self.re.search(f.read())
self.output = self.output = {
"full_text" : self.format.format(*match.groups()),
"name" : "regex",
}