Unverified Commit 66737dcd authored by Peder Bergebakken Sundt's avatar Peder Bergebakken Sundt Committed by Michael Daniels
Browse files

maintainers/scripts/remove-old-aliases: detect and avoid more complex cases

parent f01a5c82
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -42,11 +42,12 @@ def process_args() -> argparse.Namespace:

def get_date_lists(
    txt: list[str], cutoffdate: datetimedate, only_throws: bool
) -> tuple[list[str], list[str], list[str]]:
) -> tuple[list[str], list[str], list[str], list[str]]:
    """get a list of lines in which the date is older than $cutoffdate"""
    date_older_list: list[str] = []
    date_older_throw_list: list[str] = []
    date_sep_line_list: list[str] = []
    date_too_complex_list: list[str] = []

    for lineno, line in enumerate(txt, start=1):
        line = line.rstrip()
@@ -70,11 +71,17 @@ def get_date_lists(
            continue

        if "=" not in line:
            date_sep_line_list.append(f"{lineno} {line}")
            date_sep_line_list.append(f"{lineno:>5} {line}")
        # 'if' lines could be complicated
        elif "if " in line and "if =" not in line:
            print(f"RESOLVE MANUALLY {line}")
        elif "throw" in line:
            date_too_complex_list.append(f"{lineno:>5} {line}")
        elif "= with " in line:
            date_too_complex_list.append(f"{lineno:>5} {line}")
        elif "lib.warnOnInstantiate" in line:
            date_too_complex_list.append(f"{lineno:>5} {line}")
        elif '"' in line:
            date_too_complex_list.append(f"{lineno:>5} {line}")
        elif " = throw" in line:
            date_older_throw_list.append(line)
        elif not only_throws:
            date_older_list.append(line)
@@ -82,6 +89,7 @@ def get_date_lists(
    return (
        date_older_list,
        date_sep_line_list,
        date_too_complex_list,
        date_older_throw_list,
    )

@@ -180,10 +188,14 @@ def main() -> None:
    date_older_list: list[str] = []
    date_sep_line_list: list[str] = []
    date_older_throw_list: list[str] = []
    date_too_complex_list: list[str] = []

    date_older_list, date_sep_line_list, date_older_throw_list = get_date_lists(
        txt, cutoffdate, only_throws
    )
    (
        date_older_list,
        date_sep_line_list,
        date_too_complex_list,
        date_older_throw_list,
    ) = get_date_lists(txt, cutoffdate, only_throws)

    converted_to_throw: list[tuple[str, str]] = []
    if date_older_list:
@@ -197,6 +209,11 @@ def main() -> None:
        for l_n in date_older_throw_list:
            print(l_n)

    if date_too_complex_list:
        print(" Too complex, resolve manually. ".center(100, "-"))
        for l_n in date_too_complex_list:
            print(l_n)

    if date_sep_line_list:
        print(" On separate line, resolve manually. ".center(100, "-"))
        for l_n in date_sep_line_list: