1. Hideo Hattori
  2. nosier

Commits

Hideo Hattori  committed 1e77419

featured: show ok/ng icon when desktop notification.

  • Participants
  • Parent commits 026bbca
  • Branches default

Comments (0)

Files changed (2)

File nosier/constants.py

View file
 BUILTIN_BLACK_LIST = ['.hg', '.git', '.bzr', '.svn', 'CVS', '*~', '#*', '.#*', '*.swp', '*.pyc', '*.pyo']
 
 WIDTH = 80
+
+OK_IMG_BASE64 = """\
+iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEUyzTI2FvSnAAAADElEQVQI
+12NgGNwAAACgAAFhJX1HAAAAAElFTkSuQmCC
+"""
+
+NG_IMG_BASE64 = """\
+iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX/AAAZ4gk3AAAADElEQVQI
+12NgGNwAAACgAAFhJX1HAAAAAElFTkSuQmCC
+"""

File nosier/nosier.py

View file
 from __future__ import with_statement
 
+from tempfile import mkdtemp
 from constants import *
+import shutil
 import inotifyx
 import subprocess
 import optparse
 import time
 import sys
 import os
+import atexit
 
 try:
     import pynotify
     pynotify = None
 if pynotify:
     pynotify.init("nosier")
+    atexit.register(pynotify.uninit)
 
 
 class Reporter(object):
 
         return subprocess.call(command)
 
+    def _notify_atexit(self):
+        shutil.rmtree(self.tempdir)
+
     def _notify(self, command, retcode):
+        self.tempdir = mkdtemp()
+        okfile = open("%s/ok.png" % self.tempdir, 'wb')
+        okfile.write(OK_IMG_BASE64.decode('base64'))
+        okfile.close()
+        ngfile = open("%s/ng.png" % self.tempdir, 'wb')
+        ngfile.write(NG_IMG_BASE64.decode('base64'))
+        ngfile.close()
+        atexit.register(self._notify_atexit)
         if retcode:
             msg = "NG"
+            img_path = "%s/ng.png" % (self.tempdir)
         else:
             msg = "OK"
-        notify = pynotify.Notification(" ".join(command), msg, "")
+            img_path = "%s/ok.png" % (self.tempdir)
+        notify = pynotify.Notification(" ".join(command), msg, img_path)
         notify.set_urgency(pynotify.URGENCY_NORMAL)
         notify.show()