Selaa lähdekoodia

Tweak LPC1768 upload py script

Scott Lahteine 4 vuotta sitten
vanhempi
commit
a33d08928a
1 muutettua tiedostoa jossa 115 lisäystä ja 114 poistoa
  1. 115
    114
      Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py

+ 115
- 114
Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py Näytä tiedosto

@@ -16,129 +16,130 @@ current_OS = platform.system()
16 16
 Import("env")
17 17
 
18 18
 def print_error(e):
19
-    print('\nUnable to find destination disk (' + e + ')\n' \
20
-          'Please select it in platformio.ini using the upload_port keyword ' \
21
-          '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
22
-          'or copy the firmware (.pio/build/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
19
+	print('\nUnable to find destination disk (%s)\n' \
20
+		  'Please select it in platformio.ini using the upload_port keyword ' \
21
+		  '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
22
+		  'or copy the firmware (.pio/build/%s/firmware.bin) manually to the appropriate disk\n' \
23
+		  %(e, env.get('PIOENV')))
23 24
 
24 25
 try:
25
-    if current_OS == 'Windows':
26
-        #
27
-        # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
28
-        #   Windows - doesn't care about the disk's name, only cares about the drive letter
29
-        #
26
+	if current_OS == 'Windows':
27
+		#
28
+		# platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
29
+		#   Windows - doesn't care about the disk's name, only cares about the drive letter
30
+		#
30 31
 
31
-        #
32
-        # get all drives on this computer
33
-        #
34
-        import subprocess
35
-        # typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
36
-        driveStr = str(subprocess.check_output("fsutil fsinfo drives"))
37
-        # typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
38
-        # driveStr = driveStr.strip().lstrip('Drives: ') <- Doesn't work in other Languages as English. In German is "Drives:" = "Laufwerke:"
39
-        FirstFound = driveStr.find(':',0,-1)         # Find the first ":" and
40
-        driveStr = driveStr[FirstFound + 1 : -1]     # truncate to the rest
41
-        # typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
42
-        # 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
43
-        drives = driveStr.split()
32
+		#
33
+		# get all drives on this computer
34
+		#
35
+		import subprocess
36
+		# typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
37
+		driveStr = str(subprocess.check_output("fsutil fsinfo drives"))
38
+		# typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
39
+		# driveStr = driveStr.strip().lstrip('Drives: ') <- Doesn't work in other Languages as English. In German is "Drives:" = "Laufwerke:"
40
+		FirstFound = driveStr.find(':',0,-1)         # Find the first ":" and
41
+		driveStr = driveStr[FirstFound + 1 : -1]     # truncate to the rest
42
+		# typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
43
+		# 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
44
+		drives = driveStr.split()
44 45
 
45
-        upload_disk = 'Disk not found'
46
-        target_file_found = False
47
-        target_drive_found = False
48
-        for drive in drives:
49
-            final_drive_name = drive.strip().rstrip('\\')   # typical result (string): 'C:'
50
-            try:
51
-                volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT))
52
-            except Exception as e:
53
-                continue
54
-            else:
55
-                if target_drive in volume_info and target_file_found == False:  # set upload if not found target file yet
56
-                    target_drive_found = True
57
-                    upload_disk = final_drive_name
58
-                if target_filename in volume_info:
59
-                    if target_file_found == False:
60
-                        upload_disk = final_drive_name
61
-                    target_file_found = True
46
+		upload_disk = 'Disk not found'
47
+		target_file_found = False
48
+		target_drive_found = False
49
+		for drive in drives:
50
+			final_drive_name = drive.strip().rstrip('\\')   # typical result (string): 'C:'
51
+			try:
52
+				volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT))
53
+			except Exception as e:
54
+				continue
55
+			else:
56
+				if target_drive in volume_info and target_file_found == False:  # set upload if not found target file yet
57
+					target_drive_found = True
58
+					upload_disk = final_drive_name
59
+				if target_filename in volume_info:
60
+					if target_file_found == False:
61
+						upload_disk = final_drive_name
62
+					target_file_found = True
62 63
 
63
-        #
64
-        # set upload_port to drive if found
65
-        #
64
+		#
65
+		# set upload_port to drive if found
66
+		#
66 67
 
67
-        if target_file_found == True or target_drive_found == True:
68
-            env.Replace(
69
-                UPLOAD_PORT=upload_disk
70
-            )
71
-            print('upload disk: ', upload_disk)
72
-        else:
73
-            print_error('Autodetect Error')
68
+		if target_file_found == True or target_drive_found == True:
69
+			env.Replace(
70
+				UPLOAD_PORT=upload_disk
71
+			)
72
+			print('upload disk: ', upload_disk)
73
+		else:
74
+			print_error('Autodetect Error')
74 75
 
75
-    elif current_OS == 'Linux':
76
-        #
77
-        # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
78
-        #
79
-        upload_disk = 'Disk not found'
80
-        target_file_found = False
81
-        target_drive_found = False
82
-        drives = os.listdir(os.path.join(os.sep, 'media', getpass.getuser()))
83
-        if target_drive in drives:  # If target drive is found, use it.
84
-            target_drive_found = True
85
-            upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), target_drive) + os.sep
86
-        else:
87
-            for drive in drives:
88
-                try:
89
-                    files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive))
90
-                except:
91
-                    continue
92
-                else:
93
-                    if target_filename in files:
94
-                        upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep
95
-                        target_file_found = True
96
-                        break
97
-        #
98
-        # set upload_port to drive if found
99
-        #
76
+	elif current_OS == 'Linux':
77
+		#
78
+		# platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive'
79
+		#
80
+		upload_disk = 'Disk not found'
81
+		target_file_found = False
82
+		target_drive_found = False
83
+		drives = os.listdir(os.path.join(os.sep, 'media', getpass.getuser()))
84
+		if target_drive in drives:  # If target drive is found, use it.
85
+			target_drive_found = True
86
+			upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), target_drive) + os.sep
87
+		else:
88
+			for drive in drives:
89
+				try:
90
+					files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive))
91
+				except:
92
+					continue
93
+				else:
94
+					if target_filename in files:
95
+						upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep
96
+						target_file_found = True
97
+						break
98
+		#
99
+		# set upload_port to drive if found
100
+		#
100 101
 
101
-        if target_file_found or target_drive_found:
102
-            env.Replace(
103
-                UPLOAD_FLAGS="-P$UPLOAD_PORT",
104
-                UPLOAD_PORT=upload_disk
105
-            )
106
-            print('upload disk: ', upload_disk)
107
-        else:
108
-            print_error('Autodetect Error')
102
+		if target_file_found or target_drive_found:
103
+			env.Replace(
104
+				UPLOAD_FLAGS="-P$UPLOAD_PORT",
105
+				UPLOAD_PORT=upload_disk
106
+			)
107
+			print('upload disk: ', upload_disk)
108
+		else:
109
+			print_error('Autodetect Error')
109 110
 
110
-    elif current_OS == 'Darwin':  # MAC
111
-        #
112
-        # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
113
-        #
114
-        upload_disk = 'Disk not found'
115
-        drives = os.listdir('/Volumes')  # human readable names
116
-        target_file_found = False
117
-        target_drive_found = False
118
-        if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
119
-            target_drive_found = True
120
-            upload_disk = '/Volumes/' + target_drive + '/'
121
-        for drive in drives:
122
-            try:
123
-                filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
124
-            except:
125
-                continue
126
-            else:
127
-                if target_filename in filenames:
128
-                    if target_file_found == False:
129
-                        upload_disk = '/Volumes/' + drive + '/'
130
-                    target_file_found = True
131
-        #
132
-        # set upload_port to drive if found
133
-        #
111
+	elif current_OS == 'Darwin':  # MAC
112
+		#
113
+		# platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive'
114
+		#
115
+		upload_disk = 'Disk not found'
116
+		drives = os.listdir('/Volumes')  # human readable names
117
+		target_file_found = False
118
+		target_drive_found = False
119
+		if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
120
+			target_drive_found = True
121
+			upload_disk = '/Volumes/' + target_drive + '/'
122
+		for drive in drives:
123
+			try:
124
+				filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
125
+			except:
126
+				continue
127
+			else:
128
+				if target_filename in filenames:
129
+					if target_file_found == False:
130
+						upload_disk = '/Volumes/' + drive + '/'
131
+					target_file_found = True
132
+		#
133
+		# set upload_port to drive if found
134
+		#
134 135
 
135
-        if target_file_found == True or target_drive_found == True:
136
-            env.Replace(
137
-                UPLOAD_PORT=upload_disk
138
-            )
139
-            print('\nupload disk: ', upload_disk, '\n')
140
-        else:
141
-            print_error('Autodetect Error')
136
+		if target_file_found == True or target_drive_found == True:
137
+			env.Replace(
138
+				UPLOAD_PORT=upload_disk
139
+			)
140
+			print('\nupload disk: ', upload_disk, '\n')
141
+		else:
142
+			print_error('Autodetect Error')
142 143
 
143 144
 except Exception as e:
144
-    print_error(str(e))
145
+	print_error(str(e))

Loading…
Peruuta
Tallenna