[virt-tools-list] [PATCH 2/2] virtinst: Use isoinfo to extract files from ISOs
Andrew Wong
andrew.kw.w at gmail.com
Wed Nov 8 06:23:29 UTC 2017
---
virtinst/urlfetcher.py | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/virtinst/urlfetcher.py b/virtinst/urlfetcher.py
index 1288668a..3d197afd 100644
--- a/virtinst/urlfetcher.py
+++ b/virtinst/urlfetcher.py
@@ -305,11 +305,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
if self.location.startswith("nfs:"):
cmd = [mountcmd, "-o", "ro", self.location[4:], self._srcdir]
else:
- if stat.S_ISBLK(os.stat(self.location)[stat.ST_MODE]):
- mountopt = "ro"
- else:
- mountopt = "ro,loop"
- cmd = [mountcmd, "-o", mountopt, self.location, self._srcdir]
+ cmd = [mountcmd, "-o", "ro", self.location, self._srcdir]
logging.debug("mount cmd: %s", cmd)
if not self._in_test_suite:
@@ -338,6 +334,33 @@ class _MountedURLFetcher(_LocalURLFetcher):
self._mounted = False
+class _ISOURLFetcher(_URLFetcher):
+ _cache_file_list = None
+
+ def _make_full_url(self, filename):
+ return "/" + filename
+
+ def _grabber(self, url):
+ """
+ Use isoinfo to grab the file
+ """
+ print "_grabber: filename", url
+ output = subprocess.check_output(
+ ["isoinfo", "-J", "-i", self.location, "-x", url])
+ return io.BytesIO(output), len(output)
+
+ def _hasFile(self, filename):
+ """
+ Use isoinfo to list and search for the file
+ """
+ if not self._cache_file_list:
+ output = subprocess.check_output(
+ ["isoinfo", "-J", "-i", self.location, "-f"])
+ self._cache_file_list = output.splitlines(False)
+
+ return filename in self._cache_file_list
+
+
def fetcherForURI(uri, *args, **kwargs):
if uri.startswith("http://") or uri.startswith("https://"):
fclass = _HTTPURLFetcher
@@ -348,9 +371,12 @@ def fetcherForURI(uri, *args, **kwargs):
elif os.path.isdir(uri):
# Pointing to a local tree
fclass = _LocalURLFetcher
+ elif stat.S_ISBLK(os.stat(uri)[stat.ST_MODE]):
+ # Pointing to a block device
+ fclass = _MountedURLFetcher
else:
# Pointing to a path, like an .iso to mount
- fclass = _MountedURLFetcher
+ fclass = _ISOURLFetcher
return fclass(uri, *args, **kwargs)
--
2.14.1
More information about the virt-tools-list
mailing list