add console logging in gui, remove progress bar from gui, add new logging function, refactor all print statements to use new log function

This commit is contained in:
Vxrtrauter
2026-01-14 11:27:22 +01:00
parent 9afced8a0b
commit a386269f29
15 changed files with 128 additions and 122 deletions
+3 -4
View File
@@ -1,4 +1,5 @@
from core.utils.data.state import state
from core.utils.general.logs import consoleLog
from core.utils.network.download import run_download_direct
def split_data(data):
@@ -11,12 +12,10 @@ def split_data(data):
def check_completed(downloads, resume):
for download in downloads:
if download.completed == False:
if state.debug:
print(f"Found unfinished download: {download.title}")
consoleLog(f"Found unfinished download: {download.title}")
if resume == True:
run_download_direct(download.magnet_uri)
if state.debug:
print(f"Resuming {download.title}")
consoleLog(f"Resuming {download.title}")
+36 -32
View File
@@ -21,8 +21,7 @@ def add_download_log(title, url, magnet_uri, completed) -> DownloadList:
if any(d.magnet_uri == magnet_uri or d.url == url for d in downloads):
if state.debug:
print("Skipped Logging, download already in file")
consoleLog("Skipped Logging, download already in file")
return DownloadList(data=downloads, count=len(downloads)) # thanks again claude (im stupid)
@@ -33,8 +32,7 @@ def add_download_log(title, url, magnet_uri, completed) -> DownloadList:
completed=completed,
))
if state.debug:
print(f"Added {title} to Log File")
consoleLog(f"Added {title} to Log File")
download_list = DownloadList(data=downloads, count=len(downloads))
with open(downloads_file, "w") as file:
@@ -51,51 +49,45 @@ def update_download_completed(magnet_uri, completed) -> DownloadList:
existing_data = json.load(file)
downloads = [Download(**d) for d in existing_data.get("data", [])]
except (json.JSONDecodeError, TypeError) as e:
if state.debug:
print(f"Error loading downloads.json: {e}")
consoleLog(f"Error loading downloads.json: {e}")
downloads = []
else:
downloads = []
identifier = (magnet_uri or "").strip()
if state.debug:
print(f"Updating download completed for identifier: {identifier!r}")
print(f"Total downloads in file: {len(downloads)}")
consoleLog(f"Updating download completed for identifier: {identifier!r}")
consoleLog(f"Total downloads in file: {len(downloads)}")
for i, d in enumerate(downloads):
try:
mag = (getattr(d, 'magnet_uri', None) or '')[:50]
url = (getattr(d, 'url', None) or '')[:50]
print(f" [{i}] magnet: {mag}... url: {url}...")
consoleLog(f" [{i}] magnet: {mag}... url: {url}...")
except Exception as e:
print(f" [{i}] Error reading download: {e}")
consoleLog(f" [{i}] Error reading download: {e}")
found = False
for download in downloads:
try:
stored_magnet = (getattr(download, 'magnet_uri', None) or "").strip()
stored_url = (getattr(download, 'url', None) or "").strip()
if state.debug:
print(f"Comparing with magnet: {stored_magnet[:50] if stored_magnet else 'None'}...")
consoleLog(f"Comparing with magnet: {stored_magnet[:50] if stored_magnet else 'None'}...")
if identifier and (stored_magnet == identifier or stored_url == identifier):
if state.debug:
print(f"Match found! Setting completed={completed}")
consoleLog(f"Match found! Setting completed={completed}")
download.completed = completed
found = True
except Exception as e:
if state.debug:
print(f"Error comparing download: {e}")
consoleLog(f"Error comparing download: {e}")
if not found:
if state.debug:
print("No matching download found to update")
consoleLog("No matching download found to update")
return DownloadList(data=downloads, count=len(downloads))
download_list = DownloadList(data=downloads, count=len(downloads))
with open(downloads_file, "w") as file:
json.dump(asdict(download_list), file, indent=4)
if state.debug:
print("Updated download log")
consoleLog("Updated download log")
return download_list
@@ -132,16 +124,14 @@ def update_download_completed_by_hash(info_hash, completed) -> DownloadList:
existing_data = json.load(file)
downloads = [Download(**d) for d in existing_data.get("data", [])]
except (json.JSONDecodeError, TypeError) as e:
if state.debug:
print(f"Error loading downloads.json: {e}")
consoleLog(f"Error loading downloads.json: {e}")
downloads = []
else:
downloads = []
info_hash_upper = (info_hash or "").upper().strip()
if state.debug:
print(f"Updating download by hash: {info_hash_upper}")
print(f"Total downloads in file: {len(downloads)}")
consoleLog(f"Updating download by hash: {info_hash_upper}")
consoleLog(f"Total downloads in file: {len(downloads)}")
found = False
for download in downloads:
@@ -153,19 +143,33 @@ def update_download_completed_by_hash(info_hash, completed) -> DownloadList:
download.completed = completed
found = True
except Exception as e:
if state.debug:
print(f"Error comparing download: {e}")
consoleLog(f"Error comparing download: {e}")
if not found:
if state.debug:
print("No matching download found to update")
consoleLog("No matching download found to update")
return DownloadList(data=downloads, count=len(downloads))
download_list = DownloadList(data=downloads, count=len(downloads))
with open(downloads_file, "w") as file:
json.dump(asdict(download_list), file, indent=4)
if state.debug:
print("Updated download log")
consoleLog("Updated download log")
return download_list
return download_list
_main_window = None
def set_main_window(window):
global _main_window
_main_window = window
def consoleLog(text):
try:
from core.interface.gui import MainWindow
MainWindow.add_log(text)
except Exception:
pass
if state.debug:
print(text)
+3 -4
View File
@@ -1,4 +1,5 @@
from core.utils.data.state import state
from core.utils.general.logs import consoleLog
import threading
import psutil
import sys
@@ -14,15 +15,13 @@ def kill_aria2server():
if state.aria2process:
state.aria2process.kill()
if state.debug:
print("Killed Aria2")
consoleLog("Killed Aria2")
try:
for proc in psutil.process_iter():
if proc.name() == process:
proc.kill()
if state.debug:
print(f"Killed Aria2c (PID {proc.pid})")
consoleLog(f"Killed Aria2c (PID {proc.pid})")
except psutil.NoSuchProcess:
pass