urlfetcher: Drop explicit prepare/cleanup calls
We can do this automatically easily enough. The downsides of not cleaning up are pretty minor these days anyways without the 'mount' handling
This commit is contained in:
parent
9995ebc86b
commit
9e4287321f
|
@ -198,11 +198,7 @@ def _testURL(fetcher, testdata):
|
|||
|
||||
def _fetchWrapper(url, cb):
|
||||
fetcher = urlfetcher.fetcherForURI(url, "/tmp", meter)
|
||||
try:
|
||||
fetcher.prepareLocation()
|
||||
return cb(fetcher)
|
||||
finally:
|
||||
fetcher.cleanupLocation()
|
||||
return cb(fetcher)
|
||||
|
||||
|
||||
def _testURLWrapper(testdata):
|
||||
|
|
|
@ -217,6 +217,8 @@ class vmmCreate(vmmGObjectUI):
|
|||
if self._storage_browser:
|
||||
self._storage_browser.close()
|
||||
self._set_conn(None)
|
||||
self._failed_guest = None
|
||||
self._guest = None
|
||||
|
||||
def _cleanup(self):
|
||||
if self._storage_browser:
|
||||
|
@ -331,8 +333,6 @@ class vmmCreate(vmmGObjectUI):
|
|||
Reset all UI state to default values. Conn specific state is
|
||||
populated in _populate_conn_state
|
||||
"""
|
||||
self._failed_guest = None
|
||||
self._guest = None
|
||||
self.reset_finish_cursor()
|
||||
|
||||
self.widget("create-pages").set_current_page(PAGE_NAME)
|
||||
|
|
|
@ -106,7 +106,6 @@ class InstallerTreeMedia(object):
|
|||
return self._cached_fetcher
|
||||
|
||||
def _get_store(self, guest, fetcher):
|
||||
# Caller is responsible for calling fetcher prepare/cleanup if needed
|
||||
if not self._cached_store:
|
||||
self._cached_store = urldetect.getDistroStore(guest, fetcher)
|
||||
return self._cached_store
|
||||
|
@ -143,17 +142,7 @@ class InstallerTreeMedia(object):
|
|||
|
||||
def prepare(self, guest, meter):
|
||||
fetcher = self._get_fetcher(guest, meter)
|
||||
try:
|
||||
try:
|
||||
fetcher.prepareLocation()
|
||||
except ValueError as e:
|
||||
logging.debug("Error preparing install location",
|
||||
exc_info=True)
|
||||
raise ValueError(_("Invalid install location: ") + str(e))
|
||||
|
||||
return self._prepare_kernel_url(guest, fetcher)
|
||||
finally:
|
||||
fetcher.cleanupLocation()
|
||||
return self._prepare_kernel_url(guest, fetcher)
|
||||
|
||||
def cleanup(self, guest):
|
||||
ignore = guest
|
||||
|
@ -176,25 +165,15 @@ class InstallerTreeMedia(object):
|
|||
if self._media_type not in [MEDIA_URL]:
|
||||
return True
|
||||
|
||||
try:
|
||||
fetcher = self._get_fetcher(guest, None)
|
||||
fetcher.prepareLocation()
|
||||
|
||||
# This will throw an error for us
|
||||
ignore = self._get_store(guest, fetcher)
|
||||
finally:
|
||||
fetcher.cleanupLocation()
|
||||
fetcher = self._get_fetcher(guest, None)
|
||||
# This will throw an error for us
|
||||
ignore = self._get_store(guest, fetcher)
|
||||
return True
|
||||
|
||||
def detect_distro(self, guest):
|
||||
if self._media_type in [MEDIA_ISO]:
|
||||
return InstallerTreeMedia.detect_iso_distro(guest, self.location)
|
||||
|
||||
try:
|
||||
fetcher = self._get_fetcher(guest, None)
|
||||
fetcher.prepareLocation()
|
||||
|
||||
store = self._get_store(guest, fetcher)
|
||||
return store.get_osdict_info()
|
||||
finally:
|
||||
fetcher.cleanupLocation()
|
||||
fetcher = self._get_fetcher(guest, None)
|
||||
store = self._get_store(guest, fetcher)
|
||||
return store.get_osdict_info()
|
||||
|
|
|
@ -33,6 +33,7 @@ class _URLFetcher(object):
|
|||
self.meter = meter
|
||||
|
||||
logging.debug("Using scratchdir=%s", scratchdir)
|
||||
self._prepare()
|
||||
|
||||
|
||||
####################
|
||||
|
@ -103,18 +104,21 @@ class _URLFetcher(object):
|
|||
"""
|
||||
return self._is_iso
|
||||
|
||||
def prepareLocation(self):
|
||||
def _prepare(self):
|
||||
"""
|
||||
Perform any necessary setup
|
||||
"""
|
||||
pass
|
||||
|
||||
def cleanupLocation(self):
|
||||
def _cleanup(self):
|
||||
"""
|
||||
Perform any necessary cleanup
|
||||
"""
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
self._cleanup()
|
||||
|
||||
def can_access(self):
|
||||
"""
|
||||
Return True if the location URL seems to be valid
|
||||
|
@ -165,10 +169,10 @@ class _URLFetcher(object):
|
|||
class _HTTPURLFetcher(_URLFetcher):
|
||||
_session = None
|
||||
|
||||
def prepareLocation(self):
|
||||
def _prepare(self):
|
||||
self._session = requests.Session()
|
||||
|
||||
def cleanupLocation(self):
|
||||
def _cleanup(self):
|
||||
if self._session:
|
||||
try:
|
||||
self._session.close()
|
||||
|
@ -219,7 +223,7 @@ class _HTTPURLFetcher(_URLFetcher):
|
|||
class _FTPURLFetcher(_URLFetcher):
|
||||
_ftp = None
|
||||
|
||||
def prepareLocation(self):
|
||||
def _prepare(self):
|
||||
if self._ftp:
|
||||
return
|
||||
|
||||
|
@ -246,7 +250,7 @@ class _FTPURLFetcher(_URLFetcher):
|
|||
return urlobj, size
|
||||
|
||||
|
||||
def cleanupLocation(self):
|
||||
def _cleanup(self):
|
||||
if not self._ftp:
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue