Create package i3pystatus
This commit is contained in:
parent
469f711dcd
commit
922ae49aba
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*__pycache__*
|
*__pycache__*
|
||||||
*.pyc
|
*.pyc
|
||||||
wrapper.py
|
i3pystatus/__main__.py
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
Copyright (c) 2012 Jan Oliver Oelerich, http://www.oelerich.org
|
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
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
@ -5,7 +5,7 @@ import json
|
|||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
class Module(object):
|
class Module:
|
||||||
output = None
|
output = None
|
||||||
async = False
|
async = False
|
||||||
|
|
||||||
@ -13,15 +13,18 @@ class Module(object):
|
|||||||
"""Called when this module is registered with a status handler"""
|
"""Called when this module is registered with a status handler"""
|
||||||
|
|
||||||
def tick(self):
|
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 = []
|
modules = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def register_module(self, module):
|
def register(self, module):
|
||||||
"""Register a new module."""
|
"""Register a new module."""
|
||||||
|
|
||||||
self.modules.append(module)
|
self.modules.append(module)
|
||||||
@ -50,6 +53,7 @@ class I3statusHandler(object):
|
|||||||
self.print_line(self.read_line())
|
self.print_line(self.read_line())
|
||||||
self.print_line(self.read_line())
|
self.print_line(self.read_line())
|
||||||
|
|
||||||
|
# Start threads for asynchronous modules
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
if module.async:
|
if module.async:
|
||||||
module.thread = Thread(target=module.mainloop)
|
module.thread = Thread(target=module.mainloop)
|
57
i3pystatus/__main__.py.dist
Executable file
57
i3pystatus/__main__.py.dist
Executable file
@ -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()
|
@ -5,10 +5,10 @@ import sys
|
|||||||
import json
|
import json
|
||||||
from datetime import datetime,timedelta
|
from datetime import datetime,timedelta
|
||||||
import imaplib
|
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
|
This class handles mailservers and outputs i3status compatible
|
||||||
json data for the accumulated unread count. The mail server
|
json data for the accumulated unread count. The mail server
|
@ -9,7 +9,9 @@ import re
|
|||||||
import http.cookiejar
|
import http.cookiejar
|
||||||
import xml.etree.ElementTree as ET
|
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
|
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.
|
@ -13,7 +13,9 @@ import json
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class ThunderbirdMailChecker(object):
|
from i3pystatus import Module
|
||||||
|
|
||||||
|
class ThunderbirdMailChecker(Module):
|
||||||
"""
|
"""
|
||||||
This class listens for dbus signals emitted by
|
This class listens for dbus signals emitted by
|
||||||
the dbus-sender extension for thunderbird.
|
the dbus-sender extension for thunderbird.
|
||||||
@ -28,7 +30,8 @@ class ThunderbirdMailChecker(object):
|
|||||||
|
|
||||||
unread = set()
|
unread = set()
|
||||||
|
|
||||||
def __init__(self, settings):
|
def __init__(self, settings=None):
|
||||||
|
if settings is not None:
|
||||||
self.settings.update(settings)
|
self.settings.update(settings)
|
||||||
|
|
||||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
@ -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()
|
|
Loading…
Reference in New Issue
Block a user