forked from MarlinFirmware/Marlin
-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rhapsodyv/download-mks-assets
script to download mks assets and create the assets folder
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Import("env") | ||
import os | ||
import requests | ||
import zipfile | ||
import tempfile | ||
import shutil | ||
|
||
url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/master.zip" | ||
zip_path = os.path.join(env.Dictionary("PROJECT_LIBDEPS_DIR"), "mks-assets.zip") | ||
assets_path = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env.Dictionary("PIOENV"), "assets") | ||
|
||
def download_mks_assets(): | ||
print("Downloading MKS Assets") | ||
r = requests.get(url, stream=True) | ||
with open(zip_path, 'wb') as fd: | ||
for chunk in r.iter_content(chunk_size=128): | ||
fd.write(chunk) | ||
|
||
def copy_mks_assets(): | ||
print("Copying MKS Assets") | ||
output_path = tempfile.TemporaryDirectory() | ||
zip_obj = zipfile.ZipFile(zip_path, 'r') | ||
zip_obj.extractall(output_path.name) | ||
zip_obj.close() | ||
if os.path.exists(assets_path) == True and os.path.isdir(assets_path) == False: | ||
os.unlink(assets_path) | ||
if os.path.exists(assets_path) == False: | ||
os.mkdir(assets_path) | ||
base_path = '' | ||
for filename in os.listdir(output_path.name): | ||
base_path = filename | ||
for filename in os.listdir(os.path.join(output_path.name, base_path, 'Firmware', 'mks_font')): | ||
shutil.copy(os.path.join(output_path.name, base_path, 'Firmware', 'mks_font', filename), assets_path) | ||
for filename in os.listdir(os.path.join(output_path.name, base_path, 'Firmware', 'mks_pic')): | ||
shutil.copy(os.path.join(output_path.name, base_path, 'Firmware', 'mks_pic', filename), assets_path) | ||
output_path.cleanup() | ||
|
||
if os.path.exists(zip_path) == False: | ||
download_mks_assets() | ||
|
||
if os.path.exists(assets_path) == False: | ||
copy_mks_assets() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters