Skip to content

Commit

Permalink
pynotify notifications for Linux.
Browse files Browse the repository at this point in the history
This is a followup to #59 for #55.
  • Loading branch information
ralphbean committed Mar 1, 2013
1 parent 953adfe commit 4513b07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
38 changes: 38 additions & 0 deletions bugwarrior/notifications.py
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand All @@ -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')

Expand Down Expand Up @@ -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()

0 comments on commit 4513b07

Please sign in to comment.