sidrefresh's picture
Add files using upload-large-folder tool
1daa78e verified
Raw History Blame Contribute Delete
956 Bytes
"""Freeze named submissions with hashes; never merge whitespace-distinct paths."""
from pathlib import Path
import json
import shutil
from media import sha256
def freeze(project, videos, out):
out = Path(out)
out.mkdir(parents=True, exist_ok=True)
records = []
for role, source in [('project', project)] + list(videos.items()):
source = Path(source)
row = {'role': role, 'original_path': str(source)}
if not source.is_file():
row['status'] = 'missing'
else:
destination = out / role / source.name
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, destination)
row.update(status='ok', path=str(destination), sha256=sha256(destination),
size_bytes=destination.stat().st_size)
records.append(row)
(out / 'manifest.json').write_text(json.dumps(records, indent=2) + '\n')
return records