|
|
fd2bce |
From 3f9938a45b2fd7705e6fd40ab41231a79aaf5861 Mon Sep 17 00:00:00 2001
|
|
|
fd2bce |
From: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
fd2bce |
Date: Tue, 21 Jul 2015 16:48:27 +0200
|
|
|
fd2bce |
Subject: [PATCH 7/7] Better handle and report erroneous states
|
|
|
fd2bce |
|
|
|
fd2bce |
So that users have a chance to find out what happened and fix the issue.
|
|
|
fd2bce |
|
|
|
fd2bce |
Resolves: rhbz#1241064
|
|
|
fd2bce |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
fd2bce |
---
|
|
|
fd2bce |
org_fedora_oscap/gui/spokes/oscap.py | 93 ++++++++++++++++++++++++------------
|
|
|
fd2bce |
1 file changed, 62 insertions(+), 31 deletions(-)
|
|
|
fd2bce |
|
|
|
fd2bce |
diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
|
|
|
fd2bce |
index 10a7ca7..e5ea225 100644
|
|
|
fd2bce |
--- a/org_fedora_oscap/gui/spokes/oscap.py
|
|
|
fd2bce |
+++ b/org_fedora_oscap/gui/spokes/oscap.py
|
|
|
fd2bce |
@@ -19,6 +19,7 @@
|
|
|
fd2bce |
#
|
|
|
fd2bce |
|
|
|
fd2bce |
import threading
|
|
|
fd2bce |
+from functools import wraps
|
|
|
fd2bce |
|
|
|
fd2bce |
import gettext
|
|
|
fd2bce |
_ = lambda x: gettext.ldgettext("oscap-anaconda-addon", x)
|
|
|
fd2bce |
@@ -46,6 +47,9 @@ from pykickstart.errors import KickstartValueError
|
|
|
fd2bce |
# pylint: disable-msg=E0611
|
|
|
fd2bce |
from gi.repository import Gdk
|
|
|
fd2bce |
|
|
|
fd2bce |
+import logging
|
|
|
fd2bce |
+log = logging.getLogger("anaconda")
|
|
|
fd2bce |
+
|
|
|
fd2bce |
# export only the spoke, no helper functions, classes or constants
|
|
|
fd2bce |
__all__ = ["OSCAPSpoke"]
|
|
|
fd2bce |
|
|
|
fd2bce |
@@ -105,6 +109,21 @@ def render_message_type(column, renderer, model, itr, user_data=None):
|
|
|
fd2bce |
else:
|
|
|
fd2bce |
renderer.set_property("stock-id", "gtk-dialog-question")
|
|
|
fd2bce |
|
|
|
fd2bce |
+def set_ready(func):
|
|
|
fd2bce |
+ @wraps(func)
|
|
|
fd2bce |
+ def decorated(self, *args, **kwargs):
|
|
|
fd2bce |
+ ret = func(self, *args, **kwargs)
|
|
|
fd2bce |
+
|
|
|
fd2bce |
+ self._unitialized_status = None
|
|
|
fd2bce |
+ self._ready = True
|
|
|
fd2bce |
+ # pylint: disable-msg=E1101
|
|
|
fd2bce |
+ hubQ.send_ready(self.__class__.__name__, True)
|
|
|
fd2bce |
+ hubQ.send_message(self.__class__.__name__, self.status)
|
|
|
fd2bce |
+
|
|
|
fd2bce |
+ return ret
|
|
|
fd2bce |
+
|
|
|
fd2bce |
+ return decorated
|
|
|
fd2bce |
+
|
|
|
fd2bce |
class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
Main class of the OSCAP addon spoke that will appear in the Security
|
|
|
fd2bce |
@@ -182,6 +201,8 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
self._fetching = False
|
|
|
fd2bce |
self._fetch_flag_lock = threading.Lock()
|
|
|
fd2bce |
|
|
|
fd2bce |
+ self._error = None
|
|
|
fd2bce |
+
|
|
|
fd2bce |
def initialize(self):
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
The initialize method that is called after the instance is created.
|
|
|
fd2bce |
@@ -304,6 +325,7 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
target=self._init_after_data_fetch,
|
|
|
fd2bce |
args=(thread_name,)))
|
|
|
fd2bce |
|
|
|
fd2bce |
+ @set_ready
|
|
|
fd2bce |
def _init_after_data_fetch(self, wait_for):
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
Waits for data fetching to be finished, extracts it (if needed),
|
|
|
fd2bce |
@@ -379,6 +401,7 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
# fetching done
|
|
|
fd2bce |
with self._fetch_flag_lock:
|
|
|
fd2bce |
self._fetching = False
|
|
|
fd2bce |
+
|
|
|
fd2bce |
return
|
|
|
fd2bce |
|
|
|
fd2bce |
if self._using_ds:
|
|
|
fd2bce |
@@ -403,24 +426,19 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
# update the message store with the messages
|
|
|
fd2bce |
self._update_message_store()
|
|
|
fd2bce |
|
|
|
fd2bce |
- # no more being unitialized
|
|
|
fd2bce |
- self._unitialized_status = None
|
|
|
fd2bce |
- self._ready = True
|
|
|
fd2bce |
-
|
|
|
fd2bce |
# all initialized, we can now let user set parameters
|
|
|
fd2bce |
fire_gtk_action(self._main_notebook.set_current_page, SET_PARAMS_PAGE)
|
|
|
fd2bce |
|
|
|
fd2bce |
# and use control buttons
|
|
|
fd2bce |
fire_gtk_action(really_show, self._control_buttons)
|
|
|
fd2bce |
|
|
|
fd2bce |
- # pylint: disable-msg=E1101
|
|
|
fd2bce |
- hubQ.send_ready(self.__class__.__name__, True)
|
|
|
fd2bce |
- hubQ.send_message(self.__class__.__name__, self.status)
|
|
|
fd2bce |
-
|
|
|
fd2bce |
# fetching done
|
|
|
fd2bce |
with self._fetch_flag_lock:
|
|
|
fd2bce |
self._fetching = False
|
|
|
fd2bce |
|
|
|
fd2bce |
+ # no error
|
|
|
fd2bce |
+ self._error = None
|
|
|
fd2bce |
+
|
|
|
fd2bce |
@property
|
|
|
fd2bce |
def _using_ds(self):
|
|
|
fd2bce |
return self._content_handling_cls == content_handling.DataStreamHandler
|
|
|
fd2bce |
@@ -620,39 +638,43 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
# update messages according to the newly chosen profile
|
|
|
fd2bce |
self._update_message_store()
|
|
|
fd2bce |
|
|
|
fd2bce |
+ @set_ready
|
|
|
fd2bce |
+ def _set_error(self, msg):
|
|
|
fd2bce |
+ self._error = msg
|
|
|
fd2bce |
+ self.set_error(msg)
|
|
|
fd2bce |
+
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _invalid_content(self):
|
|
|
fd2bce |
"""Callback for informing user about provided content invalidity."""
|
|
|
fd2bce |
|
|
|
fd2bce |
- self._progress_label.set_markup("%s" % _("Invalid content "
|
|
|
fd2bce |
- "provided. Enter a different URL, "
|
|
|
fd2bce |
- "please."))
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ msg = _("Invalid content provided. Enter a different URL, please.")
|
|
|
fd2bce |
+ self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _invalid_url(self):
|
|
|
fd2bce |
"""Callback for informing user about provided URL invalidity."""
|
|
|
fd2bce |
|
|
|
fd2bce |
- self._progress_label.set_markup("%s" % _("Invalid or unsupported content "
|
|
|
fd2bce |
- "URL, please enter a different one."))
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ msg = _("Invalid or unsupported content URL, please enter a different one.")
|
|
|
fd2bce |
+ self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _data_fetch_failed(self):
|
|
|
fd2bce |
"""Adapts the UI if fetching data from entered URL failed"""
|
|
|
fd2bce |
|
|
|
fd2bce |
- self._progress_label.set_markup("%s" % _("Failed to fetch "
|
|
|
fd2bce |
- "content. Enter a different URL, "
|
|
|
fd2bce |
- "please."))
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ msg = _("Failed to fetch content. Enter a different URL, please.")
|
|
|
fd2bce |
+ self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _network_problem(self):
|
|
|
fd2bce |
"""Adapts the UI if network error was encountered during data fetch"""
|
|
|
fd2bce |
|
|
|
fd2bce |
- self._progress_label.set_markup("%s" % _("Network error encountered when fetching data."
|
|
|
fd2bce |
- " Please check that network is setup and working."))
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ msg = _("Network error encountered when fetching data."
|
|
|
fd2bce |
+ " Please check that network is setup and working.")
|
|
|
fd2bce |
+ self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _integrity_check_failed(self):
|
|
|
fd2bce |
@@ -660,7 +682,7 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
|
|
|
fd2bce |
msg = _("The integrity check of the content failed. Cannot use the content.")
|
|
|
fd2bce |
self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _extraction_failed(self, err_msg):
|
|
|
fd2bce |
@@ -669,17 +691,18 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
msg = _("Failed to extract content (%s). Enter a different URL, "
|
|
|
fd2bce |
"please.") % err_msg
|
|
|
fd2bce |
self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
- def _wrong_content(self):
|
|
|
fd2bce |
- self._addon_data.content_url = ""
|
|
|
fd2bce |
- self._addon_data.content_type = ""
|
|
|
fd2bce |
+ def _wrong_content(self, msg):
|
|
|
fd2bce |
+ self._addon_data.clear_all()
|
|
|
fd2bce |
really_hide(self._progress_spinner)
|
|
|
fd2bce |
self._fetch_button.set_sensitive(True)
|
|
|
fd2bce |
self._content_url_entry.set_sensitive(True)
|
|
|
fd2bce |
self._content_url_entry.grab_focus()
|
|
|
fd2bce |
self._content_url_entry.select_region(0, -1)
|
|
|
fd2bce |
+ self._content_handling_cls == None
|
|
|
fd2bce |
+ self._set_error(msg)
|
|
|
fd2bce |
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
def _switch_dry_run(self, dry_run):
|
|
|
fd2bce |
@@ -792,6 +815,10 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
|
|
|
fd2bce |
+ if not self._addon_data.content_defined or not self._active_profile:
|
|
|
fd2bce |
+ # no errors for no content or no profile
|
|
|
fd2bce |
+ self._error = None
|
|
|
fd2bce |
+
|
|
|
fd2bce |
# store currently selected values to the addon data attributes
|
|
|
fd2bce |
if self._using_ds:
|
|
|
fd2bce |
self._addon_data.datastream_id = self._current_ds_id
|
|
|
fd2bce |
@@ -838,8 +865,8 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
|
|
|
fd2bce |
# no error message in the store
|
|
|
fd2bce |
- return all(row[0] != common.MESSAGE_TYPE_FATAL
|
|
|
fd2bce |
- for row in self._message_store)
|
|
|
fd2bce |
+ return not self._error and all(row[0] != common.MESSAGE_TYPE_FATAL
|
|
|
fd2bce |
+ for row in self._message_store)
|
|
|
fd2bce |
|
|
|
fd2bce |
@property
|
|
|
fd2bce |
@gtk_action_wait
|
|
|
fd2bce |
@@ -854,6 +881,9 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
|
|
|
fd2bce |
"""
|
|
|
fd2bce |
|
|
|
fd2bce |
+ if self._error:
|
|
|
fd2bce |
+ return _("Error fetching and loading content")
|
|
|
fd2bce |
+
|
|
|
fd2bce |
if self._unitialized_status:
|
|
|
fd2bce |
# not initialized
|
|
|
fd2bce |
return self._unitialized_status
|
|
|
fd2bce |
@@ -951,9 +981,10 @@ class OSCAPSpoke(NormalSpoke):
|
|
|
fd2bce |
really_show(self._progress_spinner)
|
|
|
fd2bce |
|
|
|
fd2bce |
if not data_fetch.can_fetch_from(url):
|
|
|
fd2bce |
+ msg = _("Invalid or unsupported URL")
|
|
|
fd2bce |
# cannot start fetching
|
|
|
fd2bce |
- self._progress_label.set_markup("%s" % _("Invalid or unsupported URL"))
|
|
|
fd2bce |
- self._wrong_content()
|
|
|
fd2bce |
+ self._progress_label.set_markup("%s" % msg)
|
|
|
fd2bce |
+ self._wrong_content(msg)
|
|
|
fd2bce |
return
|
|
|
fd2bce |
|
|
|
fd2bce |
self._progress_label.set_text(_("Fetching content..."))
|
|
|
fd2bce |
--
|
|
|
fd2bce |
2.4.3
|
|
|
fd2bce |
|