/mili

PyGTK Gksu Module

These days I am trying to use gksu from python but this module has no documention
Until last night Behdad opened a new world to me ! he showed me help(…).
Any way I hope this sample code help you understand methods and relations between objects.

import gtk
import gksu
import gksu.ui

import gobject
 
dialog=gksu.ui.Dialog()
dialog.set_message("Hi dear geek\nTo do your request I need your root password !")
result=dialog.run()
 
dialog.hide()
if result==gtk.RESPONSE_OK:
try:
cont=gksu.Context()
#default user is root
#cont.set_user('root')
cont.set_password(dialog.get_password())
cont.set_command('synaptic')
cont.sudo_run()
except gobject.GError , errormsg:
print errormsg

When run this sample a new dialog open and ask root password from you after that if you give correct password open synaptic with root roles, else tarp in exception and give you error message in console