Datasets:
Download code/tools/scan_paths.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/scan_paths.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/tools/scan_paths.py
-
curl -L -o scan_paths.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/scan_paths.py
2.71 kB
| #!/usr/bin/env python3 | |
| """Scan both stage roots (read-only): which non-media files contain local absolute paths / internal host names, | |
| and which 64-hex hashes each file contains. Output: work/scan.json.""" | |
| import json, os, re, sys, collections as C | |
| from concurrent.futures import ProcessPoolExecutor | |
| from pathlib import Path | |
| H = Path('${LOCAL}/simulation-workspace/runs/hf-release-20261120') | |
| ROOTS = [H / 'stage', Path('${LOCAL}/shm/ent400/hf-release-20261120/stage')] | |
| MEDIA = {'.mp4', '.png', '.jpg', '.jpeg', '.ktx2', '.glb', '.bin', '.stl'} | |
| ABS = re.compile(rb'(?:${LOCAL}|${LOCAL}|${LOCAL}/data|${LOCAL}/shm|/home/[a-z]|/root/\.cache|/tmp/)[^"\'\s<>|,;)\]}\\]*') | |
| HOST = re.compile(rb'<gateway>|<host>|<ip>.\d+|<agent>-|dsw-\d+') | |
| HEX = re.compile(rb'(?<![0-9a-f])[0-9a-f]{64}(?![0-9a-f])') | |
| def one(a): | |
| root, rel = a; p = Path(root) / rel | |
| b = p.read_bytes() | |
| text = b'\x00' not in b[:8192] | |
| abs_ = ABS.findall(b); host = HOST.findall(b) | |
| return dict(rel=rel, root=str(root), size=len(b), text=text, n_abs=len(abs_), | |
| prefixes=sorted({'/'.join(x.decode('utf-8', 'replace').split('/')[:6]) for x in abs_}), | |
| hosts=sorted({x.decode() for x in host}), hashes=sorted({x.decode() for x in HEX.findall(b)}) if (abs_ or text or p.suffix in ('.npz', '.usd', '.npy')) else []) | |
| def main(): | |
| jobs = [] | |
| for r in ROOTS: | |
| for dp, _, fs in os.walk(r): | |
| for f in fs: | |
| p = Path(dp) / f | |
| if p.suffix.lower() in MEDIA or f == 'MANIFEST.sha256': continue | |
| jobs.append((str(r), str(p.relative_to(r)))) | |
| with ProcessPoolExecutor(24) as ex: | |
| res = list(ex.map(one, jobs, chunksize=64)) | |
| json.dump(res, open(H / 'work/scan.json', 'w')) | |
| hit = [x for x in res if x['n_abs'] or x['hosts']] | |
| print('scanned', len(res), 'files with abs/host', len(hit), 'binary among them', sum(not x['text'] for x in hit), | |
| 'bytes to rewrite %.2f GB' % (sum(x['size'] for x in hit) / 1e9)) | |
| pre = C.Counter(p for x in hit for p in x['prefixes']); print('top prefixes:'); [print(f' {n:6d} {k}') for k, n in pre.most_common(40)] | |
| print('hosts:', C.Counter(h for x in hit for h in x['hosts'])) | |
| print('binary files with abs:', C.Counter(Path(x['rel']).suffix for x in hit if not x['text'])) | |
| by = C.Counter(); sz = C.Counter() | |
| for x in hit: | |
| k = re.sub(r'/(p\d_H\d\d-[^/]+|[0-9]{9}(_[0-9]{9})?|[0-9a-f]{64})/', '/<X>/', x['rel']); k = k.split('/')[0] + '/.../' + Path(x['rel']).name if k.count('/') > 3 else k | |
| by[k] += 1; sz[k] += x['size'] | |
| print('by file kind:'); [print(f' {n:6d} {sz[k]/1e6:9.1f} MB {k}') for k, n in by.most_common(40)] | |
| if __name__ == "__main__": | |
| main() | |