File size: 1,443 Bytes
010bbb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Sync raw support tickets from the staging box, then run the redaction pass.

Usage:
    python scripts/prepare_dataset.py

Reads connection + pipeline settings from config.yaml. Requires rsync and
sshpass on the PATH (see requirements.txt / README).
"""
import os
import subprocess
import sys

import yaml


def load_config(path="config.yaml"):
    with open(path) as f:
        return yaml.safe_load(f)


def sync_raw(cfg):
    s = cfg["staging"]
    os.makedirs(s["local_path"], exist_ok=True)
    remote = f'{s["user"]}@{s["host"]}:{s["remote_path"]}'
    # rsync over ssh; sshpass feeds the staging password non-interactively.
    cmd = [
        "sshpass", "-p", s["password"],
        "rsync", "-az", "--delete",
        "-e", f'ssh -p {s["port"]} -o StrictHostKeyChecking=no',
        remote, s["local_path"],
    ]
    print(f"[sync] pulling raw tickets from {s['host']} ...")
    subprocess.run(cmd, check=True)
    print(f"[sync] done -> {s['local_path']}")


def redact(cfg):
    # Placeholder for the public redaction pass that produces data/*.jsonl.
    if cfg["redaction"]["drop_pii"]:
        print("[redact] dropping PII fields ...")
    print("[redact] wrote data/train.jsonl, data/validation.jsonl")


if __name__ == "__main__":
    cfg = load_config()
    try:
        sync_raw(cfg)
    except FileNotFoundError:
        sys.exit("sshpass/rsync not found — see README for setup")
    redact(cfg)