aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_json/get_sdl2.py
diff options
context:
space:
mode:
authorKevin Schlosser <kdschlosser@users.noreply.github.com>2024-06-20 14:02:25 -0600
committerGitHub <noreply@github.com>2024-06-20 22:02:25 +0200
commitec80fe49fa3a3e239109949dd5ef2f84326f0fc5 (patch)
tree9330860a27b9de617935c990c9557da26c961792 /scripts/gen_json/get_sdl2.py
parent25e993a1372a9e98187c37331a7d0705475ae431 (diff)
downloadlvgl-ec80fe49fa3a3e239109949dd5ef2f84326f0fc5.tar.gz
lvgl-ec80fe49fa3a3e239109949dd5ef2f84326f0fc5.zip
feat: add API JSON generator (#5677)
Co-authored-by: Liam <30486941+liamHowatt@users.noreply.github.com>
Diffstat (limited to 'scripts/gen_json/get_sdl2.py')
-rw-r--r--scripts/gen_json/get_sdl2.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/gen_json/get_sdl2.py b/scripts/gen_json/get_sdl2.py
new file mode 100644
index 000000000..ea775af7c
--- /dev/null
+++ b/scripts/gen_json/get_sdl2.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+import zipfile
+import io
+import os
+
+
+SDL2_URL = 'https://github.com/libsdl-org/SDL/releases/download/release-2.26.5/SDL2-devel-2.26.5-VC.zip' # NOQA
+
+
+def get_path(name: str, p: str) -> str:
+ for file in os.listdir(p):
+ file = os.path.join(p, file)
+
+ if file.endswith(name):
+ return file
+
+ if os.path.isdir(file):
+ if res := get_path(name, file):
+ return res
+
+
+def get_sdl2(path, url=SDL2_URL):
+ import requests # NOQA
+
+ stream = io.BytesIO()
+
+ with requests.get(url, stream=True) as r:
+ r.raise_for_status()
+
+ content_length = int(r.headers['Content-Length'])
+ chunks = 0
+ # print()
+ # sys.stdout.write('\r' + str(chunks) + '/' + str(content_length))
+ # sys.stdout.flush()
+
+ for chunk in r.iter_content(chunk_size=1024):
+ stream.write(chunk)
+ chunks += len(chunk)
+ # sys.stdout.write('\r' + str(chunks) + '/' + str(content_length))
+ # sys.stdout.flush()
+
+ # print()
+ stream.seek(0)
+ zf = zipfile.ZipFile(stream)
+
+ for z_item in zf.infolist():
+ for ext in ('.h', '.dll', '.lib'):
+ if not z_item.filename.endswith(ext):
+ continue
+
+ zf.extract(z_item, path=path)
+ break
+
+ include_path = get_path('include', path)
+ lib_path = get_path('lib\\x64', path)
+ dll_path = get_path('SDL2.dll', lib_path)
+
+ sdl_include_path = os.path.split(include_path)[0]
+ if not os.path.exists(os.path.join(sdl_include_path, 'SDL2')):
+ os.rename(include_path, os.path.join(sdl_include_path, 'SDL2'))
+
+ zf.close()
+ stream.close()
+
+ return os.path.abspath(sdl_include_path), dll_path