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.

upload_extra_script.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #
  2. # sets output_port
  3. # if target_filename is found then that drive is used
  4. # else if target_drive is found then that drive is used
  5. #
  6. target_filename = "FIRMWARE.CUR"
  7. target_drive = "REARM"
  8. import platform
  9. current_OS = platform.system()
  10. if current_OS == 'Windows':
  11. #
  12. # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
  13. # Windows - doesn't care about the disk's name, only cares about the drive letter
  14. #
  15. #
  16. # get all drives on this computer
  17. #
  18. import subprocess
  19. driveStr = subprocess.check_output("fsutil fsinfo drives") # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  20. driveStr = driveStr.strip().lstrip('Drives: ') # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  21. drives = driveStr.split() # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
  22. #
  23. # scan top directory of each drive for FIRMWARE.CUR
  24. # return first drive found
  25. #
  26. import os
  27. target_file_found = False
  28. target_drive_found = False
  29. for drive in drives:
  30. final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
  31. # modified version of walklevel()
  32. level=0
  33. some_dir = "/"
  34. some_dir = some_dir.rstrip(os.path.sep)
  35. assert os.path.isdir(some_dir)
  36. num_sep = some_dir.count(os.path.sep)
  37. for root, dirs, files in os.walk(final_drive_name):
  38. num_sep_this = root.count(os.path.sep)
  39. if num_sep + level <= num_sep_this:
  40. del dirs[:]
  41. volume_info = subprocess.check_output('fsutil fsinfo volumeinfo ' + final_drive_name)
  42. if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
  43. target_drive_found = True
  44. upload_disk = root
  45. if target_filename in files:
  46. if target_file_found == False:
  47. upload_disk = root
  48. target_file_found = True
  49. #
  50. # set upload_port to drive if found
  51. #
  52. if target_file_found == True or target_drive_found == True:
  53. Import("env")
  54. env.Replace(
  55. UPLOAD_PORT = upload_disk
  56. )
  57. if current_OS == 'Linux':
  58. #
  59. # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
  60. #
  61. import os
  62. target_file_found = False
  63. target_drive_found = False
  64. medias = os.listdir('/media') #
  65. for media in medias:
  66. drives = os.listdir('/media/' + media) #
  67. if target_drive in drives and target_file_found == False: # set upload if not found target file yet
  68. target_drive_found = True
  69. upload_disk = '/media/' + media + '/' + target_drive + '/'
  70. for drive in drives:
  71. files = os.listdir('/media/' + media + '/' + drive ) #
  72. if target_filename in files:
  73. if target_file_found == False:
  74. upload_disk = '/media/' + media + '/' + drive + '/'
  75. target_file_found = True
  76. #
  77. # set upload_port to drive if found
  78. #
  79. if target_file_found == True or target_drive_found == True:
  80. Import("env")
  81. env.Replace(
  82. UPLOAD_FLAGS = "-P$UPLOAD_PORT",
  83. UPLOAD_PORT = upload_disk
  84. )
  85. if current_OS == 'Darwin': # MAC
  86. #
  87. # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
  88. #
  89. import os
  90. drives = os.listdir('/Volumes') # human readable names
  91. target_file_found = False
  92. target_drive_found = False
  93. if target_drive in drives and target_file_found == False: # set upload if not found target file yet
  94. target_drive_found = True
  95. upload_disk = '/Volumes/' + drive + '/'
  96. for drive in drives:
  97. target_file_found = True
  98. filenames = os.listdir('/Volumes/' + drive + '/')
  99. if target_filename in filenames:
  100. if target_file_found == False:
  101. upload_disk = '/Volumes/' + drive + '/'
  102. target_file_found = True
  103. #
  104. # set upload_port to drive if found
  105. #
  106. if target_file_found == True or target_drive_found == True:
  107. Import("env")
  108. env.Replace(
  109. UPLOAD_PORT = upload_disk
  110. )