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

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