Skip to content

Commit

Permalink
Set urgency levels for notify-send calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Mar 6, 2018
1 parent 5784c1f commit 92cf59f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions backuppy/notifier.py
Expand Up @@ -86,40 +86,40 @@ class NotifySendNotifier(Notifier):
See https://linux.die.net/man/2/send.
"""

def _notify(self, message):
def _notify(self, message, urgency):
"""Send a notification.
:param message: str
"""
subprocess.call(('notify-send', "'%s'" % message))
subprocess.call(('notify-send', '-c', 'backuppy', '-u', urgency, message))

def state(self, message):
"""Send a notification that may be ignored.
:param message: str
"""
self._notify(message)
self._notify(message, 'low')

def inform(self, message):
"""Send an informative notification.
:param message: str
"""
self._notify(message)
self._notify(message, 'normal')

def confirm(self, message):
"""Send a confirmation/success notification.
:param message: str
"""
self._notify(message)
self._notify(message, 'normal')

def alert(self, message):
"""Send an error notification.
:param message: str
"""
self._notify(message)
self._notify(message, 'critical')


class FileNotifier(Notifier):
Expand Down
8 changes: 4 additions & 4 deletions backuppy/tests/test_notifier.py
Expand Up @@ -59,25 +59,25 @@ def test_state(self, m):
sut = NotifySendNotifier()
message = 'Something happened!'
sut.state(message)
m.assert_called_with(('notify-send', "'%s'" % message))
m.assert_called_with(('notify-send', '-c', 'backuppy', '-u', 'low', message))

@patch('subprocess.call')
def test_inform(self, m):
sut = NotifySendNotifier()
message = 'Something happened!'
sut.inform(message)
m.assert_called_with(('notify-send', "'%s'" % message))
m.assert_called_with(('notify-send', '-c', 'backuppy', '-u', 'normal', message))

@patch('subprocess.call')
def test_confirm(self, m):
sut = NotifySendNotifier()
message = 'Something happened!'
sut.confirm(message)
m.assert_called_with(('notify-send', "'%s'" % message))
m.assert_called_with(('notify-send', '-c', 'backuppy', '-u', 'normal', message))

@patch('subprocess.call')
def test_alert(self, m):
sut = NotifySendNotifier()
message = 'Something happened!'
sut.alert(message)
m.assert_called_with(('notify-send', "'%s'" % message))
m.assert_called_with(('notify-send', '-c', 'backuppy', '-u', 'critical', message))

0 comments on commit 92cf59f

Please sign in to comment.