From e1c4d5aaaf1af3cfe145a96ce22fe6deda5598ba Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 12 Mar 2025 10:23:49 +0100 Subject: [PATCH] feat: enhance printfe function to include timestamp and message type, and update server tasks for dotfiles-test --- bin/helpers/functions.py | 26 ++++++++++++++++++++++--- config/ansible/tasks/servers/server.yml | 2 +- config/ansible/tasks/servers/zfs.yml | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bin/helpers/functions.py b/bin/helpers/functions.py index f00b97f..f5e9bad 100644 --- a/bin/helpers/functions.py +++ b/bin/helpers/functions.py @@ -6,6 +6,7 @@ import subprocess import math import random import shutil +import datetime try: import pyfiglet except ImportError: @@ -21,12 +22,31 @@ COLORS = { "purple": "\033[0;35m", "cyan": "\033[0;36m", "white": "\033[0;37m", + "grey": "\033[0;90m", # Added grey color for timestamp "reset": "\033[0m" } -def printfe(color, message): - """Print a formatted message with the specified color""" +def printfe(color, message, show_time=True): + """ + Print a formatted message with the specified color + With timestamp and message type prefix similar to setup.sh + """ color_code = COLORS.get(color.lower(), COLORS["reset"]) + + if show_time: + # Add timestamp + timestamp = datetime.datetime.now().strftime('%H:%M:%S') + print(f"{COLORS['grey']}{timestamp}{COLORS['reset']}", end='') + + # Add message type based on color + if color.lower() in ["green", "cyan", "blue", "purple"]: + print(f"{COLORS['green']} INF {COLORS['reset']}", end='') + elif color.lower() == "yellow": + print(f"{COLORS['yellow']} WRN {COLORS['reset']}", end='') + elif color.lower() == "red": + print(f"{COLORS['red']} ERR {COLORS['reset']}", end='') + + # Print the actual message with color print(f"{color_code}{message}{COLORS['reset']}") def println(message, color=None): @@ -34,7 +54,7 @@ def println(message, color=None): if color: printfe(color, message) else: - print(message) + printfe("reset", message) def _rainbow_color(text, freq=0.1, offset=0): """Apply rainbow colors to text similar to lolcat""" diff --git a/config/ansible/tasks/servers/server.yml b/config/ansible/tasks/servers/server.yml index 3006e15..93714ce 100644 --- a/config/ansible/tasks/servers/server.yml +++ b/config/ansible/tasks/servers/server.yml @@ -9,7 +9,7 @@ - name: Include ZFS tasks ansible.builtin.include_tasks: zfs.yml - when: ansible_hostname == "mennos-server" + when: ansible_hostname == "mennos-server" or ansible_hostname == "dotfiles-test" - name: Include services tasks ansible.builtin.include_tasks: services/services.yml diff --git a/config/ansible/tasks/servers/zfs.yml b/config/ansible/tasks/servers/zfs.yml index 78a8521..474503b 100644 --- a/config/ansible/tasks/servers/zfs.yml +++ b/config/ansible/tasks/servers/zfs.yml @@ -2,6 +2,7 @@ ansible.builtin.package: name: - zfsutils-linux + - zfs-dkms become: true - name: Ensure ZFS kernel module is loaded