add fd.flush() to writing files

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2020-02-26 10:05:32 +09:00
parent 42078a2834
commit ebead77b65

View File

@@ -30,10 +30,15 @@ from logging import getLogger
import requests import requests
import py7zr import py7zr
from aqt.archives import QtPackage from aqt.archives import QtPackage
from aqt.helper import altlink from aqt.helper import altlink
class ExtractionError(Exception):
pass
class QtInstaller: class QtInstaller:
""" """
Installer class to download packages and extract it. Installer class to download packages and extract it.
@@ -68,8 +73,9 @@ class QtInstaller:
with open(archive, 'wb') as fd: with open(archive, 'wb') as fd:
for chunk in r.iter_content(chunk_size=8196): for chunk in r.iter_content(chunk_size=8196):
fd.write(chunk) fd.write(chunk)
fd.seek(0) fd.flush()
if self.command is None: if self.command is None:
with open(archive, 'rb') as fd:
self.extract_archive(fd) self.extract_archive(fd)
except Exception as e: except Exception as e:
exc = sys.exc_info() exc = sys.exc_info()
@@ -82,13 +88,9 @@ class QtInstaller:
self.logger.info("Finish installation of {} in {}".format(archive, time.process_time())) self.logger.info("Finish installation of {} in {}".format(archive, time.process_time()))
def extract_archive(self, archive): def extract_archive(self, archive):
try: szf = py7zr.SevenZipFile(archive)
szf = py7zr.SevenZipFile(archive) szf.extractall(path=self.base_dir)
szf.extractall(path=self.base_dir) szf.close()
except Exception as e:
exc = sys.exc_info()
self.logger.error("Extraction error: %s" % exc[1])
raise e
def extract_archive_ext(self, archive): def extract_archive_ext(self, archive):
if self.base_dir is not None: if self.base_dir is not None: