mvd001/cyberset / scripts /code /record_hf.py
mvd001's picture
download
raw
1.72 kB
#!/usr/bin/env python3
"""Append download receipts (sha256, size, pinned revision) for the Hugging Face-hosted code sources to logs/code/downloads.jsonl."""
import glob, hashlib, json, os, datetime
ROOT = "/workspace/security-dataset"; IST = datetime.timezone(datetime.timedelta(hours=5, minutes=30))
SRC = {"draper_vdisc": ("claudios/Draper", "ac5a08c4292dd42be9a5c5f29780258f81333a46", "hf-ac5a08c", "CC-BY-4.0 (OSF original; HF mirror)"),
"cleanvul": ("yikun-li/CleanVul", "74b2fda1c51eea0f99987df6924ca60c6e9f92d2", "hf-74b2fda", "none (no license file; research use only, not redistributed)"),
"devign": ("google/code_x_glue_cc_defect_detection", "69bd48c03223c2104342acd9a807caf61ac3efb8", "hf-69bd48c", "C-UDA (not redistributed)")}
def sha(p):
h = hashlib.sha256()
with open(p, "rb") as f:
for b in iter(lambda: f.read(1 << 22), b""): h.update(b)
return h.hexdigest()
with open(f"{ROOT}/logs/code/downloads.jsonl", "a") as out:
for ds, (repo, rev, ver, lic) in SRC.items():
for p in sorted(glob.glob(f"{ROOT}/raw/code/{ds}/{ver}/**/*", recursive=True)):
if os.path.isdir(p) or "/.cache/" in p or "box-store-snap" in p or p.endswith(".gitattributes"): continue
rel = os.path.relpath(p, f"{ROOT}/raw/code/{ds}/{ver}")
out.write(json.dumps(dict(dataset=ds, version=ver, url=f"https://huggingface.co/datasets/{repo}/resolve/{rev}/{rel}", hf_repo=repo,
hf_revision=rev, path=os.path.relpath(p, ROOT), size_bytes=os.path.getsize(p), sha256=sha(p), license=lic, status="ok",
downloaded_ist=datetime.datetime.fromtimestamp(os.path.getmtime(p), IST).strftime("%Y-%m-%d %H:%M IST"))) + "\n")
print("ok")

Xet Storage Details

Size:
1.72 kB
·
Xet hash:
d58d2f36e82f9b225770a4f0cf4c96e64437f0552bff24cb41fd803378ebef48

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.