1 #!/usr/bin/env nix-shell
2 #! nix-shell -i python -p "python3.withPackages (ps: with ps; [ ps.absl-py ps.requests ])"
11 from absl
import app
, flags
13 BASE_NAME
= "Install_NDI_SDK_v5_Linux"
14 NDI_SDK_URL
= f
"https://downloads.ndi.tv/SDK/NDI_SDK_Linux/{BASE_NAME}.tar.gz"
15 NDI_EXEC
= f
"{BASE_NAME}.sh"
17 NDI_ARCHIVE_MAGIC
= b
"__NDI_ARCHIVE_BEGIN__\n"
19 FLAG_out
= flags
.DEFINE_string("out", None, "Path to read/write version.json from/to.")
22 def find_version_json() -> str:
25 try_paths
= ["pkgs/development/libraries/ndi/version.json", "version.json"]
26 for path
in try_paths
:
27 if os
.path
.exists(path
):
30 "Couldn't figure out where to write version.json; try specifying --out"
34 def fetch_tarball() -> bytes
:
35 r
= requests
.get(NDI_SDK_URL
)
40 def read_version(tarball
: bytes
) -> str:
41 # Find the inner script.
42 outer_tarfile
= tarfile
.open(fileobj
=io
.BytesIO(tarball
), mode
="r:gz")
43 eula_script
= outer_tarfile
.extractfile(NDI_EXEC
).read()
45 # Now find the archive embedded within the script.
46 archive_start
= eula_script
.find(NDI_ARCHIVE_MAGIC
) + len(NDI_ARCHIVE_MAGIC
)
47 inner_tarfile
= tarfile
.open(
48 fileobj
=io
.BytesIO(eula_script
[archive_start
:]), mode
="r:gz"
51 # Now find Version.txt...
53 inner_tarfile
.extractfile("NDI SDK for Linux/Version.txt")
57 _
, _
, version
= version_txt
.strip().partition(" v")
62 tarball
= fetch_tarball()
64 sha256
= hashlib
.sha256(tarball
).hexdigest()
66 "hash": f
"sha256:{sha256}",
67 "version": read_version(tarball
),
70 out_path
= find_version_json()
71 with
open(out_path
, "w") as f
:
76 if __name__
== "__main__":