linting
This commit is contained in:
@@ -11,16 +11,18 @@ from helpers.functions import printfe, println, logo
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""Display help information."""
|
||||||
# Print logo
|
# Print logo
|
||||||
logo(continue_after=True)
|
logo(continue_after=True)
|
||||||
|
|
||||||
# Print help
|
# Print help
|
||||||
dotfiles_path = os.environ.get("DOTFILES_PATH", os.path.expanduser("~/.dotfiles"))
|
dotfiles_path = os.environ.get("DOTFILES_PATH", os.path.expanduser("~/.dotfiles"))
|
||||||
try:
|
try:
|
||||||
with open(f"{dotfiles_path}/bin/resources/help.txt", "r") as f:
|
with open(
|
||||||
|
f"{dotfiles_path}/bin/resources/help.txt", "r", encoding="utf-8"
|
||||||
|
) as f:
|
||||||
help_text = f.read()
|
help_text = f.read()
|
||||||
print(help_text)
|
except OSError as e:
|
||||||
except Exception as e:
|
|
||||||
printfe("red", f"Error reading help file: {e}")
|
printfe("red", f"Error reading help file: {e}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import argparse
|
|||||||
|
|
||||||
# Import helper functions
|
# Import helper functions
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
from helpers.functions import printfe, println, logo
|
from helpers.functions import printfe, println
|
||||||
|
|
||||||
# Base directory for Docker services $HOME/services
|
# Base directory for Docker services $HOME/services
|
||||||
SERVICES_DIR = os.path.join(os.path.expanduser("~"), ".services")
|
SERVICES_DIR = os.path.join(os.path.expanduser("~"), ".services")
|
||||||
@@ -109,7 +109,8 @@ def cmd_stop(args):
|
|||||||
if protected_running:
|
if protected_running:
|
||||||
printfe(
|
printfe(
|
||||||
"yellow",
|
"yellow",
|
||||||
f"Note: {', '.join(protected_running)} will not be stopped as they are protected services",
|
f"Note: {', '.join(protected_running)} will not be stopped "
|
||||||
|
"as they are protected services",
|
||||||
)
|
)
|
||||||
|
|
||||||
if not safe_services:
|
if not safe_services:
|
||||||
@@ -136,19 +137,18 @@ def cmd_stop(args):
|
|||||||
else:
|
else:
|
||||||
printfe("green", "\nAll running services stopped successfully")
|
printfe("green", "\nAll running services stopped successfully")
|
||||||
return 0
|
return 0
|
||||||
else:
|
# Check if trying to stop a protected service
|
||||||
# Check if trying to stop a protected service
|
if args.service in PROTECTED_SERVICES:
|
||||||
if args.service in PROTECTED_SERVICES:
|
printfe(
|
||||||
printfe(
|
"red",
|
||||||
"red",
|
f"Error: {args.service} is a protected service and cannot be stopped",
|
||||||
f"Error: {args.service} is a protected service and cannot be stopped",
|
)
|
||||||
)
|
printfe(
|
||||||
printfe(
|
"yellow",
|
||||||
"yellow",
|
f"The {args.service} service is required for other services to work properly",
|
||||||
f"The {args.service} service is required for other services to work properly",
|
)
|
||||||
)
|
return 1
|
||||||
return 1
|
return run_docker_compose(["down"], service_name=args.service)
|
||||||
return run_docker_compose(["down"], service_name=args.service)
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_restart(args):
|
def cmd_restart(args):
|
||||||
@@ -208,15 +208,15 @@ def cmd_update(args):
|
|||||||
else:
|
else:
|
||||||
printfe("green", "\nAll running services updated successfully")
|
printfe("green", "\nAll running services updated successfully")
|
||||||
return 0
|
return 0
|
||||||
else:
|
|
||||||
# The original single-service update logic
|
|
||||||
# First pull the latest images
|
|
||||||
pull_result = run_docker_compose(["pull"], service_name=args.service)
|
|
||||||
if pull_result != 0:
|
|
||||||
return pull_result
|
|
||||||
|
|
||||||
# Then bring the service up with the latest images
|
# The original single-service update logic
|
||||||
return run_docker_compose(["up", "-d"], service_name=args.service)
|
# First pull the latest images
|
||||||
|
pull_result = run_docker_compose(["pull"], service_name=args.service)
|
||||||
|
if pull_result != 0:
|
||||||
|
return pull_result
|
||||||
|
|
||||||
|
# Then bring the service up with the latest images
|
||||||
|
return run_docker_compose(["up", "-d"], service_name=args.service)
|
||||||
|
|
||||||
|
|
||||||
def cmd_ps(args):
|
def cmd_ps(args):
|
||||||
@@ -262,18 +262,27 @@ def get_systemd_timer_status(timer_name):
|
|||||||
"""Check if a systemd timer is active and enabled, and get next run time"""
|
"""Check if a systemd timer is active and enabled, and get next run time"""
|
||||||
# Check if timer is active (running/waiting)
|
# Check if timer is active (running/waiting)
|
||||||
active_result = subprocess.run(
|
active_result = subprocess.run(
|
||||||
["sudo", "systemctl", "is-active", timer_name], capture_output=True, text=True, check=False
|
["sudo", "systemctl", "is-active", timer_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if timer is enabled (will start on boot)
|
# Check if timer is enabled (will start on boot)
|
||||||
enabled_result = subprocess.run(
|
enabled_result = subprocess.run(
|
||||||
["sudo", "systemctl", "is-enabled", timer_name], capture_output=True, text=True, check=False
|
["sudo", "systemctl", "is-enabled", timer_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check corresponding service status
|
# Check corresponding service status
|
||||||
service_name = timer_name.replace(".timer", ".service")
|
service_name = timer_name.replace(".timer", ".service")
|
||||||
service_result = subprocess.run(
|
service_result = subprocess.run(
|
||||||
["sudo", "systemctl", "is-active", service_name], capture_output=True, text=True, check=False
|
["sudo", "systemctl", "is-active", service_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get next run time
|
# Get next run time
|
||||||
@@ -297,7 +306,7 @@ def get_systemd_timer_status(timer_name):
|
|||||||
return is_active, is_enabled, next_run, service_status
|
return is_active, is_enabled, next_run, service_status
|
||||||
|
|
||||||
|
|
||||||
def cmd_list(args):
|
def cmd_list(args): # pylint: disable=unused-argument
|
||||||
"""List available Docker services and systemd services"""
|
"""List available Docker services and systemd services"""
|
||||||
# Docker services section
|
# Docker services section
|
||||||
if not os.path.exists(SERVICES_DIR):
|
if not os.path.exists(SERVICES_DIR):
|
||||||
@@ -320,7 +329,10 @@ def cmd_list(args):
|
|||||||
is_running = container_count > 0
|
is_running = container_count > 0
|
||||||
|
|
||||||
if is_running:
|
if is_running:
|
||||||
status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]"
|
status = (
|
||||||
|
f"[RUNNING - {container_count} container"
|
||||||
|
f"{'s' if container_count > 1 else ''}]"
|
||||||
|
)
|
||||||
color = "green"
|
color = "green"
|
||||||
else:
|
else:
|
||||||
status = "[STOPPED]"
|
status = "[STOPPED]"
|
||||||
@@ -360,6 +372,7 @@ def cmd_list(args):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""Main entry point for managing Docker services."""
|
||||||
parser = argparse.ArgumentParser(description="Manage Docker services")
|
parser = argparse.ArgumentParser(description="Manage Docker services")
|
||||||
subparsers = parser.add_subparsers(dest="command", help="Command to run")
|
subparsers = parser.add_subparsers(dest="command", help="Command to run")
|
||||||
|
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ def main():
|
|||||||
|
|
||||||
# Generate the export commands
|
# Generate the export commands
|
||||||
exports = [
|
exports = [
|
||||||
f'export BORG_REPO="/mnt/object_storage/borg-repo"',
|
'export BORG_REPO="/mnt/object_storage/borg-repo"',
|
||||||
f'export BORG_PASSPHRASE="{passphrase}"',
|
f'export BORG_PASSPHRASE="{passphrase}"',
|
||||||
f'export BORG_CACHE_DIR="/home/menno/.config/borg/cache"',
|
'export BORG_CACHE_DIR="/home/menno/.config/borg/cache"',
|
||||||
f'export BORG_CONFIG_DIR="/home/menno/.config/borg/config"',
|
'export BORG_CONFIG_DIR="/home/menno/.config/borg/config"',
|
||||||
f'export BORG_SECURITY_DIR="/home/menno/.config/borg/security"',
|
'export BORG_SECURITY_DIR="/home/menno/.config/borg/security"',
|
||||||
f'export BORG_KEYS_DIR="/home/menno/.config/borg/keys"',
|
'export BORG_KEYS_DIR="/home/menno/.config/borg/keys"',
|
||||||
]
|
]
|
||||||
|
|
||||||
# Check if we're being eval'd (no arguments and stdout is a pipe)
|
# Check if we're being eval'd (no arguments and stdout is a pipe)
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ def main():
|
|||||||
str(jobs),
|
str(jobs),
|
||||||
]
|
]
|
||||||
|
|
||||||
result = subprocess.run(cmd, env=env)
|
result = subprocess.run(cmd, env=env, check=False)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
printfe("red", "Failed to upgrade Home Manager packages.")
|
printfe("red", "Failed to upgrade Home Manager packages.")
|
||||||
return 1
|
return 1
|
||||||
@@ -419,9 +419,9 @@ def main():
|
|||||||
|
|
||||||
# Execute the Ansible command, passing password via stdin if available
|
# Execute the Ansible command, passing password via stdin if available
|
||||||
if sudo_password:
|
if sudo_password:
|
||||||
result = subprocess.run(ansible_cmd, input=sudo_password.encode("utf-8"))
|
result = subprocess.run(ansible_cmd, input=sudo_password.encode("utf-8"), check=False)
|
||||||
else:
|
else:
|
||||||
result = subprocess.run(ansible_cmd)
|
result = subprocess.run(ansible_cmd, check=False)
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
printfe("red", "Failed to upgrade Ansible packages.")
|
printfe("red", "Failed to upgrade Ansible packages.")
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""Helper functions for the dotfiles system."""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import math
|
import math
|
||||||
@@ -7,7 +9,6 @@ import random
|
|||||||
import shutil
|
import shutil
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
"""Helper functions for the dotfiles system."""
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pyfiglet
|
import pyfiglet
|
||||||
@@ -173,7 +174,6 @@ def ensure_dependencies():
|
|||||||
|
|
||||||
printfe("green", "All dependencies have been processed")
|
printfe("green", "All dependencies have been processed")
|
||||||
return True
|
return True
|
||||||
else:
|
printfe("yellow", "Skipping dependency installation")
|
||||||
printfe("yellow", "Skipping dependency installation")
|
return False
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
# Basic configuration
|
# Basic configuration
|
||||||
userName = "Menno van Leeuwen";
|
userName = "Menno van Leeuwen";
|
||||||
userEmail = "menno@vleeuwen.me";
|
userEmail = "menno@vleeuwen.me";
|
||||||
signingKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM+sKpcREOUjwMMSzEWAso6830wbOi8kUxqpuXWw5gHr";
|
signing = {
|
||||||
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM+sKpcREOUjwMMSzEWAso6830wbOi8kUxqpuXWw5gHr";
|
||||||
|
};
|
||||||
|
|
||||||
# Git settings
|
# Git settings
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
|
|||||||
Reference in New Issue
Block a user