mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
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:
+36
-32
@@ -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)
|
||||
Reference in New Issue
Block a user