File size: 956 Bytes
7ec48b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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