Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LPC176x] Update PIO extrascript #12878

Merged
merged 2 commits into from Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
155 changes: 74 additions & 81 deletions Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
Expand Up @@ -10,18 +10,16 @@
import os
import platform
current_OS = platform.system()
Import("env")

#env_vars = subprocess.check_output('platformio run -t envdump')
#env_vars = env_vars.split('\n')
#for env in env_vars:
# print env
#exit(0)

build_type = os.environ.get("BUILD_TYPE", 'Not Set')
if build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set' :
def detect_error(e):
print '\nUnable to find destination disk (' + e + ')\n' \
'Please select it in platformio.ini using the upload_port keyword ' \
'(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html)\n' \
'or copy the firmware (.pioenvs/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n'

try:
if current_OS == 'Windows':

#
# platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
# Windows - doesn't care about the disk's name, only cares about the drive letter
Expand All @@ -30,119 +28,114 @@
#
# get all drives on this computer
#

import subprocess

driveStr = subprocess.check_output("fsutil fsinfo drives") # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
driveStr = driveStr.strip().lstrip('Drives: ') # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
drives = driveStr.split() # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
# typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
driveStr = subprocess.check_output("fsutil fsinfo drives")
# typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
driveStr = driveStr.strip().lstrip('Drives: ')
# typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
# 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
drives = driveStr.split()

upload_disk = 'Disk not found'
target_file_found = False
target_drive_found = False
for drive in drives:
final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
try:
volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
except Exception as e:
continue
else:
if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
target_drive_found = True
upload_disk = final_drive_name
if target_filename in volume_info:
if target_file_found == False:
upload_disk = final_drive_name
target_file_found = True
final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
try:
volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
except Exception as e:
continue
else:
if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
target_drive_found = True
upload_disk = final_drive_name
if target_filename in volume_info:
if target_file_found == False:
upload_disk = final_drive_name
target_file_found = True

#
# set upload_port to drive if found
#

if target_file_found == True or target_drive_found == True:
Import("env")
env.Replace(
UPLOAD_PORT = upload_disk
)
print 'upload disk: ' , upload_disk
env.Replace(
UPLOAD_PORT=upload_disk
)
print 'upload disk: ', upload_disk
else:
print '\nUnable to find destination disk. File must be copied manually. \n'


if current_OS == 'Linux':
detect_error('Autodetect Error')

elif current_OS == 'Linux':
#
# platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
#

upload_disk = 'Disk not found'
target_file_found = False
target_drive_found = False
medias = os.listdir('/media') #
for media in medias:
drives = os.listdir('/media/' + media) #
if target_drive in drives and target_file_found == False: # set upload if not found target file yet
target_drive_found = True
upload_disk = '/media/' + media + '/' + target_drive + '/'
for drive in drives:
try:
files = os.listdir('/media/' + media + '/' + drive )
except:
continue
else:
if target_filename in files:
if target_file_found == False:
upload_disk = '/media/' + media + '/' + drive + '/'
target_file_found = True
drives = os.listdir('/media/' + media) #
if target_drive in drives and target_file_found == False: # set upload if not found target file yet
target_drive_found = True
upload_disk = '/media/' + media + '/' + target_drive + '/'
for drive in drives:
try:
files = os.listdir('/media/' + media + '/' + drive)
except:
continue
else:
if target_filename in files:
if target_file_found == False:
upload_disk = '/media/' + media + '/' + drive + '/'
target_file_found = True

#
# set upload_port to drive if found
#

if target_file_found == True or target_drive_found == True:
Import("env")
env.Replace(
UPLOAD_FLAGS = "-P$UPLOAD_PORT",
UPLOAD_PORT = upload_disk
)
print 'upload disk: ' , upload_disk
env.Replace(
UPLOAD_FLAGS="-P$UPLOAD_PORT",
UPLOAD_PORT=upload_disk
)
print 'upload disk: ', upload_disk
else:
print '\nUnable to find destination disk. File must be copied manually. \n'


if current_OS == 'Darwin': # MAC
detect_error('Autodetect Error')

elif current_OS == 'Darwin': # MAC
#
# platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
#

import os
upload_disk = 'Disk not found'
drives = os.listdir('/Volumes') # human readable names
drives = os.listdir('/Volumes') # human readable names
target_file_found = False
target_drive_found = False
if target_drive in drives and target_file_found == False: # set upload if not found target file yet
target_drive_found = True
upload_disk = '/Volumes/' + target_drive + '/'
target_drive_found = True
upload_disk = '/Volumes/' + target_drive + '/'
for drive in drives:
try:
filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected
except:
continue
else:
if target_filename in filenames:
if target_file_found == False:
upload_disk = '/Volumes/' + drive + '/'
target_file_found = True
try:
filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected
except:
continue
else:
if target_filename in filenames:
if target_file_found == False:
upload_disk = '/Volumes/' + drive + '/'
target_file_found = True
#
# set upload_port to drive if found
#

if target_file_found == True or target_drive_found == True:
Import("env")
env.Replace(
UPLOAD_PORT = upload_disk
)
print '\nupload disk: ' , upload_disk, '\n'
env.Replace(
UPLOAD_PORT=upload_disk
)
print '\nupload disk: ', upload_disk, '\n'
else:
print '\nUnable to find destination disk. File must be copied manually. \n'
detect_error('Autodetect Error')

except Exception as e:
detect_error(str(e))
4 changes: 2 additions & 2 deletions platformio.ini
Expand Up @@ -161,7 +161,7 @@ src_filter = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
monitor_speed = 250000
lib_deps = Servo
LiquidCrystal
https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful syntax. May be helpful in other places too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, I added it to all the downloaded zip libs to clean things up in the first commit, but DUE builds failed for errors with no apparent cause so reverted it.

TMCStepper@<1.0.0

[env:LPC1769]
Expand All @@ -179,7 +179,7 @@ src_filter = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
monitor_speed = 250000
lib_deps = Servo
LiquidCrystal
https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
TMCStepper@<1.0.0

#
Expand Down