My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

download_mks_assets.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Import("env")
  2. import os
  3. import requests
  4. import zipfile
  5. import tempfile
  6. import shutil
  7. url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/master.zip"
  8. zip_path = os.path.join(env.Dictionary("PROJECT_LIBDEPS_DIR"), "mks-assets.zip")
  9. assets_path = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env.Dictionary("PIOENV"), "assets")
  10. def download_mks_assets():
  11. print("Downloading MKS Assets")
  12. r = requests.get(url, stream=True)
  13. # the user may have a very clean workspace,
  14. # so create the PROJECT_LIBDEPS_DIR directory if not exits
  15. if os.path.exists(env.Dictionary("PROJECT_LIBDEPS_DIR")) == False:
  16. os.mkdir(env.Dictionary("PROJECT_LIBDEPS_DIR"))
  17. with open(zip_path, 'wb') as fd:
  18. for chunk in r.iter_content(chunk_size=128):
  19. fd.write(chunk)
  20. def copy_mks_assets():
  21. print("Copying MKS Assets")
  22. output_path = tempfile.mkdtemp()
  23. zip_obj = zipfile.ZipFile(zip_path, 'r')
  24. zip_obj.extractall(output_path)
  25. zip_obj.close()
  26. if os.path.exists(assets_path) == True and os.path.isdir(assets_path) == False:
  27. os.unlink(assets_path)
  28. if os.path.exists(assets_path) == False:
  29. os.mkdir(assets_path)
  30. base_path = ''
  31. for filename in os.listdir(output_path):
  32. base_path = filename
  33. for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_font')):
  34. shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_font', filename), assets_path)
  35. for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_pic')):
  36. shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_pic', filename), assets_path)
  37. shutil.rmtree(output_path, ignore_errors=True)
  38. if os.path.exists(zip_path) == False:
  39. download_mks_assets()
  40. if os.path.exists(assets_path) == False:
  41. copy_mks_assets()