#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Показать функцию sync_rejections — чтобы править прицельно, а не вслепую.""" import re, sys P = "/opt/sovereign/grafana/sync_to_db.py" src = open(P, encoding="utf-8", errors="replace").read() lines = src.splitlines() i = next((n for n, l in enumerate(lines) if re.match(r"\s*def sync_rejections", l)), None) if i is None: sys.exit("функция sync_rejections не найдена") # до следующего def того же уровня indent = len(lines[i]) - len(lines[i].lstrip()) j = i + 1 while j < len(lines): l = lines[j] if l.strip() and (len(l) - len(l.lstrip())) <= indent and re.match(r"\s*(def|class)\s", l): break j += 1 print(f"файл: {P} строки {i+1}-{j}") print("=" * 70) for n in range(i, min(j, i + 60)): print(f"{n+1:4} {lines[n][:96]}")