Refactor for consistent string quoting and formatting
This commit is contained in:
@@ -5,18 +5,22 @@ import subprocess
|
||||
import sys
|
||||
|
||||
# Add the helpers directory to the path
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'helpers'))
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "helpers"))
|
||||
from functions import printfe
|
||||
|
||||
|
||||
def run_command(cmd, capture_output=True):
|
||||
"""Run a command and return the result"""
|
||||
try:
|
||||
result = subprocess.run(cmd, shell=True, capture_output=capture_output, text=True)
|
||||
result = subprocess.run(
|
||||
cmd, shell=True, capture_output=capture_output, text=True
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
printfe("red", f"Error running command: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def show_timer_status(timer_name, system_level=True):
|
||||
"""Show concise status for a specific timer"""
|
||||
cmd_prefix = "sudo systemctl" if system_level else "systemctl --user"
|
||||
@@ -24,10 +28,12 @@ def show_timer_status(timer_name, system_level=True):
|
||||
# Get timer status
|
||||
status_cmd = f"{cmd_prefix} is-active {timer_name}"
|
||||
status_result = run_command(status_cmd)
|
||||
timer_status = "active" if status_result and status_result.returncode == 0 else "inactive"
|
||||
timer_status = (
|
||||
"active" if status_result and status_result.returncode == 0 else "inactive"
|
||||
)
|
||||
|
||||
# Get corresponding service status
|
||||
service_name = timer_name.replace('.timer', '.service')
|
||||
service_name = timer_name.replace(".timer", ".service")
|
||||
service_cmd = f"{cmd_prefix} is-active {service_name}"
|
||||
service_result = run_command(service_cmd)
|
||||
service_status = service_result.stdout.strip() if service_result else "unknown"
|
||||
@@ -43,7 +49,7 @@ def show_timer_status(timer_name, system_level=True):
|
||||
next_run = f"{parts[0]} {parts[1]} {parts[2]} ({parts[3]})"
|
||||
|
||||
# Format output based on service status
|
||||
service_short = service_name.replace('.service', '')
|
||||
service_short = service_name.replace(".service", "")
|
||||
|
||||
if service_status in ["activating", "active"]:
|
||||
# Service is currently running
|
||||
@@ -63,6 +69,7 @@ def show_timer_status(timer_name, system_level=True):
|
||||
|
||||
printfe(status_color, f"{symbol} {service_short:<12} {status_text}")
|
||||
|
||||
|
||||
def show_examples():
|
||||
"""Show example commands for checking services and logs"""
|
||||
printfe("cyan", "=== Useful Commands ===")
|
||||
@@ -92,6 +99,7 @@ def show_examples():
|
||||
print(" sudo systemctl list-timers")
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
"""Main timers action"""
|
||||
args = sys.argv[1:] if len(sys.argv) > 1 else []
|
||||
@@ -103,7 +111,7 @@ def main():
|
||||
timers = [
|
||||
("borg-backup.timer", True),
|
||||
("borg-local-sync.timer", True),
|
||||
("dynamic-dns.timer", True)
|
||||
("dynamic-dns.timer", True),
|
||||
]
|
||||
|
||||
for timer_name, system_level in timers:
|
||||
@@ -118,5 +126,6 @@ def main():
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user