Advertisement
son_link

Example for SystemDbus

May 30th, 2011
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3.  
  4. import gobject, commands, re
  5. from dbus.service import BusName, Object, method
  6. from dbus import SystemBus
  7. from dbus.mainloop.glib import DBusGMainLoop
  8.  
  9. dbus_loop = DBusGMainLoop()
  10. session = SystemBus(mainloop=dbus_loop)
  11.  
  12. class Ejemplo(Object):
  13.     instancias = 0
  14.     def __init__(self, bus, loop):
  15.         # Nombre Conocido de la aplicaciΓ³n
  16.         name = BusName('com.pacsyu.check', bus)
  17.         self.loop = loop
  18.         self.path = '/com/pacsyu/check'
  19.         super(Ejemplo, self).__init__(name, self.path)
  20.      
  21.     @method(dbus_interface='com.pacsyu.check')
  22.     def if_updates(self):
  23.         sync = commands.getoutput('pacman -Sy')
  24.         if re.findall('No address record', sync):
  25.                 raise NameError('NoConecction')
  26.         try:
  27.             updates = commands.getoutput('pacman -Qu')
  28.             if updates:
  29.                 return True
  30.             else:
  31.                 return False
  32.         except NameError:
  33.             return -1
  34.      
  35.     @method(dbus_interface='com.pacsyu.check')
  36.     def salir(self):
  37.         self.loop.quit()
  38.  
  39. loop = gobject.MainLoop()
  40. gobject.threads_init()
  41. ejemplo1 = Ejemplo(session, loop)
  42. loop.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement