taisei/scripts/res-index-install.py
Andrei Alexeyev 28f206a09d
vfs,build: Add "resource index" VFS backend
This is currently unused. It's going to be the backbone for a new
on-the-fly resource fetching system for the Emscripten port.

In this mode, the virtual resource directory structure is embedded into
the executable. Files are referenced by their "content IDs", which are
currently their sha256 hashes. The "resindex" VFS backend allows one to
define a custom file open function, which connects the content IDs to
actual data. A example implementation is provided in resindex_layered,
which simply opens the content ID as a file under a specified VFS path.
2023-01-28 00:31:15 +01:00

62 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python3
import sys
import os
import shutil
from ast import literal_eval
from pathlib import Path
from taiseilib.common import (
add_common_args,
run_main,
)
def install(args):
install_root = Path(os.environ['MESON_INSTALL_DESTDIR_PREFIX'])
install_dir = install_root / args.subdir
install_dir.mkdir(exist_ok=True, parents=True)
installed_files = set(p.name for p in install_dir.iterdir())
quiet = bool(os.environ.get('MESON_INSTALL_QUIET', False))
for line in args.index.read_text().split('\n'):
if not line.startswith('FILE('):
continue
_, unique_id, _, srcpath = literal_eval(line[4:])
if unique_id in installed_files:
continue
dstpath = install_dir / unique_id
assert not dstpath.exists()
if not quiet:
print('Installing resource {} as {}'.format(srcpath, dstpath))
shutil.copy2(srcpath, dstpath)
installed_files.add(unique_id)
def main(args):
import argparse
parser = argparse.ArgumentParser(description='Install resources from res-index', prog=args[0])
parser.add_argument('index',
type=Path,
help='the index file'
)
parser.add_argument('subdir',
help='the target subdirectory (inside prefix)'
)
add_common_args(parser)
args = parser.parse_args(args[1:])
install(args)
if __name__ == '__main__':
run_main(main)