55 lines
2.7 KiB
Python
55 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Import the pinned, authorized local candidate pack; never generate or modify originals."""
|
|
from pathlib import Path, PurePosixPath
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
BASE_SHA = 'ca817f1e538a5933beac4f3f4cda6367bf87a2d428b3307622c98842ae8679d1'
|
|
CALL_SHA = '3b6918cdc955f6d51e8910cf7a0067f4dedb19d28accbb5525f15876e6ad4d8c'
|
|
|
|
def digest(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('source', type=Path)
|
|
args = parser.parse_args()
|
|
source = args.source.resolve(strict=True)
|
|
base = (source/'manifest.json').read_bytes()
|
|
call = (source/'call-avatar-manifest.json').read_bytes()
|
|
assert digest(base) == BASE_SHA and digest(call) == CALL_SHA, 'Manifest hash mismatch'
|
|
manifest, supplement = json.loads(base), json.loads(call)
|
|
assert manifest['schemaVersion'] == 1 and manifest['identityId'] == supplement['identityId'] == 'a01'
|
|
assert manifest['rightsStatus'] == 'unverified' and manifest['deviceTestStatus'] == 'pending'
|
|
assert {a['mode'] for a in manifest['assets']} == {'idle','talk'}
|
|
rows = manifest['assets'] + [manifest['staticFallback'], supplement['waiting']]
|
|
verified = {'manifest.json': base, 'call-avatar-manifest.json': call}
|
|
for row in rows:
|
|
path = PurePosixPath(row['path'])
|
|
assert len(path.parts) == 2 and path.parts[0] in ('videos','frames') and '..' not in path.parts
|
|
src = (source/str(path)).resolve(strict=True)
|
|
assert src.is_relative_to(source) and src.is_file()
|
|
data = src.read_bytes()
|
|
assert len(data) <= 8_000_000 and digest(data) == row['sha256'], str(path)
|
|
if row.get('mode') in ('idle','talk'):
|
|
assert row['emotion'] == 'neutral' and row['intensity'] == 0 and row['loop'] and not row['hasAudio']
|
|
verified[str(path)] = data
|
|
target = ROOT/'app/src/main/assets/avatar/a01-v1'
|
|
# Refuse overwriting an unknown imported file; safe idempotent reimport is supported.
|
|
for name, data in verified.items():
|
|
dest = target/name
|
|
assert not dest.exists() or digest(dest.read_bytes()) == digest(data), f'Unknown existing asset: {dest}'
|
|
target.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
for name, data in verified.items():
|
|
dest = target/name
|
|
dest.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
dest.write_bytes(data); dest.chmod(0o600)
|
|
print(json.dumps({'pack':'a01-v1','files':{name:digest(data) for name,data in verified.items()},
|
|
'rightsStatus':'unverified','deviceTestStatus':'pending'}, indent=2))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|