qubespolicy: make pylint happy
This include refactoring out one-function-class GtkIconGetter. QubesOS/qubes-issues#910
This commit is contained in:
parent
a3da85bfda
commit
e5ad26c090
@ -6,3 +6,4 @@ jinja2
|
|||||||
lxml
|
lxml
|
||||||
pylint
|
pylint
|
||||||
sphinx
|
sphinx
|
||||||
|
pydbus
|
||||||
|
@ -23,13 +23,17 @@
|
|||||||
decisions.'''
|
decisions.'''
|
||||||
|
|
||||||
import pydbus
|
import pydbus
|
||||||
|
# pylint: disable=import-error,wrong-import-position
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
# pylint: enable=import-error
|
||||||
|
|
||||||
import qubespolicy.rpcconfirmation
|
import qubespolicy.rpcconfirmation
|
||||||
|
# pylint: enable=wrong-import-position
|
||||||
|
|
||||||
class PolicyAgent(object):
|
class PolicyAgent(object):
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
dbus = """
|
dbus = """
|
||||||
<node>
|
<node>
|
||||||
<interface name='org.qubesos.PolicyAgent'>
|
<interface name='org.qubesos.PolicyAgent'>
|
||||||
@ -45,8 +49,10 @@ class PolicyAgent(object):
|
|||||||
</node>
|
</node>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def Ask(self, source, service_name, targets, default_target,
|
@staticmethod
|
||||||
|
def Ask(source, service_name, targets, default_target,
|
||||||
icons):
|
icons):
|
||||||
|
# pylint: disable=invalid-name
|
||||||
entries_info = {}
|
entries_info = {}
|
||||||
for target in targets:
|
for target in targets:
|
||||||
entries_info[target] = {}
|
entries_info[target] = {}
|
||||||
|
@ -19,40 +19,36 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
import gi
|
|
||||||
import itertools
|
import itertools
|
||||||
|
# pylint: disable=import-error,wrong-import-position
|
||||||
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, GLib
|
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, GLib
|
||||||
|
# pylint: enable=import-error
|
||||||
|
|
||||||
from qubespolicy.utils import sanitize_domain_name
|
from qubespolicy.utils import sanitize_domain_name
|
||||||
|
# pylint: enable=wrong-import-position
|
||||||
|
|
||||||
|
class VMListModeler:
|
||||||
class GtkIconGetter:
|
def __init__(self, domains_info=None):
|
||||||
def __init__(self, size):
|
self._entries = {}
|
||||||
|
self._domains_info = domains_info
|
||||||
self._icons = {}
|
self._icons = {}
|
||||||
self._size = size
|
self._icon_size = 16
|
||||||
self._theme = Gtk.IconTheme.get_default()
|
self._theme = Gtk.IconTheme.get_default()
|
||||||
|
self._create_entries()
|
||||||
|
|
||||||
def get_icon(self, name):
|
def _get_icon(self, name):
|
||||||
if name not in self._icons:
|
if name not in self._icons:
|
||||||
try:
|
try:
|
||||||
icon = self._theme.load_icon(name, self._size, 0)
|
icon = self._theme.load_icon(name, self._icon_size, 0)
|
||||||
except GLib.Error:
|
except GLib.Error: # pylint: disable=catching-non-exception
|
||||||
icon = self._theme.load_icon("edit-find", self._size, 0)
|
icon = self._theme.load_icon("edit-find", self._icon_size, 0)
|
||||||
|
|
||||||
self._icons[name] = icon
|
self._icons[name] = icon
|
||||||
|
|
||||||
return self._icons[name]
|
return self._icons[name]
|
||||||
|
|
||||||
|
|
||||||
class VMListModeler:
|
|
||||||
def __init__(self, domains_info=None):
|
|
||||||
self._icon_getter = GtkIconGetter(16)
|
|
||||||
|
|
||||||
self._entries = {}
|
|
||||||
self._domains_info = domains_info
|
|
||||||
self._create_entries()
|
|
||||||
|
|
||||||
def _create_entries(self):
|
def _create_entries(self):
|
||||||
for name, vm in self._domains_info.items():
|
for name, vm in self._domains_info.items():
|
||||||
if name.startswith('$dispvm:'):
|
if name.startswith('$dispvm:'):
|
||||||
@ -63,7 +59,7 @@ class VMListModeler:
|
|||||||
dispvm = False
|
dispvm = False
|
||||||
sanitize_domain_name(vm_name, assert_sanitized=True)
|
sanitize_domain_name(vm_name, assert_sanitized=True)
|
||||||
|
|
||||||
icon = self._icon_getter.get_icon(vm.get('icon', None))
|
icon = self._get_icon(vm.get('icon', None))
|
||||||
|
|
||||||
if dispvm:
|
if dispvm:
|
||||||
display_name = 'Disposable VM ({})'.format(vm_name)
|
display_name = 'Disposable VM ({})'.format(vm_name)
|
||||||
@ -125,7 +121,7 @@ class VMListModeler:
|
|||||||
list_store = Gtk.ListStore(int, str, GdkPixbuf.Pixbuf)
|
list_store = Gtk.ListStore(int, str, GdkPixbuf.Pixbuf)
|
||||||
|
|
||||||
for entry_no, display_name in zip(itertools.count(),
|
for entry_no, display_name in zip(itertools.count(),
|
||||||
sorted(self._entries.keys())):
|
sorted(self._entries)):
|
||||||
entry = self._entries[display_name]
|
entry = self._entries[display_name]
|
||||||
if entry['api_name'] in vm_list:
|
if entry['api_name'] in vm_list:
|
||||||
list_store.append([entry_no, display_name, entry['icon']])
|
list_store.append([entry_no, display_name, entry['icon']])
|
||||||
@ -199,6 +195,7 @@ class VMListModeler:
|
|||||||
|
|
||||||
|
|
||||||
class GtkOneTimerHelper:
|
class GtkOneTimerHelper:
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
def __init__(self, wait_seconds):
|
def __init__(self, wait_seconds):
|
||||||
self._wait_seconds = wait_seconds
|
self._wait_seconds = wait_seconds
|
||||||
self._current_timer_id = 0
|
self._current_timer_id = 0
|
||||||
|
@ -18,15 +18,17 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
import pkg_resources
|
|
||||||
from gi.repository import Gtk, Gdk, GLib
|
|
||||||
import os
|
import os
|
||||||
|
from gi.repository import Gtk, Gdk, GLib # pylint: disable=import-error
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
from qubespolicy.gtkhelpers import VMListModeler, FocusStealingHelper
|
from qubespolicy.gtkhelpers import VMListModeler, FocusStealingHelper
|
||||||
from qubespolicy.utils import sanitize_domain_name, \
|
from qubespolicy.utils import sanitize_domain_name, \
|
||||||
sanitize_service_name
|
sanitize_service_name
|
||||||
|
|
||||||
|
|
||||||
class RPCConfirmationWindow:
|
class RPCConfirmationWindow:
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
_source_file = pkg_resources.resource_filename('qubespolicy',
|
_source_file = pkg_resources.resource_filename('qubespolicy',
|
||||||
os.path.join('glade', "RPCConfirmationWindow.glade"))
|
os.path.join('glade', "RPCConfirmationWindow.glade"))
|
||||||
_source_id = {'window': "RPCConfirmationWindow",
|
_source_id = {'window': "RPCConfirmationWindow",
|
||||||
@ -110,7 +112,8 @@ class RPCConfirmationWindow:
|
|||||||
def _can_perform_action(self):
|
def _can_perform_action(self):
|
||||||
return self._focus_helper.can_perform_action()
|
return self._focus_helper.can_perform_action()
|
||||||
|
|
||||||
def _escape_and_format_rpc_text(self, rpc_operation):
|
@staticmethod
|
||||||
|
def _escape_and_format_rpc_text(rpc_operation):
|
||||||
escaped = GLib.markup_escape_text(rpc_operation)
|
escaped = GLib.markup_escape_text(rpc_operation)
|
||||||
|
|
||||||
partitioned = escaped.partition('.')
|
partitioned = escaped.partition('.')
|
||||||
@ -161,7 +164,7 @@ class RPCConfirmationWindow:
|
|||||||
self._escape_and_format_rpc_text(rpc_operation))
|
self._escape_and_format_rpc_text(rpc_operation))
|
||||||
|
|
||||||
self._entries_info = entries_info
|
self._entries_info = entries_info
|
||||||
list_modeler = self._new_VM_list_modeler()
|
list_modeler = self._new_vm_list_modeler()
|
||||||
|
|
||||||
list_modeler.apply_model(self._rpc_combo_box, targets_list,
|
list_modeler.apply_model(self._rpc_combo_box, targets_list,
|
||||||
selection_trigger=self._update_ok_button_sensitivity,
|
selection_trigger=self._update_ok_button_sensitivity,
|
||||||
@ -186,7 +189,7 @@ class RPCConfirmationWindow:
|
|||||||
|
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
||||||
def _new_VM_list_modeler(self):
|
def _new_vm_list_modeler(self):
|
||||||
return VMListModeler(self._entries_info)
|
return VMListModeler(self._entries_info)
|
||||||
|
|
||||||
def _new_focus_stealing_helper(self):
|
def _new_focus_stealing_helper(self):
|
||||||
@ -209,4 +212,3 @@ def confirm_rpc(entries_info, source, rpc_operation, targets_list, target=None):
|
|||||||
targets_list, target)
|
targets_list, target)
|
||||||
|
|
||||||
return window.confirm_rpc()
|
return window.confirm_rpc()
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from qubespolicy.rpcconfirmation import RPCConfirmationWindow
|
|||||||
|
|
||||||
|
|
||||||
class MockRPCConfirmationWindow(RPCConfirmationWindow):
|
class MockRPCConfirmationWindow(RPCConfirmationWindow):
|
||||||
def _new_VM_list_modeler(self):
|
def _new_vm_list_modeler(self):
|
||||||
return VMListModeler(mock_domains_info)
|
return VMListModeler(mock_domains_info)
|
||||||
|
|
||||||
def _new_focus_stealing_helper(self):
|
def _new_focus_stealing_helper(self):
|
||||||
|
@ -56,4 +56,3 @@ def sanitize_domain_name(input_string, assert_sanitized=False):
|
|||||||
|
|
||||||
def sanitize_service_name(input_string, assert_sanitized=False):
|
def sanitize_service_name(input_string, assert_sanitized=False):
|
||||||
return _sanitize_name(input_string, {'+'}, assert_sanitized)
|
return _sanitize_name(input_string, {'+'}, assert_sanitized)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user