линтеры python перенастроены: mypy заменён на pyrefly
- набор правил ruff расширен по канону rp-local-env (ANN, PTH, C90, G и др.), в lefthook добавлен job ruff check --fix - код приведён под новые правила: логирование через %s вместо f-строк, os.path заменён на pathlib, run_backup_process и initialize разбиты на функции по порогу цикломатической сложности
This commit is contained in:
+7
-5
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -18,12 +19,13 @@ def main() -> None:
|
||||
if args.keep < 0:
|
||||
parser.error("--keep value cannot be negative")
|
||||
|
||||
if not os.path.isdir(args.directory):
|
||||
directory = Path(args.directory)
|
||||
if not directory.is_dir():
|
||||
parser.error(f"Directory not found: {args.directory}")
|
||||
|
||||
# Get list of files (exclude subdirectories)
|
||||
files = []
|
||||
with os.scandir(args.directory) as entries:
|
||||
with os.scandir(directory) as entries:
|
||||
for entry in entries:
|
||||
if entry.is_file():
|
||||
files.append(entry.name)
|
||||
@@ -36,9 +38,9 @@ def main() -> None:
|
||||
|
||||
# Delete files and print results
|
||||
for filename in to_delete:
|
||||
filepath = os.path.join(args.directory, filename)
|
||||
filepath = directory / filename
|
||||
try:
|
||||
os.remove(filepath)
|
||||
filepath.unlink()
|
||||
print(f"Deleted: {filename}")
|
||||
except Exception as e:
|
||||
print(f"Error deleting {filename}: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user