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 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 os
  9. import platform
  10. current_OS = platform.system()
  11. #env_vars = subprocess.check_output('platformio run -t envdump')
  12. #env_vars = env_vars.split('\n')
  13. #for env in env_vars:
  14. # print env
  15. #exit(0)
  16. build_type = os.environ.get("BUILD_TYPE", 'Not Set')
  17. if build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set' :
  18. if current_OS == 'Windows':
  19. #
  20. # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
  21. # Windows - doesn't care about the disk's name, only cares about the drive letter
  22. #
  23. #
  24. # get all drives on this computer
  25. #
  26. import subprocess
  27. driveStr = subprocess.check_output("fsutil fsinfo drives") # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  28. driveStr = driveStr.strip().lstrip('Drives: ') # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
  29. drives = driveStr.split() # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
  30. upload_disk = 'Disk not found'
  31. target_file_found = False
  32. target_drive_found = False
  33. for drive in drives:
  34. final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
  35. try:
  36. volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
  37. except Exception as e:
  38. continue
  39. else:
  40. if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
  41. target_drive_found = True
  42. upload_disk = final_drive_name
  43. if target_filename in volume_info:
  44. if target_file_found == False:
  45. upload_disk = final_drive_name
  46. target_file_found = True
  47. #
  48. # set upload_port to drive if found
  49. #
  50. if target_file_found == True or target_drive_found == True:
  51. Import("env")
  52. env.Replace(
  53. UPLOAD_PORT = upload_disk
  54. )
  55. print 'upload disk: ' , upload_disk
  56. else:
  57. print '\nUnable to find destination disk. File must be copied manually. \n'
  58. if current_OS == 'Linux':
  59. #
  60. # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
  61. #
  62. upload_disk = 'Disk not found'
  63. target_file_found = False
  64. target_drive_found = False
  65. medias = os.listdir('/media') #
  66. for media in medias:
  67. drives = os.listdir('/media/' + media) #
  68. if target_drive in drives and target_file_found == False: # set upload if not found target file yet
  69. target_drive_found = True
  70. upload_disk = '/media/' + media + '/' + target_drive + '/'
  71. for drive in drives:
  72. try:
  73. files = os.listdir('/media/' + media + '/' + drive )
  74. except:
  75. continue
  76. else:
  77. if target_filename in files:
  78. if target_file_found == False:
  79. upload_disk = '/media/' + media + '/' + drive + '/'
  80. target_file_found = True
  81. #
  82. # set upload_port to drive if found
  83. #
  84. if target_file_found == True or target_drive_found == True:
  85. Import("env")
  86. env.Replace(
  87. UPLOAD_FLAGS = "-P$UPLOAD_PORT",
  88. UPLOAD_PORT = upload_disk
  89. )
  90. print 'upload disk: ' , upload_disk
  91. else:
  92. print '\nUnable to find destination disk. File must be copied manually. \n'
  93. if current_OS == 'Darwin': # MAC
  94. #
  95. # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
  96. #
  97. import os
  98. upload_disk = 'Disk not found'
  99. drives = os.listdir('/Volumes') # human readable names
  100. target_file_found = False
  101. target_drive_found = False
  102. if target_drive in drives and target_file_found == False: # set upload if not found target file yet
  103. target_drive_found = True
  104. upload_disk = '/Volumes/' + target_drive + '/'
  105. for drive in drives:
  106. try:
  107. filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected
  108. except:
  109. continue
  110. else:
  111. if target_filename in filenames:
  112. if target_file_found == False:
  113. upload_disk = '/Volumes/' + drive + '/'
  114. target_file_found = True
  115. #
  116. # set upload_port to drive if found
  117. #
  118. if target_file_found == True or target_drive_found == True:
  119. Import("env")
  120. env.Replace(
  121. UPLOAD_PORT = upload_disk
  122. )
  123. print '\nupload disk: ' , upload_disk, '\n'
  124. else:
  125. print '\nUnable to find destination disk. File must be copied manually. \n'