|
|
610fa1 |
From dae2f3471a56f3967952e6951f60f523060c89a0 Mon Sep 17 00:00:00 2001
|
|
|
610fa1 |
From: Cole Robinson <crobinso@redhat.com>
|
|
|
610fa1 |
Date: Wed, 7 Apr 2021 09:51:41 -0400
|
|
|
610fa1 |
Subject: [PATCH] urlfetcher: Factor out ISOReader class
|
|
|
610fa1 |
|
|
|
610fa1 |
This contains all the isoinfo command logic. This will be used
|
|
|
610fa1 |
to add an xorriso backend as well
|
|
|
610fa1 |
|
|
|
610fa1 |
Signed-off-by: Cole Robinson <crobinso@redhat.com>
|
|
|
610fa1 |
(cherry picked from commit b13b5e0f5edf8efabae643d28f12693f43f094db)
|
|
|
610fa1 |
|
|
|
610fa1 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1973236
|
|
|
610fa1 |
|
|
|
610fa1 |
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
|
|
|
610fa1 |
---
|
|
|
610fa1 |
virtinst/install/urlfetcher.py | 64 +++++++++++++++++++++++++---------
|
|
|
610fa1 |
1 file changed, 48 insertions(+), 16 deletions(-)
|
|
|
610fa1 |
|
|
|
610fa1 |
diff --git a/virtinst/install/urlfetcher.py b/virtinst/install/urlfetcher.py
|
|
|
610fa1 |
index f531fe50..3cacab1a 100644
|
|
|
610fa1 |
--- a/virtinst/install/urlfetcher.py
|
|
|
610fa1 |
+++ b/virtinst/install/urlfetcher.py
|
|
|
610fa1 |
@@ -18,6 +18,45 @@ import requests
|
|
|
610fa1 |
from ..logger import log
|
|
|
610fa1 |
|
|
|
610fa1 |
|
|
|
610fa1 |
+#########################
|
|
|
610fa1 |
+# isoreader abstraction #
|
|
|
610fa1 |
+#########################
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+class _ISOReader:
|
|
|
610fa1 |
+ def __init__(self, location):
|
|
|
610fa1 |
+ self._location = location
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ def grabFile(self, url):
|
|
|
610fa1 |
+ raise NotImplementedError()
|
|
|
610fa1 |
+ def hasFile(self, url):
|
|
|
610fa1 |
+ raise NotImplementedError()
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+class _ISOinfoReader(_ISOReader):
|
|
|
610fa1 |
+ """
|
|
|
610fa1 |
+ Handle reading reading files off an iso
|
|
|
610fa1 |
+ """
|
|
|
610fa1 |
+ def __init__(self, location):
|
|
|
610fa1 |
+ super().__init__(location)
|
|
|
610fa1 |
+ self._cache_file_list = self._make_file_list()
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ def _make_file_list(self):
|
|
|
610fa1 |
+ cmd = ["isoinfo", "-J", "-i", self._location, "-f"]
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ log.debug("Running isoinfo: %s", cmd)
|
|
|
610fa1 |
+ output = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
|
|
|
610fa1 |
+ return output.splitlines(False)
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ def grabFile(self, url):
|
|
|
610fa1 |
+ cmd = ["isoinfo", "-J", "-i", self._location, "-x", url]
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ log.debug("Running isoinfo: %s", cmd)
|
|
|
610fa1 |
+ return subprocess.check_output(cmd)
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+ def hasFile(self, url):
|
|
|
610fa1 |
+ return url.encode("ascii") in self._cache_file_list
|
|
|
610fa1 |
+
|
|
|
610fa1 |
+
|
|
|
610fa1 |
###########################
|
|
|
610fa1 |
# Fetcher implementations #
|
|
|
610fa1 |
###########################
|
|
|
610fa1 |
@@ -302,39 +341,32 @@ class _LocalURLFetcher(_URLFetcher):
|
|
|
610fa1 |
|
|
|
610fa1 |
|
|
|
610fa1 |
class _ISOURLFetcher(_URLFetcher):
|
|
|
610fa1 |
- _cache_file_list = None
|
|
|
610fa1 |
+ _isoreader = None
|
|
|
610fa1 |
_is_iso = True
|
|
|
610fa1 |
|
|
|
610fa1 |
def _make_full_url(self, filename):
|
|
|
610fa1 |
return os.path.join("/", filename)
|
|
|
610fa1 |
|
|
|
610fa1 |
+ def _get_isoreader(self):
|
|
|
610fa1 |
+ if not self._isoreader:
|
|
|
610fa1 |
+ self._isoreader = _ISOinfoReader(self.location)
|
|
|
610fa1 |
+ return self._isoreader
|
|
|
610fa1 |
+
|
|
|
610fa1 |
def _grabber(self, url):
|
|
|
610fa1 |
"""
|
|
|
610fa1 |
Use isoinfo to grab the file
|
|
|
610fa1 |
"""
|
|
|
610fa1 |
if not self._hasFile(url):
|
|
|
610fa1 |
- raise RuntimeError("isoinfo didn't find file=%s" % url)
|
|
|
610fa1 |
-
|
|
|
610fa1 |
- cmd = ["isoinfo", "-J", "-i", self.location, "-x", url]
|
|
|
610fa1 |
-
|
|
|
610fa1 |
- log.debug("Running isoinfo: %s", cmd)
|
|
|
610fa1 |
- output = subprocess.check_output(cmd)
|
|
|
610fa1 |
+ raise RuntimeError("iso doesn't have file=%s" % url)
|
|
|
610fa1 |
|
|
|
610fa1 |
+ output = self._get_isoreader().grabFile(url)
|
|
|
610fa1 |
return io.BytesIO(output), len(output)
|
|
|
610fa1 |
|
|
|
610fa1 |
def _hasFile(self, url):
|
|
|
610fa1 |
"""
|
|
|
610fa1 |
Use isoinfo to list and search for the file
|
|
|
610fa1 |
"""
|
|
|
610fa1 |
- if not self._cache_file_list:
|
|
|
610fa1 |
- cmd = ["isoinfo", "-J", "-i", self.location, "-f"]
|
|
|
610fa1 |
-
|
|
|
610fa1 |
- log.debug("Running isoinfo: %s", cmd)
|
|
|
610fa1 |
- output = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
|
|
|
610fa1 |
-
|
|
|
610fa1 |
- self._cache_file_list = output.splitlines(False)
|
|
|
610fa1 |
-
|
|
|
610fa1 |
- return url.encode("ascii") in self._cache_file_list
|
|
|
610fa1 |
+ return self._get_isoreader().hasFile(url)
|
|
|
610fa1 |
|
|
|
610fa1 |
|
|
|
610fa1 |
class DirectFetcher(_URLFetcher):
|
|
|
610fa1 |
--
|
|
|
610fa1 |
2.31.1
|
|
|
610fa1 |
|