From 922ae49aba20f19b8dc13abccdefbdd377e0eea4 Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 12 Feb 2013 01:07:26 +0100 Subject: [PATCH] Create package i3pystatus --- .gitignore | 3 +- MIT-LICENSE | 1 + statushandler.py => i3pystatus/__init__.py | 12 ++-- i3pystatus/__main__.py.dist | 57 +++++++++++++++++++ mailchecker.py => i3pystatus/mailchecker.py | 4 +- modsde.py => i3pystatus/modsde.py | 4 +- .../notmuchmailchecker.py | 0 .../thunderbird.py | 9 ++- wrapper.py.dist | 57 ------------------- 9 files changed, 79 insertions(+), 68 deletions(-) rename statushandler.py => i3pystatus/__init__.py (86%) create mode 100755 i3pystatus/__main__.py.dist rename mailchecker.py => i3pystatus/mailchecker.py (97%) rename modsde.py => i3pystatus/modsde.py (97%) rename notmuchmailchecker.py => i3pystatus/notmuchmailchecker.py (100%) rename thunderbirdnewmail.py => i3pystatus/thunderbird.py (91%) delete mode 100755 wrapper.py.dist diff --git a/.gitignore b/.gitignore index 17f0368..50a0550 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *__pycache__* *.pyc -wrapper.py +i3pystatus/__main__.py + diff --git a/MIT-LICENSE b/MIT-LICENSE index eb9397a..f11efad 100644 --- a/MIT-LICENSE +++ b/MIT-LICENSE @@ -1,4 +1,5 @@ Copyright (c) 2012 Jan Oliver Oelerich, http://www.oelerich.org +Copyright (c) 2013 mabe, http://enkore.de Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/statushandler.py b/i3pystatus/__init__.py similarity index 86% rename from statushandler.py rename to i3pystatus/__init__.py index bb64b74..4f8ba44 100644 --- a/statushandler.py +++ b/i3pystatus/__init__.py @@ -5,7 +5,7 @@ import json import urllib.request, urllib.error, urllib.parse from threading import Thread -class Module(object): +class Module: output = None async = False @@ -13,15 +13,18 @@ class Module(object): """Called when this module is registered with a status handler""" def tick(self): - """Only called if self.async == False. Called once per tick""" + """Only called if async is False. Called once per tick""" -class I3statusHandler(object): + def mainloop(self): + """This is run in a separate daemon-thread if async is True""" + +class I3statusHandler: modules = [] def __init__(self): pass - def register_module(self, module): + def register(self, module): """Register a new module.""" self.modules.append(module) @@ -50,6 +53,7 @@ class I3statusHandler(object): self.print_line(self.read_line()) self.print_line(self.read_line()) + # Start threads for asynchronous modules for module in self.modules: if module.async: module.thread = Thread(target=module.mainloop) diff --git a/i3pystatus/__main__.py.dist b/i3pystatus/__main__.py.dist new file mode 100755 index 0000000..5d3448e --- /dev/null +++ b/i3pystatus/__main__.py.dist @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from i3pystatus import ( + I3statusHandler, + mailchecker, + modsde, + notmuchmailchecker, + thunderbird, +) + +status = I3statusHandler() + +# The imap checker module +mailsettings = { + 'color': '#ff0000', + 'servers': [ + { + 'host': 'www.testhost1.com', + 'port': '993', + 'ssl' : True, + 'username': 'your_username', + 'password': 'your_password', + 'pause': 20 + }, + { + 'host': 'www.testhost2.net', + 'port': '993', + 'ssl' : True, + 'username': 'your_username', + 'password': 'your_password', + 'pause': 20 + } + ] +} +mailchecker = mailchecker.MailChecker(mailsettings) +status.register_module(mailchecker) + +# the mods.de forum new bookmarks module +mdesettings = { + 'username': "your_username", + 'password': "your_password" +} +mde = modsde.ModsDeChecker(mdesettings) +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) + +# the thunderbird dbus new mail checker module +tb = thunderbirdnewmail.ThunderbirdMailChecker() +status.register_module(tb) + +# start the handler +status.run() diff --git a/mailchecker.py b/i3pystatus/mailchecker.py similarity index 97% rename from mailchecker.py rename to i3pystatus/mailchecker.py index f367336..60421ff 100644 --- a/mailchecker.py +++ b/i3pystatus/mailchecker.py @@ -5,10 +5,10 @@ import sys import json from datetime import datetime,timedelta import imaplib -from statushandler import has_internet_connection +from i3pystatus import Module -class MailChecker(object): +class MailChecker(Module): """ This class handles mailservers and outputs i3status compatible json data for the accumulated unread count. The mail server diff --git a/modsde.py b/i3pystatus/modsde.py similarity index 97% rename from modsde.py rename to i3pystatus/modsde.py index 996a494..d98d10b 100644 --- a/modsde.py +++ b/i3pystatus/modsde.py @@ -9,7 +9,9 @@ import re import http.cookiejar import xml.etree.ElementTree as ET -class ModsDeChecker(object): +from i3pystatus import Module + +class ModsDeChecker(Module): """ This class returns i3status parsable output of the number of unread posts in any bookmark in the mods.de forums. diff --git a/notmuchmailchecker.py b/i3pystatus/notmuchmailchecker.py similarity index 100% rename from notmuchmailchecker.py rename to i3pystatus/notmuchmailchecker.py diff --git a/thunderbirdnewmail.py b/i3pystatus/thunderbird.py similarity index 91% rename from thunderbirdnewmail.py rename to i3pystatus/thunderbird.py index b5873b8..5e754a5 100644 --- a/thunderbirdnewmail.py +++ b/i3pystatus/thunderbird.py @@ -13,7 +13,9 @@ import json import threading import time -class ThunderbirdMailChecker(object): +from i3pystatus import Module + +class ThunderbirdMailChecker(Module): """ This class listens for dbus signals emitted by the dbus-sender extension for thunderbird. @@ -28,8 +30,9 @@ class ThunderbirdMailChecker(object): unread = set() - def __init__(self, settings): - self.settings.update(settings) + def __init__(self, settings=None): + if settings is not None: + self.settings.update(settings) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() diff --git a/wrapper.py.dist b/wrapper.py.dist deleted file mode 100755 index c6a3b44..0000000 --- a/wrapper.py.dist +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import mailchecker -import modsde -import notmuchmailchecker -import thunderbirdnewmail -from statushandler import I3statusHandler - -if __name__ == '__main__': - - status = I3statusHandler() - - # The imap checker module - mailsettings = { - 'color': '#ff0000', - 'servers': [ - { - 'host': 'www.testhost1.com', - 'port': '993', - 'ssl' : True, - 'username': 'your_username', - 'password': 'your_password', - 'pause': 20 - }, - { - 'host': 'www.testhost2.net', - 'port': '993', - 'ssl' : True, - 'username': 'your_username', - 'password': 'your_password', - 'pause': 20 - } - ] - } - mailchecker = mailchecker.MailChecker(mailsettings) - status.register_module(mailchecker) - - # the mods.de forum new bookmarks module - mdesettings = { - 'username': "your_username", - 'password': "your_password" - } - mde = modsde.ModsDeChecker(mdesettings) - 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) - - # the thunderbird dbus new mail checker module - tb = thunderbirdnewmail.ThunderbirdMailChecker() - status.register_module(tb) - - # start the handler - status.run()