Fix some pylint issues
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Uptime Kuma client wrapper for API operations."""
|
||||
|
||||
import fnmatch
|
||||
import re
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from uptime_kuma_api import UptimeKumaApi
|
||||
|
||||
|
||||
class KumaClient:
|
||||
"""Client wrapper for Uptime Kuma API operations."""
|
||||
|
||||
def __init__(self, url, username=None, password=None):
|
||||
self.url = url
|
||||
self.username = username
|
||||
@@ -29,9 +32,9 @@ class KumaClient:
|
||||
|
||||
if unit == "s":
|
||||
return value
|
||||
elif unit == "m":
|
||||
if unit == "m":
|
||||
return value * 60
|
||||
elif unit == "h":
|
||||
if unit == "h":
|
||||
return value * 3600
|
||||
|
||||
raise ValueError(f"Invalid duration unit: {unit}")
|
||||
@@ -71,7 +74,7 @@ class KumaClient:
|
||||
try:
|
||||
self.api = UptimeKumaApi(self.url)
|
||||
if self.username and self.password:
|
||||
result = self.api.login(self.username, self.password)
|
||||
self.api.login(self.username, self.password)
|
||||
print(f"Connected to {self.url}")
|
||||
return True
|
||||
except Exception as e:
|
||||
|
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Info command implementations for Uptime Kuma CLI."""
|
||||
|
||||
from ..client import KumaClient
|
||||
|
||||
|
||||
class InfoCommands:
|
||||
"""Commands for retrieving server information."""
|
||||
|
||||
def __init__(self, client: KumaClient):
|
||||
self.client = client
|
||||
|
||||
@@ -29,7 +32,7 @@ def setup_info_parser(subparsers):
|
||||
return info_parser
|
||||
|
||||
|
||||
def handle_info_command(args, client):
|
||||
def handle_info_command(args, client): # pylint: disable=unused-argument
|
||||
"""Handle info command execution"""
|
||||
info_commands = InfoCommands(client)
|
||||
info_commands.get_info()
|
||||
|
@@ -1,10 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Maintenance command implementations for Uptime Kuma CLI."""
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from ..client import KumaClient
|
||||
|
||||
|
||||
class MaintenanceCommands:
|
||||
"""Commands for managing maintenance windows."""
|
||||
|
||||
def __init__(self, client: KumaClient):
|
||||
self.client = client
|
||||
|
||||
@@ -49,7 +52,8 @@ class MaintenanceCommands:
|
||||
# Check if we have either monitor patterns or group patterns
|
||||
if not monitor_patterns and not group_patterns:
|
||||
print(
|
||||
"Error: Either --monitor or --group flag is required. Specify at least one pattern."
|
||||
"Error: Either --monitor or --group flag is required. "
|
||||
"Specify at least one pattern."
|
||||
)
|
||||
return
|
||||
|
||||
@@ -102,7 +106,8 @@ class MaintenanceCommands:
|
||||
end_dt = start_dt + timedelta(seconds=duration_seconds)
|
||||
|
||||
print(
|
||||
f"Maintenance window: {start_dt.strftime('%Y-%m-%d %H:%M:%S UTC')} - {end_dt.strftime('%Y-%m-%d %H:%M:%S UTC')} ({duration})"
|
||||
f"Maintenance window: {start_dt.strftime('%Y-%m-%d %H:%M:%S UTC')} - "
|
||||
f"{end_dt.strftime('%Y-%m-%d %H:%M:%S UTC')} ({duration})"
|
||||
)
|
||||
|
||||
# Create the maintenance with single strategy and date range
|
||||
@@ -157,7 +162,8 @@ class MaintenanceCommands:
|
||||
print(f"Found {len(maintenances)} maintenances to delete:")
|
||||
for maintenance in maintenances:
|
||||
print(
|
||||
f" - {maintenance.get('title', 'N/A')} (ID: {maintenance.get('id', 'N/A')})"
|
||||
f" - {maintenance.get('title', 'N/A')} "
|
||||
f"(ID: {maintenance.get('id', 'N/A')})"
|
||||
)
|
||||
|
||||
# Delete all maintenances
|
||||
@@ -168,7 +174,8 @@ class MaintenanceCommands:
|
||||
maintenance.get("id")
|
||||
)
|
||||
print(
|
||||
f"Deleted maintenance '{maintenance.get('title', 'N/A')}' (ID: {maintenance.get('id')})"
|
||||
f"Deleted maintenance '{maintenance.get('title', 'N/A')}' "
|
||||
f"(ID: {maintenance.get('id')})"
|
||||
)
|
||||
deleted_count += 1
|
||||
except Exception as e:
|
||||
@@ -189,7 +196,8 @@ class MaintenanceCommands:
|
||||
|
||||
result = self.client.api.delete_maintenance(maintenance_id)
|
||||
print(
|
||||
f"Successfully deleted maintenance '{maintenance_title}' (ID: {maintenance_id})"
|
||||
f"Successfully deleted maintenance '{maintenance_title}' "
|
||||
f"(ID: {maintenance_id})"
|
||||
)
|
||||
print(f"API response: {result}")
|
||||
|
||||
@@ -209,8 +217,6 @@ def setup_maintenance_parser(subparsers):
|
||||
maintenance_parser = subparsers.add_parser(
|
||||
"maintenance", help="Maintenance operations"
|
||||
)
|
||||
# Store reference to parser for help display
|
||||
setup_maintenance_parser._parser = maintenance_parser
|
||||
maintenance_subparsers = maintenance_parser.add_subparsers(
|
||||
dest="maintenance_action", help="Maintenance actions"
|
||||
)
|
||||
@@ -250,12 +256,14 @@ def setup_maintenance_parser(subparsers):
|
||||
add_maintenance_parser.add_argument(
|
||||
"--monitor",
|
||||
action="append",
|
||||
help="Monitor name pattern to add to maintenance (supports wildcards like *NextCloud*, can be repeated)",
|
||||
help="Monitor name pattern to add to maintenance "
|
||||
"(supports wildcards like *NextCloud*, can be repeated)",
|
||||
)
|
||||
add_maintenance_parser.add_argument(
|
||||
"--group",
|
||||
action="append",
|
||||
help="Group name pattern to add all group members to maintenance (supports wildcards, can be repeated)",
|
||||
help="Group name pattern to add all group members to maintenance "
|
||||
"(supports wildcards, can be repeated)",
|
||||
)
|
||||
|
||||
return maintenance_parser
|
||||
@@ -266,14 +274,11 @@ def handle_maintenance_command(args, client):
|
||||
maintenance_commands = MaintenanceCommands(client)
|
||||
|
||||
if not args.maintenance_action:
|
||||
if hasattr(setup_maintenance_parser, "_parser"):
|
||||
setup_maintenance_parser._parser.print_help()
|
||||
else:
|
||||
print(
|
||||
"Error: No maintenance action specified. Use --help for usage information."
|
||||
)
|
||||
print(
|
||||
"Error: No maintenance action specified. Use --help for usage information."
|
||||
)
|
||||
return False
|
||||
elif args.maintenance_action == "list":
|
||||
if args.maintenance_action == "list":
|
||||
maintenance_commands.list_maintenances()
|
||||
elif args.maintenance_action == "add":
|
||||
title = (
|
||||
|
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Monitor command implementations for Uptime Kuma CLI."""
|
||||
|
||||
from ..client import KumaClient
|
||||
|
||||
|
||||
class MonitorCommands:
|
||||
"""Commands for managing monitors."""
|
||||
|
||||
def __init__(self, client: KumaClient):
|
||||
self.client = client
|
||||
|
||||
@@ -61,7 +64,8 @@ class MonitorCommands:
|
||||
parent_name = parent_monitor.get("name", f"Group {parent_id}")
|
||||
|
||||
print(
|
||||
f"{monitor_id:<5} {name:<25} {monitor_type:<12} {parent_name:<20} {url:<35} {active:<10}"
|
||||
f"{monitor_id:<5} {name:<25} {monitor_type:<12} "
|
||||
f"{parent_name:<20} {url:<35} {active:<10}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
@@ -73,7 +77,8 @@ class MonitorCommands:
|
||||
# Check if we have either monitor patterns or group patterns
|
||||
if not monitor_patterns and not group_patterns:
|
||||
print(
|
||||
"Error: Either --monitor or --group flag is required. Specify at least one pattern."
|
||||
"Error: Either --monitor or --group flag is required. "
|
||||
"Specify at least one pattern."
|
||||
)
|
||||
return
|
||||
|
||||
@@ -119,7 +124,7 @@ class MonitorCommands:
|
||||
paused_count = 0
|
||||
for monitor in matched_monitors:
|
||||
try:
|
||||
result = self.client.api.pause_monitor(monitor["id"])
|
||||
self.client.api.pause_monitor(monitor["id"])
|
||||
print(f"Paused monitor '{monitor['name']}' (ID: {monitor['id']})")
|
||||
paused_count += 1
|
||||
except Exception as e:
|
||||
@@ -201,7 +206,7 @@ class MonitorCommands:
|
||||
resumed_count = 0
|
||||
for monitor in matched_monitors:
|
||||
try:
|
||||
result = self.client.api.resume_monitor(monitor["id"])
|
||||
self.client.api.resume_monitor(monitor["id"])
|
||||
print(f"Resumed monitor '{monitor['name']}' (ID: {monitor['id']})")
|
||||
resumed_count += 1
|
||||
except Exception as e:
|
||||
@@ -218,8 +223,6 @@ class MonitorCommands:
|
||||
def setup_monitor_parser(subparsers):
|
||||
"""Setup monitor command parser"""
|
||||
monitor_parser = subparsers.add_parser("monitor", help="Monitor operations")
|
||||
# Store reference to parser for help display
|
||||
setup_monitor_parser._parser = monitor_parser
|
||||
monitor_subparsers = monitor_parser.add_subparsers(
|
||||
dest="monitor_action", help="Monitor actions"
|
||||
)
|
||||
@@ -280,14 +283,9 @@ def handle_monitor_command(args, client):
|
||||
monitor_commands = MonitorCommands(client)
|
||||
|
||||
if not args.monitor_action:
|
||||
if hasattr(setup_monitor_parser, "_parser"):
|
||||
setup_monitor_parser._parser.print_help()
|
||||
else:
|
||||
print(
|
||||
"Error: No monitor action specified. Use --help for usage information."
|
||||
)
|
||||
print("Error: No monitor action specified. Use --help for usage information.")
|
||||
return False
|
||||
elif args.monitor_action == "list":
|
||||
if args.monitor_action == "list":
|
||||
monitor_commands.list_monitors(
|
||||
monitor_patterns=args.monitor, group_patterns=args.group
|
||||
)
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Main CLI module for Uptime Kuma."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
# Handle both direct execution and package import
|
||||
try:
|
||||
@@ -24,6 +24,7 @@ except ImportError:
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point for the CLI application."""
|
||||
parser = argparse.ArgumentParser(description="Uptime Kuma CLI Client")
|
||||
parser.add_argument(
|
||||
"--url", help="Uptime Kuma server URL (can also use KUMA_URL env var)"
|
||||
@@ -40,9 +41,9 @@ def main():
|
||||
subparsers = parser.add_subparsers(dest="resource", help="Resource to operate on")
|
||||
|
||||
# Setup command parsers
|
||||
monitor_parser = setup_monitor_parser(subparsers)
|
||||
maintenance_parser = setup_maintenance_parser(subparsers)
|
||||
info_parser = setup_info_parser(subparsers)
|
||||
setup_monitor_parser(subparsers)
|
||||
setup_maintenance_parser(subparsers)
|
||||
setup_info_parser(subparsers)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
Reference in New Issue
Block a user