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