Add full cacert support for all platforms also for the checksum.
Distinguish compiled and script case. Adjust .spec files
This commit is contained in:
@@ -43,7 +43,8 @@ from utilities import (checksum_ok,
|
||||
is_undef_band,
|
||||
format_numbers,
|
||||
resource_path,
|
||||
safe_cast)
|
||||
safe_cast,
|
||||
is_mac_os)
|
||||
|
||||
# import default_imgs_rc
|
||||
|
||||
@@ -1627,7 +1628,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
|
||||
|
||||
if __name__ == '__main__':
|
||||
# For executables running on Mac Os systems.
|
||||
if hasattr(sys, "_MEIPASS") and sys.platform == 'darwin':
|
||||
if hasattr(sys, "_MEIPASS") and is_mac_os():
|
||||
os.chdir(sys._MEIPASS)
|
||||
|
||||
my_app = QApplication(sys.argv)
|
||||
|
||||
@@ -4,13 +4,14 @@ from io import BytesIO
|
||||
from math import ceil
|
||||
import os.path
|
||||
from shutil import rmtree
|
||||
import sys
|
||||
from time import perf_counter
|
||||
from zipfile import ZipFile
|
||||
import aiohttp
|
||||
import urllib3
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from constants import Constants, Database, ChecksumWhat
|
||||
from utilities import checksum_ok
|
||||
from utilities import checksum_ok, get_pool_manager
|
||||
|
||||
# Needed for pyinstaller compilation.
|
||||
import encodings.idna
|
||||
@@ -87,7 +88,7 @@ class DownloadThread(BaseDownloadThread):
|
||||
raw_data = bytes(0)
|
||||
sub_data = bytes(0)
|
||||
try:
|
||||
self._db = urllib3.PoolManager(ca_certs = sys._MEIPASS + '/cacert.pem').request(
|
||||
self._db = get_pool_manager().request(
|
||||
'GET',
|
||||
Database.LINK_LOC,
|
||||
preload_content=False,
|
||||
|
||||
@@ -3,9 +3,8 @@ import hashlib
|
||||
import sys
|
||||
import os
|
||||
from pandas import read_csv
|
||||
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
import urllib3
|
||||
from constants import Constants, Signal, Database, ChecksumWhat
|
||||
|
||||
|
||||
@@ -51,6 +50,20 @@ def pop_up(cls, title, text,
|
||||
return msg
|
||||
|
||||
|
||||
def is_mac_os():
|
||||
"""Return True if running OS is Mac."""
|
||||
return sys.platform == 'darwin'
|
||||
|
||||
|
||||
def get_pool_manager():
|
||||
"""Return a urllib3.PoolManager object."""
|
||||
if hasattr(sys, "_MEIPASS"):
|
||||
ca_certs = os.path.join(sys._MEIPASS, 'cacert.pem')
|
||||
return urllib3.PoolManager(ca_certs=ca_certs)
|
||||
else:
|
||||
return urllib3.PoolManager()
|
||||
|
||||
|
||||
def checksum_ok(data, what):
|
||||
"""Check whether the checksum of the 'data' argument is correct."""
|
||||
code = hashlib.sha256()
|
||||
@@ -62,10 +75,13 @@ def checksum_ok(data, what):
|
||||
else:
|
||||
raise ValueError("Wrong entry name.")
|
||||
try:
|
||||
reference = read_csv(
|
||||
# The downloaded file is a csv file with columns (last version == last line):
|
||||
# data.zip_SHA256 | db.csv_SHA256 | Version | Creation_date
|
||||
reference = get_pool_manager().request(
|
||||
'GET',
|
||||
Database.LINK_REF,
|
||||
delimiter=Database.DELIMITER
|
||||
).iat[-1, n]
|
||||
timeout=4.0
|
||||
).data.decode("utf-8").splitlines()[-1].split(Database.DELIMITER)[n]
|
||||
except Exception:
|
||||
raise
|
||||
return code.hexdigest() == reference
|
||||
|
||||
Reference in New Issue
Block a user