From bd9ec21c96f86032a6090f0997f760a21ea19b87 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Mon, 6 Aug 2018 11:42:10 -0400 Subject: [PATCH] avocado.utils.iso9660: refactor open() on the PyCdlib implementation The goal is to make the opening of files separate from the instantiation, because that will allow for the different "open" approach of opening a new ISO file in write mode. Signed-off-by: Cleber Rosa --- avocado/utils/iso9660.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/avocado/utils/iso9660.py b/avocado/utils/iso9660.py index fef1ce11..9179b6f8 100644 --- a/avocado/utils/iso9660.py +++ b/avocado/utils/iso9660.py @@ -394,11 +394,16 @@ class ISO9660PyCDLib(BaseIso9660): def __init__(self, path): if not has_pycdlib(): raise RuntimeError('This class requires the pycdlib library') - self._iso = pycdlib.PyCdlib() - self._iso.open(path) - self._iso_closed = False + self._path = path + self._iso = None + + def _open_for_read(self): + if self._iso is None: + self._iso = pycdlib.PyCdlib() + self._iso.open(self._path) def read(self, path): + self._open_for_read() if not os.path.isabs(path): path = '/' + path data = io.BytesIO() @@ -406,14 +411,15 @@ class ISO9660PyCDLib(BaseIso9660): return data.getvalue() def copy(self, src, dst): + self._open_for_read() if not os.path.isabs(src): src = '/' + src self._iso.get_file_from_iso(dst, joliet_path=src) def close(self): - if not self._iso_closed: + if self._iso: self._iso.close() - self._iso_closed = True + self._iso = None def iso9660(path, capabilities=None): -- GitLab