#!/usr/bin/env python3 """Rewrite recorded machine paths in data files when the data lives somewhere else. Some JSON files and notes record where external data (RPLAN, the asset library, curated releases) was found on the machine they were made on. This tool writes copies of such files with the path prefixes replaced; it never changes the inputs. relocate_paths.py --map /old/prefix=/new/prefix [--map ...] --out DIR [--report] PATH [PATH ...] relocate_paths.py --map ... --check PATH [PATH ...] # writes nothing; exit status 1 if a machine path is left that no --map covers Directories are searched recursively for text files (.json .jsonl .md .txt .sh .yaml .yml .toml .csv); the relative layout is kept under --out. The longest matching --map wins. A rewritten .json file must still parse, otherwise the tool stops. """ import argparse import json import re import sys from pathlib import Path TEXT_SUFFIXES = {'.json', '.jsonl', '.md', '.txt', '.sh', '.yaml', '.yml', '.toml', '.csv'} MACHINE_PATH = re.compile(r'(?