Add Constants class in utilities
This commit is contained in:
25
threads.py
25
threads.py
@@ -6,7 +6,7 @@ from shutil import rmtree
|
||||
import urllib3
|
||||
from zipfile import ZipFile
|
||||
from PyQt5.QtCore import QThread
|
||||
import utilities
|
||||
from utilities import checksum_ok, Constants
|
||||
|
||||
class ThreadStatus(Enum):
|
||||
ok = auto()
|
||||
@@ -15,11 +15,9 @@ class ThreadStatus(Enum):
|
||||
bad_download_err = auto()
|
||||
|
||||
class DownloadThread(QThread):
|
||||
def __init__(self, db_location, path):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__db_location = db_location
|
||||
self.__path = path
|
||||
self.__status = None
|
||||
self.__status = ThreadStatus.ok
|
||||
self.reason = 0
|
||||
|
||||
@property
|
||||
@@ -32,31 +30,24 @@ class DownloadThread(QThread):
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
db = urllib3.PoolManager().request('GET', self.__db_location)
|
||||
# db = urllib.request.urlopen(self.__db_location)
|
||||
db = urllib3.PoolManager().request('GET', Constants.db_location)
|
||||
# db = urllib.request.urlopen(Constants.db_location)
|
||||
# raise urllib.error.URLError('Test')
|
||||
except urllib3.exceptions.MaxRetryError: # No internet connection.
|
||||
# self.no_connection_error.emit()
|
||||
self.__status = ThreadStatus.no_connection_err
|
||||
return
|
||||
if db.status != 200:
|
||||
self.reason = db.reason
|
||||
# self.bad_download_error.emit()
|
||||
self.__status = ThreadStatus.bad_download_err
|
||||
return
|
||||
if not utilities.checksum_ok(db.data, "folder"):
|
||||
# self.bad_download_error.emit()
|
||||
if not checksum_ok(db.data, "folder"):
|
||||
self.__status = ThreadStatus.bad_download_err
|
||||
return
|
||||
if os.path.exists(self.__path):
|
||||
rmtree(self.__path)
|
||||
if os.path.exists(Constants.data_folder):
|
||||
rmtree(Constants.data_folder)
|
||||
try:
|
||||
# data_folder = db.read()
|
||||
with ZipFile(BytesIO(db.data)) as zipped:
|
||||
zipped.extractall()
|
||||
except:
|
||||
# self.bad_file_error.emit()
|
||||
self.__status = ThreadStatus.bad_file_err
|
||||
return
|
||||
else:
|
||||
self.__status = ThreadStatus.ok
|
||||
|
||||
Reference in New Issue
Block a user