File size: 1,132 Bytes
2f382c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Filter a text stream so Slurm logs do not expose local identity details."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

from accesspath3r.privacy import sanitize_text  # noqa: E402


def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser()
    parser.add_argument("--project-root", type=Path, required=True)
    parser.add_argument("--output-root", type=Path, default=None)
    parser.add_argument("--sensitive-path", action="append", default=[])
    return parser


def main() -> int:
    args = build_parser().parse_args()
    for chunk in sys.stdin:
        sys.stdout.write(
            sanitize_text(
                chunk,
                project_root=args.project_root,
                output_root=args.output_root,
                sensitive_paths=args.sensitive_path,
            )
        )
        sys.stdout.flush()
    return 0


if __name__ == "__main__":
    raise SystemExit(main())