wrong type of exit method

This commit is contained in:
Bob-the-Kuhn 2018-05-26 08:17:03 -05:00
parent 01d37e00af
commit 1c0ad8bbae

View file

@ -18,133 +18,131 @@ current_OS = platform.system()
#exit(0) #exit(0)
build_type = os.environ.get("BUILD_TYPE", 'Not Set') build_type = os.environ.get("BUILD_TYPE", 'Not Set')
if not(build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set') : if build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set' :
exit(0)
if current_OS == 'Windows':
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
#
# #
# platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:' # get all drives on this computer
# Windows - doesn't care about the disk's name, only cares about the drive letter #
#
# import subprocess
# 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:\\']
driveStr = subprocess.check_output("fsutil fsinfo drives") # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\' upload_disk = 'Disk not found'
driveStr = driveStr.strip().lstrip('Drives: ') # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\' target_file_found = False
drives = driveStr.split() # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\'] target_drive_found = False
for drive in drives:
upload_disk = 'Disk not found' final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
target_file_found = False try:
target_drive_found = False volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
for drive in drives: except Exception as e:
final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:' continue
try: else:
volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT) if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet
except Exception as e: target_drive_found = True
continue upload_disk = final_drive_name
else: if target_filename in volume_info:
if target_drive in volume_info and target_file_found == False: # set upload if not found target file yet if target_file_found == False:
target_drive_found = True upload_disk = final_drive_name
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
else:
print '\nUnable to find destination disk. File must be copied manually. \n'
if 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 target_file_found = True
# #
# set upload_port to drive if found # set upload_port to drive if found
# #
if target_file_found == True or target_drive_found == True: if target_file_found == True or target_drive_found == True:
Import("env") Import("env")
env.Replace( env.Replace(
UPLOAD_FLAGS = "-P$UPLOAD_PORT", UPLOAD_PORT = upload_disk
UPLOAD_PORT = upload_disk )
) print 'upload disk: ' , upload_disk
print 'upload disk: ' , upload_disk else:
else: print '\nUnable to find destination disk. File must be copied manually. \n'
print '\nUnable to find destination disk. File must be copied manually. \n'
if current_OS == 'Darwin': # MAC if current_OS == 'Linux':
# #
# platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive' # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
# #
import os upload_disk = 'Disk not found'
upload_disk = 'Disk not found' target_file_found = False
drives = os.listdir('/Volumes') # human readable names target_drive_found = False
target_file_found = False medias = os.listdir('/media') #
target_drive_found = False for media in medias:
if target_drive in drives and target_file_found == False: # set upload if not found target file yet drives = os.listdir('/media/' + media) #
target_drive_found = True if target_drive in drives and target_file_found == False: # set upload if not found target file yet
upload_disk = '/Volumes/' + target_drive + '/' target_drive_found = True
for drive in drives: upload_disk = '/media/' + media + '/' + target_drive + '/'
try: for drive in drives:
filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected try:
except: files = os.listdir('/media/' + media + '/' + drive )
continue except:
else: continue
if target_filename in filenames: else:
if target_file_found == False: if target_filename in files:
upload_disk = '/Volumes/' + drive + '/' if target_file_found == False:
target_file_found = True 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") # set upload_port to drive if found
env.Replace( #
UPLOAD_PORT = upload_disk
) if target_file_found == True or target_drive_found == True:
print '\nupload disk: ' , upload_disk, '\n' Import("env")
else: env.Replace(
print '\nUnable to find destination disk. File must be copied manually. \n' 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
#
# 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
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 + '/'
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
#
# 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'
else:
print '\nUnable to find destination disk. File must be copied manually. \n'