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,7 @@ from pathlib import Path
import pwd
import shutil
from subprocess import CompletedProcess, run
from wp_app_config import AppConfig
from wp_app_config import AppConfig, logging
parser = argparse.ArgumentParser()
parser.add_argument("--user", required=True, help="Username of the target file system")
@ -17,7 +17,7 @@ try:
uid = user_info.pw_uid # User ID (e.g., 1000)
gid = user_info.pw_gid # Group ID (e.g., 1000)
except KeyError:
print(f"User '{args.user}' not found.")
logging.error(f"User '{args.user}' not found.", exc_info=True)
exit(1)
keyfile: Path = Path(f"/home/{args.user}/.config/wire_py/pbwgk.pem")
@ -40,11 +40,13 @@ if not keyfile.is_file():
text=True,
check=False,
)
print(process.stdout)
if process.returncode == 0:
print("Public key generated successfully.")
logging.info("Public key generated successfully.", exc_info=True)
else:
print(f"Error with the following code... {process.returncode}")
logging.error(
f"Error with the following code... {process.returncode}", exc_info=True
)
shutil.chown(keyfile, uid, gid)
if AppConfig.PUBLICKEY.exists():
@ -72,16 +74,11 @@ if AppConfig.PUBLICKEY.exists():
check=False,
)
shutil.chown(f"{AppConfig.TEMP_DIR}/{base_name}.conf", uid, gid)
print(f"Processing of the file: {tunnel_path}")
if process.stdout:
print(process.stdout)
logging.info(f"Processing of the file: {tunnel_path}", exc_info=True)
# Output from Openssl Error
if process.stderr:
print("(Error):", process.stderr)
if process.returncode == 0:
print(f"File {base_name}.dat successfully decrypted.")
else:
print(f"Error by {tunnel_path}: Code: {process.returncode}")
logging.error(
f"{process.stderr} Error by [{tunnel_path}] Code: {process.returncode}",
exc_info=True,
)