Web lists-archives.com

Re: GkSudo and Python Apt




Hi,

On Sat, 09 Mar 2019 18:05:25 +0000
"J.Arun Mani" <J.ArunMani@xxxxxxxxxxxxxx> wrote:

> Hello.
> 
> Im designing an application in Python for installing some apps. I need
> help in the following:
> 
> 1. Whenever I open any app which needs root permissions, it shows me a
> popup asking password. And I have seen people refer to this GKSudo. How
> can I setup such one for my app?
> 
> 2. Or is there any alternative to GKSudo, like taking password as input
> from user and entering it, using os.system("apt install...") or any
> such modules?

afaik gksu / gksudo is virtually dead. You better use pkexec, for example
like this:

$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import call
>>> call(('pkexec', '--disable-internal-agent', '/usr/sbin/synaptic'))

> 
> {In a way such that user need not run the app from terminal using
> "sudo /.myapp"; I want this process to more graphical as possible}
> 
> Like do you guys have a better idea in designing a Python based app
> which uses apt to install apps. The problem I face is with "how to get
> sudo permission". With forums saying graphical apps should not use sudo
> and Python based modules which allow calling terminal commands not so
> effective; Im confused what to do...

If you want to run a gui app with root privilege via pkexec a
properly set up policy file for polkit is required. There is one for
synaptic at
/usr/share/polkit-1/actions/com.ubuntu.pkexec.synaptic.policy , which
is why my above example works. Adding policy files like this for random
commands however is for reasons of security not recommended.

Maybe a better alternative is to use pkexec to run a command line program
in the background; you could use subprocess.Popen to catch the output of
this program and process it for the gui.

> 
> 3. Is there any documentation available for Python-Apt module?

Sure, just install python-apt-doc :-)

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Emotions are alien to me.  I'm a scientist.
		-- Spock, "This Side of Paradise", stardate 3417.3