Re: Request Help With pkexec

2017-04-05 Thread Wildman via Python-list
On Mon, 03 Apr 2017 14:29:56 -0500, Wildman wrote:

> Python 3.4.2
> Tkinter 8.6
> GCC 4.9.1 on Linux
> 
> I am working on a gui program using Tkinter. The program will
> have a feature to restart as root.  I am testing different gui
> front-ends from a terminal to raise privileges and I want to
> be able to use as many as possible for obvious reasons.  Gksu,
> kdesudo and su-to-root all work perfectly.  However, I have a
> problem with pkexec.  Here is the command I am using from a
> terminal:
> 
> $ pkexec python3 /home/user/Python/linfo-tk/linfo-tk.py
> 
> I get this error:
> 
> Traceback (most recent call last):
>   File "/home/user/Python/linfo-tk/linfo-tk.py", line 455, in 
> root = tk.Tk()
>   File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
> self.tk = _tkinter.create(screenName, baseName, className, interactive, 
> wantobjects, useTk, sync, use)
> _tkinter.TclError: no display name and no $DISPLAY environment variable

I am posting this follow-up for any Linux developer that might
be working on a gui program that requires root permissions.
My research revealed that programs like gksu are not going to
be supported long term.  Some distros have already dropped
gksu in favor of pkexec.

Pkexec is part of the PolicyKit package, policykit-1.  By
default it will not work with gui (X11) programs but that
behavior can be changed by using a .policy file placed in
/usr/share/polkit-1/actions/.  Once I created such a file,
pkexec worked perfectly with my program.  So my problem
was not Python related.

Below is the actual .policy file I am using.  It could be
edited to work with any program.  Lots of info on the
web about pkexec and the HTML .policy file.  Just search
on something like "run program with pkexec".  The name
of the file is com.ubuntu.pkexec.linfo-tk.policy.  Here
is the contents:



http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd;>



  Wildman Productions
  
Authentication is required to run Linfo-tk as root

  auth_admin
  auth_admin
  auth_admin

/opt/linfo-tk/linfo-tk.py
TRUE
  




-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Request Help With pkexec

2017-04-03 Thread Wildman via Python-list
Python 3.4.2
Tkinter 8.6
GCC 4.9.1 on Linux

I am working on a gui program using Tkinter. The program will
have a feature to restart as root.  I am testing different gui
front-ends from a terminal to raise privileges and I want to
be able to use as many as possible for obvious reasons.  Gksu,
kdesudo and su-to-root all work perfectly.  However, I have a
problem with pkexec.  Here is the command I am using from a
terminal:

$ pkexec python3 /home/user/Python/linfo-tk/linfo-tk.py

I get this error:

Traceback (most recent call last):
  File "/home/user/Python/linfo-tk/linfo-tk.py", line 455, in 
root = tk.Tk()
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, 
wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

The display environment variable is set:

$ echo $DISPLAY
:0.0

And the program displays and works perfectly in every other way.
I would appreciate any insight.

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list