Skip to content

Commit

Permalink
gui: port to Python 3 by migrating to PyGI
Browse files Browse the repository at this point in the history
PyGTK has been deprecated in favor of PyGI+GTK and thus has never been
ported to python3. Using pygi-convert.sh from
https://git.gnome.org/browse/pygobject/tree/pygi-convert.sh helps
migrating most of the API but gnome-python.

The glade file has been converted to GtkBuilder using

  gtk-builder-convert system-config-selinux.glade system-config-selinux.ui

and some fixes in order to provide an application window (object
GnomeApp disappeared, GtkVBox is deprecated, etc.). The associated
Python code also needed some modifications in order to migrate to
GtkBuilder.

The result has been tested on Arch Linux with Python 3.6. There are some
bugs in the GUI itself, for which patches will be sent afterwards.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
fishilico authored and stephensmalley committed Sep 25, 2017
1 parent 8f0ea46 commit 0f3beeb
Show file tree
Hide file tree
Showing 14 changed files with 2,281 additions and 3,292 deletions.
2 changes: 1 addition & 1 deletion gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ polgen.glade \
portsPage.py \
semanagePage.py \
statusPage.py \
system-config-selinux.glade \
system-config-selinux.png \
system-config-selinux.ui \
usersPage.py

all: $(TARGETS) system-config-selinux.py polgengui.py
Expand Down
56 changes: 23 additions & 33 deletions gui/booleansPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
# You should have received a copy of the GNU General Public License
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import string
import gtk
import gtk.glade
import os
import gobject
import sys
import tempfile
from gi.repository import Gdk, GObject, Gtk
import seobject
import semanagePage

Expand Down Expand Up @@ -61,8 +56,6 @@
import __builtin__
__builtin__.__dict__['_'] = unicode

from glob import fnmatch


class Modifier:

Expand Down Expand Up @@ -94,56 +87,53 @@ class booleansPage:

def __init__(self, xml, doDebug=None):
self.xml = xml
self.window = self.xml.get_widget("mainWindow").get_root_window()
self.window = self.xml.get_object("mainWindow").get_root_window()
self.local = False
self.types = []
self.selinuxsupport = True
self.typechanged = False
self.doDebug = doDebug
self.busy_cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
self.ready_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
self.busy_cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
self.ready_cursor = Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)

# Bring in widgets from glade file.
self.typeHBox = xml.get_widget("typeHBox")
self.booleanSW = xml.get_widget("booleanSW")
self.booleansFilter = xml.get_widget("booleansFilter")
self.booleansFilter = xml.get_object("booleansFilter")
self.booleansFilter.connect("focus_out_event", self.filter_changed)
self.booleansFilter.connect("activate", self.filter_changed)
self.booleansFilter.connect("changed", self.filter_changed)

self.booleansView = xml.get_widget("booleansView")
self.typeLabel = xml.get_widget("typeLabel")
self.modifySeparator = xml.get_widget("modifySeparator")
self.booleansView = xml.get_object("booleansView")

self.revertButton = xml.get_widget("booleanRevertButton")
self.revertButton = xml.get_object("booleanRevertButton")
self.revertButton.set_sensitive(self.local)
self.revertButton.connect("clicked", self.on_revert_clicked)
listStore = gtk.ListStore(gobject.TYPE_STRING)
cell = gtk.CellRendererText()
listStore = Gtk.ListStore(GObject.TYPE_STRING)
cell = Gtk.CellRendererText()

self.store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
self.store.set_sort_column_id(1, gtk.SORT_ASCENDING)
self.store = Gtk.ListStore(GObject.TYPE_BOOLEAN, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
self.booleansView.set_model(self.store)

checkbox = gtk.CellRendererToggle()
checkbox = Gtk.CellRendererToggle()
checkbox.connect("toggled", self.boolean_toggled)
col = gtk.TreeViewColumn('Active', checkbox, active=ACTIVE)
col = Gtk.TreeViewColumn('Active', checkbox, active=ACTIVE)
col.set_clickable(True)
col.set_sort_column_id(ACTIVE)
self.booleansView.append_column(col)

col = gtk.TreeViewColumn("Module", gtk.CellRendererText(), text=MODULE)
col = Gtk.TreeViewColumn("Module", Gtk.CellRendererText(), text=MODULE)
col.set_sort_column_id(MODULE)
col.set_resizable(True)
self.booleansView.append_column(col)

col = gtk.TreeViewColumn("Description", gtk.CellRendererText(), text=DESC)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col = Gtk.TreeViewColumn("Description", Gtk.CellRendererText(), text=DESC)
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col.set_fixed_width(400)
col.set_sort_column_id(DESC)
col.set_resizable(True)
self.booleansView.append_column(col)

col = gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=BOOLEAN)
col = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=BOOLEAN)
col.set_sort_column_id(BOOLEAN)
col.set_resizable(True)
self.booleansView.set_search_equal_func(self.__search)
Expand All @@ -152,10 +142,10 @@ def __init__(self, xml, doDebug=None):
self.load(self.filter)

def error(self, message):
dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE,
dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
message)
dlg.set_position(gtk.WIN_POS_MOUSE)
dlg.set_position(Gtk.WindowPosition.MOUSE)
dlg.show_all()
dlg.run()
dlg.destroy()
Expand All @@ -178,11 +168,11 @@ def ready(self):

def deleteDialog(self):
store, iter = self.booleansView.get_selection().get_selected()
if iter == None:
if iter is None:
return
boolean = store.get_value(iter, BOOLEAN)
# change cursor
if boolean == None:
if boolean is None:
return
try:
self.wait()
Expand Down
25 changes: 10 additions & 15 deletions gui/domainsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

## Author: Dan Walsh
import string
import gtk
import gtk.glade
import os
try:
from subprocess import getstatusoutput
except ImportError:
from commands import getstatusoutput

import gobject
import sys
import seobject
import selinux
from gi.repository import GObject, Gtk
import sepolicy
from semanagePage import *

Expand Down Expand Up @@ -58,26 +53,26 @@ class domainsPage(semanagePage):

def __init__(self, xml):
semanagePage.__init__(self, xml, "domains", _("Process Domain"))
self.domain_filter = xml.get_widget("domainsFilterEntry")
self.domain_filter = xml.get_object("domainsFilterEntry")
self.domain_filter.connect("focus_out_event", self.filter_changed)
self.domain_filter.connect("activate", self.filter_changed)

self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
self.view.set_model(self.store)
self.store.set_sort_column_id(0, gtk.SORT_ASCENDING)
col = gtk.TreeViewColumn(_("Domain Name"), gtk.CellRendererText(), text=0)
self.store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
col = Gtk.TreeViewColumn(_("Domain Name"), Gtk.CellRendererText(), text=0)
col.set_sort_column_id(0)
col.set_resizable(True)
self.view.append_column(col)
self.store.set_sort_column_id(0, gtk.SORT_ASCENDING)
col = gtk.TreeViewColumn(_("Mode"), gtk.CellRendererText(), text=1)
self.store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
col = Gtk.TreeViewColumn(_("Mode"), Gtk.CellRendererText(), text=1)
col.set_sort_column_id(1)
col.set_resizable(True)
self.view.append_column(col)
self.view.get_selection().connect("changed", self.itemSelected)

self.permissive_button = xml.get_widget("permissiveButton")
self.enforcing_button = xml.get_widget("enforcingButton")
self.permissive_button = xml.get_object("permissiveButton")
self.enforcing_button = xml.get_object("enforcingButton")

self.domains = sepolicy.get_all_entrypoint_domains()
self.load()
Expand Down Expand Up @@ -112,7 +107,7 @@ def load(self, filter=""):

def itemSelected(self, selection):
store, iter = selection.get_selected()
if iter == None:
if iter is None:
return
p = store.get_value(iter, 1) == _("Permissive")
self.permissive_button.set_sensitive(not p)
Expand Down
33 changes: 15 additions & 18 deletions gui/fcontextPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

## Author: Dan Walsh
import gtk
import gtk.glade
import os
import gobject
from gi.repository import GObject, Gtk
import seobject
try:
from subprocess import getstatusoutput
Expand Down Expand Up @@ -73,40 +70,40 @@ class fcontextPage(semanagePage):

def __init__(self, xml):
semanagePage.__init__(self, xml, "fcontext", _("File Labeling"))
self.fcontextFilter = xml.get_widget("fcontextFilterEntry")
self.fcontextFilter = xml.get_object("fcontextFilterEntry")
self.fcontextFilter.connect("focus_out_event", self.filter_changed)
self.fcontextFilter.connect("activate", self.filter_changed)

self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
self.view = xml.get_widget("fcontextView")
self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
self.view = xml.get_object("fcontextView")
self.view.set_model(self.store)
self.view.set_search_equal_func(self.search)

col = gtk.TreeViewColumn(_("File\nSpecification"), gtk.CellRendererText(), text=SPEC_COL)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col = Gtk.TreeViewColumn(_("File\nSpecification"), Gtk.CellRendererText(), text=SPEC_COL)
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col.set_fixed_width(250)

col.set_sort_column_id(SPEC_COL)
col.set_resizable(True)
self.view.append_column(col)
col = gtk.TreeViewColumn(_("Selinux\nFile Type"), gtk.CellRendererText(), text=TYPE_COL)
col = Gtk.TreeViewColumn(_("Selinux\nFile Type"), Gtk.CellRendererText(), text=TYPE_COL)

col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col.set_fixed_width(250)
col.set_sort_column_id(TYPE_COL)
col.set_resizable(True)
self.view.append_column(col)
col = gtk.TreeViewColumn(_("File\nType"), gtk.CellRendererText(), text=2)
col = Gtk.TreeViewColumn(_("File\nType"), Gtk.CellRendererText(), text=2)
col.set_sort_column_id(FTYPE_COL)
col.set_resizable(True)
self.view.append_column(col)

self.store.set_sort_column_id(SPEC_COL, gtk.SORT_ASCENDING)
self.store.set_sort_column_id(SPEC_COL, Gtk.SortType.ASCENDING)
self.load()
self.fcontextEntry = xml.get_widget("fcontextEntry")
self.fcontextFileTypeCombo = xml.get_widget("fcontextFileTypeCombo")
self.fcontextTypeEntry = xml.get_widget("fcontextTypeEntry")
self.fcontextMLSEntry = xml.get_widget("fcontextMLSEntry")
self.fcontextEntry = xml.get_object("fcontextEntry")
self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")

def match(self, fcon_dict, k, filter):
try:
Expand Down Expand Up @@ -192,7 +189,7 @@ def add(self):
mls = self.fcontextMLSEntry.get_text().strip()
list_model = self.fcontextFileTypeCombo.get_model()
it = self.fcontextFileTypeCombo.get_active_iter()
ftype = list_model.get_value(it,0)
ftype = list_model.get_value(it, 0)
self.wait()
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
self.ready()
Expand Down
28 changes: 12 additions & 16 deletions gui/loginsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

## Author: Dan Walsh
import string
import gtk
import gtk.glade
import os
import gobject
import sys
try:
from subprocess import getstatusoutput
except ImportError:
from commands import getstatusoutput

from gi.repository import GObject, Gtk
import seobject
from semanagePage import *

Expand Down Expand Up @@ -57,23 +53,23 @@ class loginsPage(semanagePage):
def __init__(self, xml):
self.firstTime = False
semanagePage.__init__(self, xml, "logins", _("User Mapping"))
self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
self.view.set_model(self.store)
self.store.set_sort_column_id(0, gtk.SORT_ASCENDING)
col = gtk.TreeViewColumn(_("Login\nName"), gtk.CellRendererText(), text=0)
self.store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
col = Gtk.TreeViewColumn(_("Login\nName"), Gtk.CellRendererText(), text=0)
col.set_sort_column_id(0)
col.set_resizable(True)
self.view.append_column(col)
col = gtk.TreeViewColumn(_("SELinux\nUser"), gtk.CellRendererText(), text=1)
col = Gtk.TreeViewColumn(_("SELinux\nUser"), Gtk.CellRendererText(), text=1)
col.set_resizable(True)
self.view.append_column(col)
col = gtk.TreeViewColumn(_("MLS/\nMCS Range"), gtk.CellRendererText(), text=2)
col = Gtk.TreeViewColumn(_("MLS/\nMCS Range"), Gtk.CellRendererText(), text=2)
col.set_resizable(True)
self.view.append_column(col)
self.load()
self.loginsNameEntry = xml.get_widget("loginsNameEntry")
self.loginsSelinuxUserCombo = xml.get_widget("loginsSelinuxUserCombo")
self.loginsMLSEntry = xml.get_widget("loginsMLSEntry")
self.loginsNameEntry = xml.get_object("loginsNameEntry")
self.loginsSelinuxUserCombo = xml.get_object("loginsSelinuxUserCombo")
self.loginsMLSEntry = xml.get_object("loginsMLSEntry")

def load(self, filter=""):
self.filter = filter
Expand All @@ -91,12 +87,12 @@ def load(self, filter=""):
self.view.get_selection().select_path((0,))

def __dialogSetup(self):
if self.firstTime == True:
if self.firstTime:
return
self.firstTime = True
liststore = gtk.ListStore(gobject.TYPE_STRING)
liststore = Gtk.ListStore(GObject.TYPE_STRING)
self.loginsSelinuxUserCombo.set_model(liststore)
cell = gtk.CellRendererText()
cell = Gtk.CellRendererText()
self.loginsSelinuxUserCombo.pack_start(cell, True)
self.loginsSelinuxUserCombo.add_attribute(cell, 'text', 0)

Expand Down
Loading

0 comments on commit 0f3beeb

Please sign in to comment.