2021-02-28 04:38:57 +00:00
|
|
|
#
|
2021-11-04 10:28:42 +00:00
|
|
|
# download_mks_assets.py
|
2021-04-27 09:49:21 +00:00
|
|
|
# Added by HAS_TFT_LVGL_UI to download assets from Makerbase repo
|
2021-02-28 04:38:57 +00:00
|
|
|
#
|
2021-11-04 10:28:42 +00:00
|
|
|
import pioutil
|
|
|
|
if pioutil.is_pio_build():
|
2022-08-19 16:00:52 +00:00
|
|
|
Import("env")
|
|
|
|
import requests,zipfile,tempfile,shutil
|
|
|
|
from pathlib import Path
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/0263cdaccf.zip"
|
|
|
|
deps_path = Path(env.Dictionary("PROJECT_LIBDEPS_DIR"))
|
|
|
|
zip_path = deps_path / "mks-assets.zip"
|
|
|
|
assets_path = Path(env.Dictionary("PROJECT_BUILD_DIR"), env.Dictionary("PIOENV"), "assets")
|
2021-10-19 07:49:35 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
def download_mks_assets():
|
2023-05-21 13:38:42 +00:00
|
|
|
print("Downloading MKS Assets for TFT_LVGL_UI")
|
2022-08-19 16:00:52 +00:00
|
|
|
r = requests.get(url, stream=True)
|
|
|
|
# the user may have a very clean workspace,
|
|
|
|
# so create the PROJECT_LIBDEPS_DIR directory if not exits
|
|
|
|
if not deps_path.exists():
|
|
|
|
deps_path.mkdir()
|
|
|
|
with zip_path.open('wb') as fd:
|
|
|
|
for chunk in r.iter_content(chunk_size=128):
|
|
|
|
fd.write(chunk)
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
def copy_mks_assets():
|
2023-05-21 13:38:42 +00:00
|
|
|
print("Copying MKS Assets for TFT_LVGL_UI")
|
2022-08-19 16:00:52 +00:00
|
|
|
output_path = Path(tempfile.mkdtemp())
|
|
|
|
zip_obj = zipfile.ZipFile(zip_path, 'r')
|
|
|
|
zip_obj.extractall(output_path)
|
|
|
|
zip_obj.close()
|
|
|
|
if assets_path.exists() and not assets_path.is_dir():
|
|
|
|
assets_path.unlink()
|
|
|
|
if not assets_path.exists():
|
|
|
|
assets_path.mkdir()
|
|
|
|
base_path = ''
|
|
|
|
for filename in output_path.iterdir():
|
|
|
|
base_path = filename
|
|
|
|
fw_path = (output_path / base_path / 'Firmware')
|
|
|
|
font_path = fw_path / 'mks_font'
|
|
|
|
for filename in font_path.iterdir():
|
|
|
|
shutil.copy(font_path / filename, assets_path)
|
|
|
|
pic_path = fw_path / 'mks_pic'
|
|
|
|
for filename in pic_path.iterdir():
|
|
|
|
shutil.copy(pic_path / filename, assets_path)
|
|
|
|
shutil.rmtree(output_path, ignore_errors=True)
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
if not zip_path.exists():
|
|
|
|
download_mks_assets()
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
if not assets_path.exists():
|
|
|
|
copy_mks_assets()
|