Well okay, its not really.. but sort of. For those not in the know, in jaunty the update-notification daemon no longer provides you with a little icon in your notification area to tell you you have updates, its annoying, its really annoying. I barely ever remember to update because of it, so i wrote a small python script to put a little notification icon up there when i have new updates and thought i would share it with the rest of the world.
if you want to use this, you will want to put it in a file called update_notifier.py and make it executionable. then stick it in ~/bin (or wherever you want really). I also added it to my list of startup programs running the following command:
nice -n20 /home/gord/bin/update_notfier.py
the reason for the nice -n20 is that checking the entire repository for new packages (does not download new package lists, just checks your current ones via python-apt) can eat up cpu power, nice just makes sure it won’t get in your way hopefully. - it runs once every 24 hours (my update mechanism only gets new info once every 24 hours, no point i doing more surely?)
here come the code:
#!/usr/bin/env python
#
# update_notfier.py
#
# Copyright 2009 Gordon Allott
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import pygtk
import gtk, gobject
import apt
import os, sys
import subprocess
class AptNotifier(object):
def __init__(self):
self.icon = gtk.StatusIcon()
self.icon.set_from_stock(gtk.STOCK_INFO)
self.icon.connect('activate', self.icon_activate)
self.icon.set_visible(False)
self.refresh()
def icon_activate(self, icon):
subprocess.Popen('update-manager')
def check_new(self):
cache = apt.Cache()
cache.upgrade(True)
if len(cache.getChanges()) > 0:
# we have changes if we get here, return True
return True
return False
def display_icon(self):
self.icon.set_visible(True)
def destroy_icon(self):
self.icon.set_visible(False)
def refresh(self):
""" checks for new update items """
if self.check_new():
self.display_icon()
else:
self.destroy_icon()
return True # we return true to make the timeout repeat
def run(self):
gobject.timeout_add(60*60*24*1000, self.refresh)
gtk.main()
def main():
notifier = AptNotifier()
notifier.run()
return 0
if __name__ == '__main__': main()