finish logging

This commit is contained in:
2025-05-23 12:36:28 +02:00
parent 5ac37ad9ad
commit 79f6fc0265
6 changed files with 83 additions and 103 deletions

View File

@ -5,7 +5,6 @@ this script is a simple GUI for managing Wireguard Tunnels
import getpass
import shutil
import subprocess
import sys
import tkinter as tk
import webbrowser
@ -22,7 +21,7 @@ from common_tools import (
Tooltip,
LxTools,
)
from wp_app_config import AppConfig, Msg
from wp_app_config import AppConfig, Msg, logging
AppConfig.ensure_directories()
AppConfig.create_default_settings()
@ -522,7 +521,7 @@ class FrameWidgets(ttk.Frame):
# Now update the UI with the fresh result
self.update_ui_for_update(res)
except Exception as e:
print(f"Error checking for updates: {e}")
logging.error(f"Error checking for updates: {e}", exc_info=True)
# Fallback to a default message if there's an error
self.update_ui_for_update("No Internet Connection!")
@ -663,7 +662,6 @@ class FrameWidgets(ttk.Frame):
Msg.STR["invalid_base64"],
)
else:
print("Key is valid and does not exist import allowed!")
filepath = Path(filepath)
# Shorten the tunnel name to the maximum allowed length if it exceeds 12 characters.
original_name = filepath.name
@ -687,10 +685,8 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
logging.error(f"{process.stderr}: Code {process.returncode}")
else:
print(f"Error process decrypt: Code {process.returncode}")
self.reset_fields()
process: CompletedProcess[str] = run(
@ -709,12 +705,9 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
if process.returncode == 0:
print(f"Tunnel >> {import_file.stem} << import successfull")
else:
print(f"Error process decrypt: Code {process.returncode}")
logging.error(
f"{process.stderr} Code: {process.returncode}", exc_info=True
)
CryptoUtil.encrypt(getpass.getuser())
LxTools.clean_files(AppConfig.TEMP_DIR, file=None)
@ -753,7 +746,7 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
logging.error(process.stderr, exc_info=True)
if process.returncode == 0:
print(f">> {import_file.stem} << autostart is disabled by default")
@ -773,8 +766,6 @@ class FrameWidgets(ttk.Frame):
print("File import: abort by user...")
except FileNotFoundError:
print("File import: abort by user...")
except subprocess.CalledProcessError:
print("Tunnel exist!")
def delete(self) -> None:
"""
@ -792,12 +783,9 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
if process.returncode == 0:
print(f"Tunnel >> {select_tl} << successfully deleted...")
else:
print(f"Error process: Code {process.returncode}")
logging.error(
f"{process.stderr} Code: {process.returncode}", exc_info=True
)
self.l_box.delete(self.select_tunnel[0])
Path.unlink(f"{AppConfig.CONFIG_DIR}/{select_tl}.dat")
@ -871,9 +859,6 @@ class FrameWidgets(ttk.Frame):
"""
if ConfigManager.get("autostart") != "off":
print(
f"{ConfigManager.get("autostart")} starts automatically when the system starts."
)
self.selected_option.set(1)
self.autoconnect_var.set("")
self.auto_con = ConfigManager.get("autostart")
@ -992,10 +977,9 @@ class FrameWidgets(ttk.Frame):
check=False,
)
if process.stderr:
print(process.stderr)
if process.returncode != 0:
print(f"Error process: Code {process.returncode}")
logging.error(
f"{process.stderr} Code: {process.returncode}", exc_info=True
)
source = Path(f"{AppConfig.CONFIG_DIR}/{select_tl}.dat")
destination = AppConfig.CONFIG_DIR / f"{self.lb_rename.get()}.dat"
@ -1019,11 +1003,8 @@ class FrameWidgets(ttk.Frame):
Msg.STR["sel_list"],
)
except subprocess.CalledProcessError:
pass
except EOFError as e:
print(e)
logging.error(e, exc_info=True)
def handle_tunnel_data(self, active=None, data=None) -> None:
"""Processes tunnel data from an active connection and updates
@ -1127,10 +1108,9 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
if process.returncode != 0:
print(f"Error process: Code {process.returncode}")
logging.error(
f"{process.stderr} Code: {process.returncode}", exc_info=True
)
self.update_connection_display()
self.reset_fields()
@ -1147,12 +1127,9 @@ class FrameWidgets(ttk.Frame):
)
if process.stderr:
print(process.stderr)
if process.returncode == 0:
print(f"Tunnel >> {target_tunnel} << started")
else:
print(f"Error process: Code {process.returncode}")
logging.error(
f"{process.stderr} Code: {process.returncode}", exc_info=True
)
self.update_connection_display()
self.handle_tunnel_data(self.a, self.tl)