notification de mises à jour avec bouton lanceur pour Handylinux
#!/usr/bin/env python
# -*- coding:Utf-8 -*-
# Fichier: update-notifier-handylinux.py
# Cree le 26 mai 2015 22:53:30
"""
Auteur : coyotus, thuban
licence : GNU General Public Licence
Description :
Liste le nombre de mises à jour disponibles
"""
import pygtk
pygtk.require('2.0')
import gtk
import pynotify
import sys
import os
import locale
import apt
import lsb_release
def count_upgradeables_pkg():
n = 0
cache=apt.Cache()
cache.open(None)
for i in cache:
if i.is_upgradable:
n += 1
return(n)
LOCALE = locale.setlocale(locale.LC_ALL, "")[0:2] # 'fr' or 'en'
NUMOFUPDATE = count_upgradeables_pkg()
RELEASE = lsb_release.get_distro_information()['CODENAME']
if LOCALE == 'fr':
LANG = 0
else:
LANG = 1
if NUMOFUPDATE == 0:
quit()
class language:
NUMBER_UPDATE_LABEL=[" mises à jours disponibles"," updates available"]
CANCEL_BUTTON=["Annuler","Cancel"]
UPDATE_BUTTON=["Mettre à jour","Update"]
def ignore_cb(n, action):
assert action == "cancel"
print "Abort"
n.close()
gtk.main_quit()
def default_cb(n, action):
assert action == "default"
if RELEASE == "wheezy":
#commande pour handylinux V2
os.system('update-manager')
n.close()
gtk.main_quit()
else:
#commande pour handylinux 1.9
os.system('gpk-update-viewer')
n.close()
gtk.main_quit()
if __name__ == '__main__':
if not pynotify.init("update-notifier"):
sys.exit(1)
n = pynotify.Notification("{} {}".format(NUMOFUPDATE, language.NUMBER_UPDATE_LABEL[LANG]), "", "/usr/share/icons/NITRUX/apps/48/gnome-session-reboot.svg",)
n.set_timeout(pynotify.EXPIRES_NEVER)
n.add_action("cancel", language.CANCEL_BUTTON[LANG], ignore_cb)
n.add_action("default", language.UPDATE_BUTTON[LANG], default_cb)
if not n.show():
print("Failed to send notification")
sys.exit(1)
gtk.main()