/usr/lib/python3/dist-packages/setoolsgui/models.py is in python3-setoolsgui 4.1.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | # Copyright 2015, Tresys Technology, LLC
#
# This file is part of SETools.
#
# SETools is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 2.1 of
# the License, or (at your option) any later version.
#
# SETools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SETools. If not, see
# <http://www.gnu.org/licenses/>.
#
import logging
from PyQt5.QtCore import QAbstractListModel, QItemSelectionModel, QAbstractTableModel, \
QModelIndex, QStringListModel, Qt
from setools.policyrep.exception import NoCommon
def invert_list_selection(selection_model):
"""Invert the selection of a list-based model."""
model = selection_model.model()
rowcount = model.rowCount()
for row in range(rowcount):
index = model.createIndex(row, 0)
selection_model.select(index, QItemSelectionModel.Toggle)
class SEToolsListModel(QAbstractListModel):
"""
The purpose of this model is to have the
objects return their string representations
for Qt.DisplayRole and return the object
for Qt.UserRole.
Some Python list-like functions are provided
for altering the model: append and remove
"""
def __init__(self, parent):
super(SEToolsListModel, self).__init__(parent)
self.log = logging.getLogger(__name__)
self._item_list = None
@property
def item_list(self):
return self._item_list
@item_list.setter
def item_list(self, item_list):
self.beginResetModel()
self._item_list = item_list
self.endResetModel()
def rowCount(self, parent=QModelIndex()):
if self.item_list:
return len(self.item_list)
else:
return 0
def columnCount(self, parent=QModelIndex()):
return 1
def append(self, item):
"""Append the item to the list."""
index = self.rowCount()
self.beginInsertRows(QModelIndex(), index, index)
self.item_list.append(item)
self.endInsertRows()
def remove(self, item):
"""Remove the first instance of the specified item from the list."""
try:
row = self.item_list.index(item)
except ValueError:
self.log.debug("Attempted to remove item {0!r} but it is not in the list".format(item))
else:
self.beginRemoveRows(QModelIndex(), row, row)
del self.item_list[row]
self.endRemoveRows()
def data(self, index, role):
if self.item_list and index.isValid():
row = index.row()
item = self.item_list[row]
if role == Qt.DisplayRole:
return str(item)
elif role == Qt.UserRole:
return item
class PermListModel(SEToolsListModel):
"""
A model that will return the intersection of permissions
for the selected classes. If no classes are
set, all permissions in the policy will be returned.
"""
def __init__(self, parent, policy):
super(PermListModel, self).__init__(parent)
self.policy = policy
self.set_classes()
def set_classes(self, classes=[]):
permlist = set()
# start will all permissions.
for cls in self.policy.classes():
permlist.update(cls.perms)
try:
permlist.update(cls.common.perms)
except NoCommon:
pass
# create intersection
for cls in classes:
cls_perms = cls.perms
try:
cls_perms.update(cls.common.perms)
except NoCommon:
pass
permlist.intersection_update(cls_perms)
self.item_list = sorted(permlist)
class SEToolsTableModel(QAbstractTableModel):
"""Base class for SETools table models."""
headers = []
def __init__(self, parent):
super(SEToolsTableModel, self).__init__(parent)
self.resultlist = []
def headerData(self, section, orientation, role):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.headers[section]
def rowCount(self, parent=QModelIndex()):
if self.resultlist:
return len(self.resultlist)
else:
return 0
def columnCount(self, parent=QModelIndex()):
return len(self.headers)
def data(self, index, role):
raise NotImplementedError
|