File: move_proofs.py

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (52 lines) | stat: -rwxr-xr-x 1,443 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3

import os
import pathlib
import shutil


def main():
    jobs_dir = pathlib.Path(".")
    suffixes = [m.name[9:] for m in jobs_dir.glob("Makefile.*")]
    suffixes.sort(key=lambda x: len(x), reverse=True)

    misc = pathlib.Path("aws_misc")
    moves = {misc: []}

    for dyr in jobs_dir.iterdir():
        if not dyr.is_dir():
            continue
        found = False
        for suffix in suffixes:
            if not dyr.name.startswith(suffix):
                continue
            group = pathlib.Path(suffix)
            pair = (dyr, group / dyr.name[len(suffix) + 1:])
            try:
                moves[group].append(pair)
            except KeyError:
                moves[group] = [pair]
            found = True
            break
        if not found:
            moves[misc].append((dyr, misc / dyr.name))

    for group, dyrs in moves.items():
        if len(dyrs) != len(set(dyrs)):
            print(f"group {group} contains duplicates")
            exit(1)
    for group, dyrs in moves.items():
        print()
        print(group.name)
        group.mkdir(exist_ok=True, parents=True)
        makefile = pathlib.Path(f"Makefile.{group.name}")
        if makefile.exists():
            makefile.rename(group / makefile.name)
        for src, dst in sorted(dyrs):
            if dst.name == group.name:
                continue
            src.rename(dst)


if __name__ == "__main__":
    main()