Add invoke as task runner, ruff and fix mypy errors
This commit is contained in:
@@ -4,6 +4,7 @@ Backup script for all applications
|
||||
Automatically discovers and runs backup scripts for all users,
|
||||
then creates restic backups and sends notifications.
|
||||
"""
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import sys
|
||||
@@ -153,7 +154,7 @@ class ResticStorage(Storage):
|
||||
|
||||
|
||||
class Notifier(ABC):
|
||||
def send(self, html_message: str):
|
||||
def send(self, html_message: str) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -174,7 +175,7 @@ class TelegramNotifier(Notifier):
|
||||
f"Missing notification configuration values for backend {name}"
|
||||
)
|
||||
|
||||
def send(self, html_message: str):
|
||||
def send(self, html_message: str) -> None:
|
||||
url = f"https://api.telegram.org/bot{self.telegram_bot_token}/sendMessage"
|
||||
data = {
|
||||
"chat_id": self.telegram_chat_id,
|
||||
@@ -358,10 +359,10 @@ class BackupManager:
|
||||
)
|
||||
|
||||
if self.warnings:
|
||||
message += f"\n\n⚠️ Предупреждения:\n" + "\n".join(self.warnings)
|
||||
message += "\n\n⚠️ Предупреждения:\n" + "\n".join(self.warnings)
|
||||
|
||||
if self.errors:
|
||||
message += f"\n\n❌ Ошибки:\n" + "\n".join(self.errors)
|
||||
message += "\n\n❌ Ошибки:\n" + "\n".join(self.errors)
|
||||
|
||||
for notificator in self.notifiers:
|
||||
try:
|
||||
@@ -470,7 +471,7 @@ def initialize(config_path: Path) -> BackupManager:
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
try:
|
||||
backup_manager = initialize(CONFIG_PATH)
|
||||
success = backup_manager.run_backup_process()
|
||||
|
||||
8
files/gramps/gramps_rename.py
Executable file → Normal file
8
files/gramps/gramps_rename.py
Executable file → Normal file
@@ -9,7 +9,9 @@ def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Rename Gramps document files by appending extensions from a list."
|
||||
)
|
||||
parser.add_argument("directory", type=Path, help="Directory containing hashed files")
|
||||
parser.add_argument(
|
||||
"directory", type=Path, help="Directory containing hashed files"
|
||||
)
|
||||
parser.add_argument("names_file", type=Path, help="Text file with target names")
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -33,7 +35,9 @@ def rename_files(directory: Path, names: list[str]) -> None:
|
||||
for name in names:
|
||||
hash_part, dot, _ = name.partition(".")
|
||||
if not dot:
|
||||
print(f"Skipping invalid entry (missing extension): {name}", file=sys.stderr)
|
||||
print(
|
||||
f"Skipping invalid entry (missing extension): {name}", file=sys.stderr
|
||||
)
|
||||
continue
|
||||
|
||||
source = directory / hash_part
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import argparse
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Retain specified number of files in a directory sorted by name, delete others."
|
||||
)
|
||||
@@ -32,7 +32,7 @@ def main():
|
||||
sorted_files = sorted(files)
|
||||
|
||||
# Identify files to delete
|
||||
to_delete = sorted_files[:-args.keep] if args.keep > 0 else sorted_files.copy()
|
||||
to_delete = sorted_files[: -args.keep] if args.keep > 0 else sorted_files.copy()
|
||||
|
||||
# Delete files and print results
|
||||
for filename in to_delete:
|
||||
|
||||
Reference in New Issue
Block a user