Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebranded the model class.
Browse files Browse the repository at this point in the history
matejak committed Jun 10, 2021
1 parent b7863da commit bd4d62e
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ def is_network(scheme):
for net_prefix in data_fetch.NET_URL_PREFIXES)


class Model:
CONTENT_DOWNLOAD_LOCATION = pathlib.Path(common.INSTALLATION_CONTENT_DIR) / "content-download"
class ContentBringer:
CONTENT_DOWNLOAD_LOCATION = pathlib.Path(common.INSTALLATION_CONTENT_DIR)
DEFAULT_CONTENT = f"{common.SSG_DIR}/{common.SSG_CONTENT}"

def __init__(self, addon_data):
@@ -66,6 +66,7 @@ def fetch_content(self, what_if_fail, cert=""):
should handle them in the calling layer.
cert: HTTPS certificates
"""
self.content_uri = self._addon_data.content_url
shutil.rmtree(self.CONTENT_DOWNLOAD_LOCATION, ignore_errors=True)
self.CONTENT_DOWNLOAD_LOCATION.mkdir(parents=True, exist_ok=True)
fetching_thread_name = self._fetch_files(
15 changes: 7 additions & 8 deletions org_fedora_oscap/gui/spokes/oscap.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
from org_fedora_oscap import scap_content_handler
from org_fedora_oscap import utils
from org_fedora_oscap.common import dry_run_skip
from org_fedora_oscap.model import Model
from org_fedora_oscap.content_discovery import ContentBringer
from pyanaconda.threading import threadMgr, AnacondaThread
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.communication import hubQ
@@ -252,7 +252,7 @@ def __init__(self, data, storage, payload):
self._anaconda_spokes_initialized = threading.Event()
self.initialization_controller.init_done.connect(self._all_anaconda_spokes_initialized)

self.model = Model(self._addon_data)
self.content_bringer = ContentBringer(self._addon_data)

def _all_anaconda_spokes_initialized(self):
log.debug("OSCAP addon: Anaconda init_done signal triggered")
@@ -375,9 +375,8 @@ def _fetch_data_and_initialize(self):

thread_name = None
if self._addon_data.content_url and self._addon_data.content_type != "scap-security-guide":
self.model.CONTENT_DOWNLOAD_LOCATION = pathlib.Path(common.INSTALLATION_CONTENT_DIR)
self.model.content_uri = self._addon_data.content_url
thread_name = self.model.fetch_content(self._handle_error, self._addon_data.certificates)
thread_name = self.content_bringer.fetch_content(
self._handle_error, self._addon_data.certificates)

# pylint: disable-msg=E1101
hubQ.send_message(self.__class__.__name__,
@@ -408,7 +407,7 @@ def update_progress_label(msg):
if actually_fetched_content:
content_path = self._addon_data.raw_preinst_content_path

content = self.model.finish_content_fetch(
content = self.content_bringer.finish_content_fetch(
wait_for, self._addon_data.fingerprint, update_progress_label,
content_path, self._handle_error)
if not content:
@@ -419,7 +418,7 @@ def update_progress_label(msg):

try:
if actually_fetched_content:
self.model.use_downloaded_content(content)
self.content_bringer.use_downloaded_content(content)
log.info(f"{self._addon_data.preinst_content_path}, {self._addon_data.preinst_tailoring_path}")
self._content_handler = scap_content_handler.SCAPContentHandler(
self._addon_data.preinst_content_path,
@@ -1148,5 +1147,5 @@ def on_change_content_clicked(self, *args):
self.refresh()

def on_use_ssg_clicked(self, *args):
self.model.use_system_content()
self.content_bringer.use_system_content()
self._fetch_data_and_initialize()
12 changes: 5 additions & 7 deletions org_fedora_oscap/ks/oscap.py
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
from org_fedora_oscap import utils, common, rule_handling, data_fetch
from org_fedora_oscap.common import SUPPORTED_ARCHIVES, _
from org_fedora_oscap.content_handling import ContentCheckError, ContentHandlingError
from org_fedora_oscap import model
from org_fedora_oscap import content_discovery

log = logging.getLogger("anaconda")

@@ -104,8 +104,7 @@ def __init__(self, name, just_clear=False):
self.rule_data = rule_handling.RuleData()
self.dry_run = False

self.model = model.Model(self)
self.model.CONTENT_DOWNLOAD_LOCATION = pathlib.Path(common.INSTALLATION_CONTENT_DIR)
self.content_bringer = content_discovery.ContentBringer(self)

def __str__(self):
"""
@@ -431,22 +430,21 @@ def setup(self, storage, ksdata, payload):
thread_name = None
if not os.path.exists(self.preinst_content_path) and not os.path.exists(self.raw_preinst_content_path):
# content not available/fetched yet
self.model.content_uri = self.content_url
thread_name = self.model.fetch_content(self._handle_error, self.certificates)
thread_name = self.content_bringer.fetch_content(self._handle_error, self.certificates)

content_dest = None
if self.content_type != "scap-security-guide":
content_dest = self.raw_preinst_content_path

content = self.model.finish_content_fetch(
content = self.content_bringer.finish_content_fetch(
thread_name, self.fingerprint, lambda msg: log.info(msg), content_dest, self._handle_error)

if not content:
return

try:
# just check that preferred content exists
_ = self.model.get_preferred_content(content)
_ = self.content_bringer.get_preferred_content(content)
except Exception as exc:
self._terminate(str(exc))
return

0 comments on commit bd4d62e

Please sign in to comment.