I am writing a python/Qt application which needs to perform disk mounting. Hence it needs root permissions. Is there any way that I could make the script acquire root permissions using a popup for password, like gparted does? I know I can detect within the script, if it has been run with sudo or not, with something like this (for example in bash):
if [[ $(id -u) -ne 0 ]];
But after this, how do I ask for the password and acquire root permissions at runtime?
Thanks.
Like this:
Popup sudo that then executes the command of interest (here, Ubuntu software center).
You can edit this with any subprocess or other way of calling a shell command.
EDIT: Anonymous downvoters: gksudo is the perfect response here? You want someone who needs root access who may not have run the script with root access to begin with. gksudo is just an interface to get root permissions to do a command, particularly for GUIs, exactly what is requested.
Leave a comment please.