summarylogtreecommitdiffstats
path: root/extract-g3mtool.py
blob: 687a447beba5a9c0bdf60d7acf4c9262bc791793 (plain)
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
#!/usr/bin/python
"""Extract the Linux G3MTool payload from an official PyInstaller release."""

import sys
from pathlib import Path

from PyInstaller.archive.readers import CArchiveReader

PREFIX = "src/assets/bin/g3mtool_linux/"


def main() -> None:
    archive = CArchiveReader(sys.argv[1])
    destination = Path(sys.argv[2])
    members = [name for name in archive.toc if name.startswith(PREFIX)]
    if not members:
        raise RuntimeError("official release contains no Linux G3MTool payload")

    for name in members:
        target = destination / name.removeprefix(PREFIX)
        target.parent.mkdir(parents=True, exist_ok=True)
        target.write_bytes(archive.extract(name))


if __name__ == "__main__":
    main()