diff --git a/bugwarrior/README.rst b/bugwarrior/README.rst index cca1f55fe..cf1ee31d8 100644 --- a/bugwarrior/README.rst +++ b/bugwarrior/README.rst @@ -59,15 +59,19 @@ Create a ``~/.bugwarriorrc`` file with the following contents. # This section is for configuring notifications when bugwarrior-pull runs, # and when issues are created, updated, or deleted by bugwarrior-pull. - # Currently only growlnotify (v2) on Mac OS X is supported. To configure, - # first install the gntp library ("pip install gntp"). Then adjust the settings - # below. + # Two backend are currently suported: + # - growlnotify (v2) on Mac OS X "gntp" must be installed + # - pynotify on Linux "pynotify" must be installed + # To configure, adjust the settings below. Note that neither of the + # "sticky" options have any effect on Linux with pynotify. They only work + # for growlnotify. [notifications] # notifications = True # backend = growlnotify # finished_querying_sticky = False # task_crud_sticky = True + # This is a github example. It says, "scrape every issue from every repository # on http://github.com/ralphbean. It doesn't matter if ralphbean owns the issue # or not." diff --git a/bugwarrior/notifications.py b/bugwarrior/notifications.py index d31c0d83b..dd8577747 100644 --- a/bugwarrior/notifications.py +++ b/bugwarrior/notifications.py @@ -1,6 +1,26 @@ import datetime +import os +import urllib + from bugwarrior.config import asbool + +cache_dir = os.path.expanduser("~/.cache/bugwarrior") +logo_path = cache_dir + "/logo.png" +logo_url = "https://upload.wikimedia.org/wikipedia/" + \ + "en/5/59/Taskwarrior_logo.png" + + +def _cache_logo(): + if os.path.exists(logo_path): + return + + if not os.path.isdir(cache_dir): + os.makedirs(cache_dir) + + urllib.urlretrieve(logo_url, logo_path) + + def _get_metadata(issue): due = '' tags = '' @@ -24,6 +44,7 @@ def _get_metadata(issue): metadata += "\n" + tags return metadata + def send_notification(issue, op, conf): notify_backend = conf.get('notifications', 'backend') @@ -59,3 +80,20 @@ def send_notification(issue, op, conf): priority = 1, ) return + elif notify_backend == 'pynotify': + _cache_logo() + + import pynotify + pynotify.init(__name__) + + if op == 'bw finished': + message = "Finished querying for new issues.\n%s" % issue + else: + message = "%s task: %s" % ( + op, issue['description'].encode("utf-8")) + metadata = _get_metadata(issue) + if metadata is not None: + message += metadata + + n = pynotify.Notification("Bugwarrior", message, logo_path) + n.show()