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