Browse Source

[LPC1768] Add error-handling to upload script, update autobuild.py (#10802)

Bob Kuhn 6 years ago
parent
commit
6dfbb39f83
2 changed files with 98 additions and 59 deletions
  1. 31
    13
      Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
  2. 67
    46
      buildroot/share/atom/auto_build.py

+ 31
- 13
Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py View File

@@ -34,6 +34,7 @@ if current_OS == 'Windows':
34 34
     #
35 35
 
36 36
     import os
37
+    upload_disk = 'Disk not found'
37 38
     target_file_found = False
38 39
     target_drive_found = False
39 40
     for drive in drives:
@@ -66,7 +67,9 @@ if current_OS == 'Windows':
66 67
       env.Replace(
67 68
           UPLOAD_PORT = upload_disk
68 69
       )
69
-
70
+      print 'upload disk: ' , upload_disk
71
+    else:
72
+       print '\nUnable to find destination disk.  File must be copied manually. \n'
70 73
 
71 74
 
72 75
 if current_OS == 'Linux':
@@ -76,6 +79,7 @@ if current_OS == 'Linux':
76 79
     #
77 80
 
78 81
     import os
82
+    upload_disk = 'Disk not found'
79 83
     target_file_found = False
80 84
     target_drive_found = False
81 85
     medias = os.listdir('/media')  #
@@ -85,11 +89,15 @@ if current_OS == 'Linux':
85 89
         target_drive_found = True
86 90
         upload_disk = '/media/' + media + '/' + target_drive + '/'
87 91
       for drive in drives:
88
-        files = os.listdir('/media/' + media + '/' + drive )  #
89
-        if target_filename in files:
90
-          if target_file_found == False:
91
-            upload_disk = '/media/' + media + '/' + drive + '/'
92
-            target_file_found = True
92
+        try:
93
+          files = os.listdir('/media/' + media + '/' + drive )
94
+        except:
95
+          continue
96
+        else:
97
+          if target_filename in files:
98
+            if target_file_found == False:
99
+              upload_disk = '/media/' + media + '/' + drive + '/'
100
+              target_file_found = True
93 101
 
94 102
     #
95 103
     # set upload_port to drive if found
@@ -101,6 +109,9 @@ if current_OS == 'Linux':
101 109
         UPLOAD_FLAGS = "-P$UPLOAD_PORT",
102 110
         UPLOAD_PORT = upload_disk
103 111
       )
112
+      print 'upload disk: ' , upload_disk
113
+    else:
114
+       print '\nUnable to find destination disk.  File must be copied manually. \n'
104 115
 
105 116
 
106 117
 if current_OS == 'Darwin':  # MAC
@@ -110,19 +121,23 @@ if current_OS == 'Darwin':  # MAC
110 121
     #
111 122
 
112 123
     import os
124
+    upload_disk = 'Disk not found'
113 125
     drives = os.listdir('/Volumes')  #  human readable names
114 126
     target_file_found = False
115 127
     target_drive_found = False
116 128
     if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
117 129
       target_drive_found = True
118
-      upload_disk = '/Volumes/' + drive + '/'
130
+      upload_disk = '/Volumes/' + target_drive + '/'
119 131
     for drive in drives:
120
-      target_file_found = True
121
-      filenames = os.listdir('/Volumes/' + drive + '/')
122
-      if target_filename in filenames:
123
-        if target_file_found == False:
124
-          upload_disk = '/Volumes/' + drive + '/'
125
-        target_file_found = True
132
+      try:
133
+        filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
134
+      except:
135
+        continue
136
+      else:
137
+        if target_filename in filenames:
138
+          if target_file_found == False:
139
+            upload_disk = '/Volumes/' + drive + '/'
140
+          target_file_found = True
126 141
     #
127 142
     # set upload_port to drive if found
128 143
     #
@@ -132,3 +147,6 @@ if current_OS == 'Darwin':  # MAC
132 147
       env.Replace(
133 148
           UPLOAD_PORT = upload_disk
134 149
       )
150
+      print '\nupload disk: ' , upload_disk, '\n'
151
+    else:
152
+       print '\nUnable to find destination disk.  File must be copied manually. \n'

+ 67
- 46
buildroot/share/atom/auto_build.py View File

@@ -204,7 +204,7 @@ def resolve_path(path):
204 204
        #get line and column numbers
205 205
         line_num = 1
206 206
         column_num = 1
207
-        line_start = path.find(':')
207
+        line_start = path.find(':', 2)                  # use 2 here so don't eat Windows full path
208 208
         column_start = path.find(':', line_start + 1)
209 209
         if column_start == -1:
210 210
           column_start = len(path)
@@ -218,57 +218,69 @@ def resolve_path(path):
218 218
         if not(column_start == column_end):
219 219
           column_num = path[ column_start + 1 : column_end]
220 220
           if column_num == '':
221
-            column_num = 1
221
+            column_num = 0
222 222
 
223
+        index_end = path.find(',')
224
+        if 0 <= index_end:
225
+            path = path[ : index_end]  # delete comma and anything after
226
+        index_end = path.find(':', 2)
227
+        if 0 <= index_end:
228
+            path = path[ : path.find(':', 2)]  # delete the line number and anything after
223 229
 
224
-        path = path[ : path.find(':')]  # delete the line number and anything after
225 230
         path = path.replace('\\','/')
226 231
 
227
-      # resolve as many '../' as we can
228
-        while 0 <= path.find('../'):
229
-          end =  path.find('../') - 1
230
-          start = path.find('/')
231
-          while 0 <= path.find('/',start) and end > path.find('/',start):
232
-            start = path.find('/',start) + 1
233
-          path = path[0:start] + path[end + 4: ]
234
-
235
-        # this is an alternative to the above - it just deletes the '../' section
236
-        # start_temp = path.find('../')
237
-        # while 0 <= path.find('../',start_temp):
238
-        #   start = path.find('../',start_temp)
239
-        #   start_temp = start  + 1
240
-        # if 0 <= start:
241
-        #   path = path[start + 2 : ]
242
-
243
-
244
-        start = path.find('/')
245
-        if not(0 == start):            # make sure path starts with '/'
246
-          while 0 == path.find(' '):    # eat any spaces at the beginning
247
-            path = path[ 1 : ]
248
-          path = '/' + path
232
+        if 1 == path.find(':') and current_OS == 'Windows':
233
+          return path, line_num, column_num                    # found a full path - no need for further processing
234
+        elif 0 == path.find('/') and (current_OS == 'Linux' or current_OS == 'Darwin'):
235
+          return path, line_num, column_num                    # found a full path - no need for further processing
249 236
 
250
-        if current_OS == 'Windows':
251
-          search_path = path.replace('/', '\\')  # os.walk uses '\' in Windows
252 237
         else:
253
-          search_path = path
254
-
255
-        start_path = os.path.abspath('')
256 238
 
257
-    # search project directory for the selection
258
-        found = False
259
-        full_path = ''
260
-        for root, directories, filenames in os.walk(start_path):
261
-          for filename in filenames:
262
-                  if  0 <= root.find('.git'):              # don't bother looking in this directory
263
-                    break
264
-                  full_path = os.path.join(root,filename)
265
-                  if 0 <= full_path.find(search_path):
266
-                    found = True
267
-                    break
268
-          if found:
269
-            break
239
+          # resolve as many '../' as we can
240
+            while 0 <= path.find('../'):
241
+              end =  path.find('../') - 1
242
+              start = path.find('/')
243
+              while 0 <= path.find('/',start) and end > path.find('/',start):
244
+                start = path.find('/',start) + 1
245
+              path = path[0:start] + path[end + 4: ]
246
+
247
+            # this is an alternative to the above - it just deletes the '../' section
248
+            # start_temp = path.find('../')
249
+            # while 0 <= path.find('../',start_temp):
250
+            #   start = path.find('../',start_temp)
251
+            #   start_temp = start  + 1
252
+            # if 0 <= start:
253
+            #   path = path[start + 2 : ]
254
+
255
+
256
+            start = path.find('/')
257
+            if not(0 == start):            # make sure path starts with '/'
258
+              while 0 == path.find(' '):    # eat any spaces at the beginning
259
+                path = path[ 1 : ]
260
+              path = '/' + path
261
+
262
+            if current_OS == 'Windows':
263
+              search_path = path.replace('/', '\\')  # os.walk uses '\' in Windows
264
+            else:
265
+              search_path = path
266
+
267
+            start_path = os.path.abspath('')
268
+
269
+        # search project directory for the selection
270
+            found = False
271
+            full_path = ''
272
+            for root, directories, filenames in os.walk(start_path):
273
+              for filename in filenames:
274
+                      if  0 <= root.find('.git'):              # don't bother looking in this directory
275
+                        break
276
+                      full_path = os.path.join(root,filename)
277
+                      if 0 <= full_path.find(search_path):
278
+                        found = True
279
+                        break
280
+              if found:
281
+                break
270 282
 
271
-        return full_path, line_num, column_num
283
+            return full_path, line_num, column_num
272 284
 
273 285
 # end - resolve_path
274 286
 
@@ -324,6 +336,9 @@ def open_file(path):
324 336
         elif current_OS == 'Linux':
325 337
 
326 338
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
339
+              index_end = command.find(',')
340
+              if 0 <= index_end:
341
+                  command = command[ : index_end]  # sometimes a comma magically appears, don't want it
327 342
               running_apps = subprocess.Popen('ps ax -o cmd', stdout=subprocess.PIPE, shell=True)
328 343
               (output, err) = running_apps.communicate()
329 344
               temp = output.split('\n')
@@ -336,7 +351,7 @@ def open_file(path):
336 351
                   return False , ''
337 352
 
338 353
               (success_sublime, editor_path_sublime) = find_editor_linux('sublime_text',temp)
339
-              (success_atom, editor_path_atom) = find_editor+linux('atom',temp)
354
+              (success_atom, editor_path_atom) = find_editor_linux('atom',temp)
340 355
 
341 356
               if success_sublime:
342 357
                   subprocess.Popen([editor_path_sublime, command])
@@ -350,6 +365,9 @@ def open_file(path):
350 365
         elif current_OS == 'Darwin':  # MAC
351 366
 
352 367
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
368
+              index_end = command.find(',')
369
+              if 0 <= index_end:
370
+                  command = command[ : index_end]  # sometimes a comma magically appears, don't want it
353 371
               running_apps = subprocess.Popen('ps axwww -o command', stdout=subprocess.PIPE, shell=True)
354 372
               (output, err) = running_apps.communicate()
355 373
               temp = output.split('\n')
@@ -424,8 +442,11 @@ def get_build_last():
424 442
         date_last = 0.0
425 443
         DIR__pioenvs = os.listdir('.pioenvs')
426 444
         for name in DIR__pioenvs:
445
+          if 0 <= name.find('.') or 0 <= name.find('-'):   # skip files in listing
446
+            continue
427 447
           DIR_temp = os.listdir('.pioenvs/' + name)
428 448
           for names_temp in DIR_temp:
449
+
429 450
             if 0 == names_temp.find('firmware.'):
430 451
               date_temp = os.path.getmtime('.pioenvs/' + name + '/' + names_temp)
431 452
               if date_temp > date_last:
@@ -941,7 +962,7 @@ class output_window(Text):
941 962
         Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
942 963
         self.config(tabs=(400,))  # configure Text widget tab stops
943 964
         self.config(background = 'black', foreground = 'white', font= ("consolas", 12), wrap = 'word', undo = 'True')
944
-        self.config(height  = 24, width = 120)
965
+        self.config(height  = 24, width = 100)
945 966
         self.config(insertbackground = 'pale green')  # keyboard insertion point
946 967
         self.pack(side='left', fill='both', expand=True)
947 968
 

Loading…
Cancel
Save