logging: Use generic saving

This commit is contained in:
Mykola Grymalyuk
2023-01-26 10:33:01 -07:00
parent 8becb554fc
commit e7727adcc6
3 changed files with 7 additions and 7 deletions

View File

@@ -33,12 +33,14 @@ class OpenCoreLegacyPatcher:
level=logging.NOTSET,
format="%(asctime)s - %(filename)s (%(lineno)d): %(message)s",
handlers=[
logging.FileHandler(f"Library/Logs/OpenCore-Patcher-v{self.constants.patcher_version}.log"),
# TODO: Handle proper file storage
logging.FileHandler(f"OpenCore-Patcher-v{self.constants.patcher_version}.log"),
logging.StreamHandler(),
],
)
logging.getLogger().handlers[1].setFormatter(logging.Formatter("%(message)s"))
logging.getLogger().setLevel(logging.INFO)
logging.getLogger().handlers[1].maxBytes = 1024 * 1024 * 10
def generate_base_data(self):
self.constants.detected_os = os_probe.detect_kernel_major()

View File

@@ -3,10 +3,7 @@
# Source: https://github.com/corpnewt/pymodules/blob/884c3de15b6a2570afde52fe8a14a3e946ffb18a/run.py
import sys, subprocess, time, threading, shlex, logging
try:
from Queue import Queue, Empty
except:
from queue import Queue, Empty
from queue import Queue, Empty
ON_POSIX = 'posix' in sys.builtin_module_names

View File

@@ -411,7 +411,7 @@ def download_file(link, location, is_gui=None, verify_checksum=False):
with location.open("wb") as file:
count = 0
start = time.perf_counter()
for chunk in response.iter_content(1024 * 1024 * 4):
for i, chunk in enumerate(response.iter_content(1024 * 1024 * 4)):
dl += len(chunk)
file.write(chunk)
count += len(chunk)
@@ -424,7 +424,8 @@ def download_file(link, location, is_gui=None, verify_checksum=False):
logging.info("")
if total_file_size > 1024:
total_downloaded_string = f" ({round(float(dl / total_file_size * 100), 2)}%)"
logging.info(f"{round(count / 1024 / 1024, 2)}MB Downloaded{file_size_string}{total_downloaded_string}\nAverage Download Speed: {round(dl//(time.perf_counter() - start) / 100000 / 8, 2)} MB/s")
if i % 100 == 0:
logging.info(f"{round(count / 1024 / 1024, 2)}MB Downloaded{file_size_string}{total_downloaded_string}\nAverage Download Speed: {round(dl//(time.perf_counter() - start) / 100000 / 8, 2)} MB/s")
if verify_checksum is True:
# Verify checksum