Bug 1253786

Summary: sandbox -X is broken because of python3
Product: [Fedora] Fedora Reporter: Daniel Walsh <dwalsh>
Component: policycoreutilsAssignee: Petr Lautrbach <plautrba>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: dwalsh, jfrieben, kahlil.hodgson, mgrepl, plautrba, swilsonau, w.chimiak
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 2.4-10.fc23 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-08-26 04:32:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Fix names for GTK 3 compatibility using the pygi-convert.sh tool none

Description Daniel Walsh 2015-08-14 17:18:55 UTC
sandbox -X evince
Traceback (most recent call last):
  File "/usr/bin/sandbox", line 500, in <module>
    rc = sandbox.main()
  File "/usr/bin/sandbox", line 488, in main
    return self.__execute()
  File "/usr/bin/sandbox", line 440, in __execute
    import gtk
ImportError: No module named 'gtk'
[Exit 1]

Comment 1 Petr Lautrbach 2015-08-17 09:05:35 UTC
Created attachment 1063726 [details]
Fix names for GTK 3 compatibility using the pygi-convert.sh tool

This patch should fix gtk 3 and python 3 related problems in sandbox. It'll part of the next update together with other similar fixes for other policycoreutils gui components.

Comment 2 Miroslav Grepl 2015-08-17 14:20:38 UTC
I see additional issue with this patch.

$ sandbox  -X -t sandbox_web_t firefox
/usr/bin/sandbox:440: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk
Traceback (most recent call last):
  File "/usr/share/sandbox/start", line 2, in <module>
    import gtk, subprocess, sys
ImportError: No module named 'gtk'

Comment 3 Miroslav Grepl 2015-08-17 15:14:16 UTC
(In reply to Miroslav Grepl from comment #2)
> I see additional issue with this patch.
> 
> $ sandbox  -X -t sandbox_web_t firefox
> /usr/bin/sandbox:440: PyGIWarning: Gtk was imported without specifying a
> version first. Use gi.require_version('Gtk', '3.0') before import to ensure
> that the right version gets loaded.
>   from gi.repository import Gtk
> Traceback (most recent call last):
>   File "/usr/share/sandbox/start", line 2, in <module>
>     import gtk, subprocess, sys
> ImportError: No module named 'gtk'

With fixes I see

$ sandbox -X -t sandbox_web_t firefox
sand
/usr/bin/sandbox:442: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk
Unable to init server: Could not connect: Connection refused
/usr/share/sandbox/start:2: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gt

Comment 4 Fedora Update System 2015-08-22 16:24:28 UTC
policycoreutils-2.4-10.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.\nIf you want to test the update, you can install it with \n su -c 'yum --enablerepo=updates-testing update policycoreutils'. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-13922

Comment 5 Fedora Update System 2015-08-26 04:32:47 UTC
policycoreutils-2.4-10.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 6 Joachim Frieben 2016-05-28 20:51:46 UTC
Issue affects current Fedora 25 (rawhide) including package policycoreutils-2.5-9.fc25:

$ sandbox -X /usr/bin/firefox
Traceback (most recent call last):
  File "/usr/bin/sandbox", line 514, in <module>
    rc = sandbox.main()
  File "/usr/bin/sandbox", line 502, in main
    return self.__execute()
  File "/usr/bin/sandbox", line 454, in __execute
    import gtk
ImportError: No module named 'gtk'

Comment 7 Kahlil Hodgson 2016-07-05 01:05:10 UTC
Just did a DNF upgrade from 23 to 24 and am getting the same result as Joachim but with the older policycoreutils-2.5-5.fc24.x86_64:

<floki:~> sandbox -X -t sandbox_web_t firefox
Traceback (most recent call last):
  File "/usr/bin/sandbox", line 514, in <module>
    rc = sandbox.main()
  File "/usr/bin/sandbox", line 502, in main
    return self.__execute()
  File "/usr/bin/sandbox", line 454, in __execute
    import gtk
ImportError: No module named 'gtk'


Maybe an issue with the upgrade path?

Comment 8 w.chimiak 2016-07-15 13:44:38 UTC
I had the same problem.  I even tried just running the 
Fedora-Workstation-Live
and the same error comes up.  Putting in the changes from gtk to
Gtk still produced those errors.
With the change
#import gtk
                #dpi = str(gtk.settings_get_default().props.gtk_xft_dpi / 1024)
                #added  
                from gi.repository import Gtk
                import Gtk
                dpi = str(Gtk.settings_get_default().props.gtk_xft_dpi / 1024)
The error is
$ sandbox -X xterm
/usr/bin/sandbox:458: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk
Traceback (most recent call last):
  File "/usr/bin/sandbox", line 519, in <module>
    rc = sandbox.main()
  File "/usr/bin/sandbox", line 507, in main
    return self.__execute()
  File "/usr/bin/sandbox", line 459, in __execute
    import Gtk
ImportError: No module named 'Gtk'


With the original

                import gtk
                dpi = str(gtk.settings_get_default().props.gtk_xft_dpi / 1024)
I get 
$ sandbox -X xterm
Traceback (most recent call last):
  File "/usr/bin/sandbox", line 519, in <module>
    rc = sandbox.main()
  File "/usr/bin/sandbox", line 507, in main
    return self.__execute()
  File "/usr/bin/sandbox", line 455, in __execute
    import gtk
ImportError: No module named 'gtk'

With the FC23 code:
              from gi.repository import Gtk
              dpi = str(Gtk.Settings.get_default().props.gtk_xft_dpi/1024)
I get
./sandbox -X xterm
./sandbox:437: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk